Package 'UnivRNG'

Title: Univariate Pseudo-Random Number Generation
Description: Pseudo-random number generation of 17 univariate distributions proposed by Demirtas. (2005) <DOI:10.22237/jmasm/1114907220>.
Authors: Hakan Demirtas, Rawan Allozi, Ran Gao
Maintainer: Ran Gao <[email protected]>
License: GPL-2 | GPL-3
Version: 1.2.3
Built: 2024-11-16 03:48:28 UTC
Source: https://github.com/cran/UnivRNG

Help Index


Univariate Pseudo-Random Number Generation

Description

This package implements the algorithms described in Demirtas (2005) for pseudo-random number generation of 17 univariate distributions. The following distributions are available: Left Truncated Gamma, Laplace, Inverse Gaussian, Von Mises, Zeta (Zipf), Logarithmic, Beta-Binomial, Rayleigh, Pareto, Non-central tt, Non-central Chi-squared, Doubly non-central FF, Standard tt, Weibull, Gamma with α\alpha<1, Gamma with α\alpha>1, and Beta with α\alpha<1 and β\beta<1. For some distributions, functions that have similar capabilities exist in the base package; the functions herein should be regarded as complementary tools.

The methodology for each random-number generation procedure varies and each distribution has its own function. draw.left.truncated.gamma, draw.von.mises, draw.inverse.gaussian, draw.zeta, draw.gamma.alpha.less.than.one, and draw.beta.alphabeta.less.than.one are based on acceptance/rejection region techniques. draw.rayleigh, draw.pareto, and draw.weibull utilize the inverse CDF method. The chop-down method is used for draw.logarithmic. In draw.laplace, a sample from an exponential distribution with mean 1/λ1/\lambda is generated and subsequently the sign is changed with probability 0.5 and all variables are shifted by α\alpha. For the Beta-Binomial distribution in draw.beta.binomial, π\pi is generated as the appropriate β\beta and used as the success probability for the binomial portion. draw.noncentral.t utilizes on arithmetic functions of normal and chi-squared random variables. draw.noncentral.chisquared is based on the sum of squared random normal variables, and draw.noncentral.F is a ratio of chi-squared random variables generated via draw.noncentral.chisquared. draw.t employs a rejection polar method developed by Bailey (1994). draw.gamma.alpha.greater.than.one uses a ratio of uniforms method by Cheng and Feast (1979).

Details

Package: UnivRNG
Type: Package
Version: 1.2.3
Date: 2021-03-05
License: GPL-2 | GPL-3

Author(s)

Hakan Demirtas, Rawan Allozi, Ran Gao

Maintainer: Ran Gao <[email protected]>

References

Bailey, R. W. (1994). Polar generation of random variates with the t-distribution. Mathematics of Computation, 62, 779-781.

Cheng, R. C. H., & Feast, G. M. (1979). Some simple gamma variate generation. Applied Statistics, 28, 290-295.

Demirtas, H. (2005). Pseudo-random number generation in R for some univariate distributions. Journal of Modern Applied Statistical Methods, 4(1), 300-311.


Generates variates from Beta distribution with max(α,β)<1(\alpha,\beta)<1

Description

This function implements pseudo-random number generation for a Beta distribution for max(α,β)<1\max(\alpha,\beta)<1 with pdf

f(xα,β)=1B(α,β)xα1(1x)β1f(x|\alpha,\beta)=\frac{1}{B(\alpha,\beta)}x^{\alpha-1}(1-x)^{\beta-1}

for 0x10 \leq x \leq 1, 0<α<10 < \alpha < 1, and 0<β<10 < \beta < 1 where α\alpha and β\beta are the shape parameters and B(α,β)B(\alpha,\beta) is the complete beta function.

Usage

draw.beta.alphabeta.less.than.one(nrep,alpha,beta)

Arguments

nrep

Number of data points to generate.

alpha

First shape parameter. Must be less than 1.

beta

Second shape parameter. Must be less than 1.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Jhonk, M. D. (1964). Erzeugung von betaverteilter und gammaverteilter zufallszahlen. Metrika, 8, 5-15.

Examples

draw.beta.alphabeta.less.than.one(nrep=100000,alpha=0.7,beta=0.4)

Generates variates from Beta-binomial distribution

Description

This function implements pseudo-random number generation for a Beta-binomial distribution with pmf

f(xn,α,β)=n!x!(nx)!B(α,β)01πα1+x(1π)n+β1xdπf(x|n,\alpha,\beta) = \frac{n!}{x!(n-x)!B(\alpha,\beta)}\int_{0}^{1}\pi^{\alpha-1+x}(1-\pi)^{n+\beta-1-x}d\pi

for x=0,1,2,...x=0,1,2,..., α>0\alpha>0, and β>0\beta>0, where nn is the sample size, α\alpha and β\beta are the shape parameters and B(α,β)B(\alpha,\beta) is the complete beta function.

Usage

draw.beta.binomial(nrep,alpha,beta,n)

Arguments

nrep

Number of data points to generate.

alpha

First shape parameter.

beta

Second shape parameter.

n

Number of trials.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

Examples

draw.beta.binomial(nrep=100000,alpha=0.2,beta=0.25,n=10)

draw.beta.binomial(nrep=100000,alpha=2,beta=3,n=10)

draw.beta.binomial(nrep=100000,alpha=600,beta=400,n=20)

Generates variation from Gamma distribution with α>1\alpha>1

Description

This function implements pseudo-random number generation for a Gamma distribution for α>1\alpha>1 with pdf

f(xα,β)=1Γ(α)βαxα1ex/βf(x|\alpha,\beta)=\frac{1}{\Gamma(\alpha)\beta^{\alpha}}x^{\alpha-1}e^{-x/\beta}

for 0x<0 \leq x < \infty and min(α,β)>0\min(\alpha,\beta)>0 where α\alpha and β\beta are the shape and scale parameters, respectively.

Usage

draw.gamma.alpha.greater.than.one(nrep,alpha,beta)

Arguments

nrep

Number of data points to generate.

alpha

Shape parameter for desired gamma distribution. Must be greater than 1.

beta

Scale parameter for desired gamma distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Cheng, R. C. H., & Feast, G. M. (1979). Some simple gamma variate generation. Applied Statistics, 28, 290-295.

Examples

draw.gamma.alpha.greater.than.one(nrep=100000,alpha=2,beta=2)

draw.gamma.alpha.greater.than.one(nrep=100000,alpha=3,beta=0.4)

Generates variation from Gamma distribution with α<1\alpha<1

Description

This function implements pseudo-random number generation for a gamma distribution for α<1\alpha<1 with pdf

f(xα,β)=1Γ(α)βαxα1ex/βf(x|\alpha,\beta)=\frac{1}{\Gamma(\alpha)\beta^{\alpha}}x^{\alpha-1}e^{-x/\beta}

for 0x<0 \leq x < \infty and min(α,β)>0\min(\alpha,\beta)>0 where α\alpha and β\beta are the shape and scale parameters, respectively.

Usage

draw.gamma.alpha.less.than.one(nrep,alpha,beta)

Arguments

nrep

Number of data points to generate.

alpha

Shape parameter for desired gamma distribution. Must be less than 1.

beta

Scale parameter for desired gamma distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Ahrens, J. H., & Dieter, U. (1974). Computer methods for sampling from gamma, beta, poisson and binomial distributions. Computing, 1, 223-246.

Examples

draw.gamma.alpha.less.than.one(nrep=100000,alpha=0.5,beta=2)

Generates variation from inverse Gaussian distribution

Description

This function implements pseudo-random number generation for an inverse Gaussian distribution with pdf

f(xμ,λ)=(λ2π)1/2x3/2eλ(xμ)22μ2xf(x|\mu,\lambda)=(\frac{\lambda}{2\pi})^{1/2}x^{-3/2}e^{-\frac{\lambda(x-\mu)^2}{2\mu^2x}}

for x>0x > 0, μ>0\mu > 0, and λ>0\lambda > 0 where μ\mu and λ\lambda are the location and scale parameters, respectively.

Usage

draw.inverse.gaussian(nrep,mu,lambda)

Arguments

nrep

Number of data points to generate.

mu

Location parameter for the desired inverse Gaussian distribution.

lambda

Scale parameter for the desired inverse Gaussian distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Michael, J. R., William, R. S., & Haas, R. W. (1976). Generating random variates using transformations with multiple roots. The American Statistician, 30, 88-90.

Examples

draw.inverse.gaussian(nrep=100000,mu=1,lambda=1)

draw.inverse.gaussian(nrep=100000,mu=3,lambda=1)

Generates variates from Laplace distribution

Description

This function implements pseudo-random number generation for a Laplace (double exponential) distribution with pdf

f(xλ,α)=λ2eλxαf(x|\lambda,\alpha)=\frac{\lambda}{2}e^{-\lambda|x-\alpha|}

for λ\lambda>0 where α\alpha and λ\lambda are the location and scale parameters, respectively.

Usage

draw.laplace(nrep, alpha, lambda)

Arguments

nrep

Number of data points to generate.

alpha

Location parameter for the desired Laplace distribution.

lambda

Scale parameter for the desired Laplace distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

Examples

draw.laplace(nrep=100000, alpha=4, lambda=2)

draw.laplace(nrep=100000, alpha=-5, lambda=4)

Generates variates from left truncated Gamma distribution

Description

This function implements pseudo-random number generation for a left-truncated gamma distribution with pdf

f(xα,β)=1(Γ(α)Γτ/β(α))βαxα1ex/βf(x|\alpha, \beta) = \frac{1}{(\Gamma(\alpha)-\Gamma_{\tau/\beta}(\alpha))\beta^{\alpha}}x^{\alpha-1}e^{-x/\beta}

for 0<τx0<\tau\leq x, and min(τ\tau, β\beta)>0 where α\alpha and β\beta are the shape and scale parameters, respectively, τ\tau is the cutoff point at which truncation occurs, and Γτ/β\Gamma_{\tau/\beta} is the incomplete gamma function.

Usage

draw.left.truncated.gamma(nrep,alpha,beta,tau)

Arguments

nrep

Number of data points to generate.

alpha

Shape parameter for the desired gamma distribution.

beta

Scale parameter fot the desired gamma distribution.

tau

Point of left truncation.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Dagpunar, J. S. (1978). Sampling of variates from a truncated gamma distribution. Journal of Statistical Computation and Simulation, 8, 59-64.

Examples

draw.left.truncated.gamma(nrep=100000,alpha=5,beta=1,tau=0.5)

draw.left.truncated.gamma(nrep=100000,alpha=2,beta=2,tau=0.1)

Generates variates from logarithmic distribution

Description

This function implements pseudo-random number generation for a logarithmic distribution with pmf

f(xθ)=θxxlog(1θ)f(x|\theta) = - \frac{\theta^{x}}{x\log(1-\theta)}

for x=1,2,3,...x=1,2,3,... and 0<θ<10 < \theta < 1.

Usage

draw.logarithmic(nrep,theta)

Arguments

nrep

Number of data points to generate.

theta

Rate parameter of the desired logarithmic distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Kemp, A. W. Efficient generation of logarithmically distributed pseudo-random variables. Applied Statistics, 30, 249-253.

Examples

draw.logarithmic(nrep=100000,theta=0.33)

draw.logarithmic(nrep=100000,theta=0.66)

Generates variates from non-central chi-squared distribution

Description

This function implements pseudo-random number generation for a non-central chi-squared distribution with pdf

f(xλ,ν)=e(x+λ)/2xν/212ν/2k=0(λx)k4kk!Γ(k+ν/2)f(x|\lambda,\nu)=\frac{e^{-(x+\lambda)/2}x^{\nu/2-1}}{2^{\nu/2}} \sum_{k=0}^{\infty} \frac{(\lambda x)^{k}}{4^{k}k!\Gamma(k+\nu/2)}

for 0x<0 \leq x < \infty, λ>0\lambda>0, and ν>1\nu>1, where λ\lambda is the non-centrality parameter and ν\nu is the degrees of freedom.

Usage

draw.noncentral.chisquared(nrep,dof,ncp)

Arguments

nrep

Number of data points to generate.

dof

Degrees of freedom of the desired non-central chi-squared distribution.

ncp

Non-centrality parameter of the desired non-central chi-squared distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

Examples

draw.noncentral.chisquared(nrep=100000,dof=2,ncp=1)

draw.noncentral.chisquared(nrep=100000,dof=5,ncp=2)

Generates variates from doubly non-central F distribution

Description

This function implements pseudo-random number generation for a doubly non-central FF distribution

F=X12/nX22/mF=\frac{X_{1}^{2}/n}{X_{2}^{2}/m}

where X12χ2(n,λ1)X_{1}^{2}\sim \chi^{2}(n,\lambda_{1}), X22χ2(m,λ2)X_{2}^{2}\sim \chi^{2}(m,\lambda_{2}), nn and mm are numerator and denominator degrees of freedom, respectively, and λ1\lambda_{1} and λ2\lambda_{2} are the numerator and denominator non-centrality parameters, respectively. It includes central and singly non-central F distributions as a special case.

Usage

draw.noncentral.F(nrep,dof1,dof2,ncp1,ncp2)

Arguments

nrep

Number of data points to generate.

dof1

Numerator degress of freedom.

dof2

Denominator degrees of freedom.

ncp1

Numerator non-centrality parameter.

ncp2

Denominator non-centrality parameter.

Value

A vector containing generated data.

See Also

draw.noncentral.chisquared

Examples

draw.noncentral.F(nrep=100000,dof1=2,dof2=4,ncp1=2,ncp2=4)

Generates variates from doubly non-central t distribution

Description

This function implements pseudo-random number generation for a non-central tt distribution

YU/ν\frac{Y}{\sqrt{U/\nu}}

where UU is a central chi-square random variable with ν\nu degrees of freedom and YY is an independent, normally distributed random variable with variance 1 and mean λ\lambda.

Usage

draw.noncentral.t(nrep,nu,lambda)

Arguments

nrep

Number of data points to generate.

nu

Degrees of freedom of the desired non-central t distribution.

lambda

Non-centrality parameter of the desired non-central t distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

Examples

draw.noncentral.t(nrep=100000,nu=4,lambda=2)

draw.noncentral.t(nrep=100000,nu=5,lambda=1)

Generates variates from Pareto distribution

Description

This function implements pseudo-random number generation for a Pareto distribution with pdf

f(xα,β)=abaxa+1f(x|\alpha,\beta)=\frac{ab^{a}}{x^{a+1}}

for 0<bx<0 < b \leq x < \infty and a>0a>0 where aa and bb are the shape and location parameters, respectively.

Usage

draw.pareto(nrep,shape,location)

Arguments

nrep

Number of data points to generate.

shape

Shape parameter of the desired Pareto distribution.

location

Location parameter of the desired Pareto distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

Examples

draw.pareto(nrep=100000,shape=11,location=11)

draw.pareto(nrep=100000,shape=8,location=10)

Generates variates from Rayleigh distribution

Description

This function implements pseudo-random number generation for a Rayleigh distribution with pdf

f(xσ)=xσ2ex2/2σ2f(x|\sigma)=\frac{x}{\sigma^2}e^{-x^2/2\sigma^2}

for x0x \geq 0 and σ>0\sigma > 0 where σ\sigma is the scale parameter.

Usage

draw.rayleigh(nrep,sigma)

Arguments

nrep

Number of data points to generate.

sigma

Scale parameter of the desired Rayleigh distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

Examples

draw.rayleigh(nrep=100000,sigma=0.5)

draw.rayleigh(nrep=100000,sigma=3)

Generates variates from standard t distribution

Description

This function implements pseudo-random number generation for a standard-tt distribution with pdf

f(xν)=Γ(ν+12)Γ(ν2)νπ(1+x2ν)(ν+1)/2f(x|\nu)=\frac{\Gamma(\frac{\nu+1}{2})}{\Gamma(\frac{\nu}{2})\sqrt{\nu\pi}}(1+\frac{x^2}{\nu})^{-(\nu+1)/2}

for <x<-\infty < x < \infty where ν\nu is the degrees of freedom.

Usage

draw.t(nrep,dof)

Arguments

nrep

Number of data points to generate.

dof

Degrees of freedom of the desired t distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Bailey, R. W. (1994). Polar generation of random variates with the t-distribution. Mathematics of Computation, 62, 779-781.

Examples

draw.t(nrep=100000,dof=2)

draw.t(nrep=100000,dof=6)

Generates variates from Von Mises distribution

Description

This function implements pseudo-random number generation for a Von Mises distribution with pdf

f(xK)=12πI0(K)eKcos(x)f(x|K)=\frac{1}{2\pi I_{0}(K)}e^{Kcos(x)}

for πxπ-\pi \leq x \leq \pi and K>0K > 0 where I0(K)I_{0}(K) is a modified Bessel function of the first kind of order 0.

Usage

draw.von.mises(nrep,K)

Arguments

nrep

Number of data points to generate.

K

Parameter of the desired von Mises distribution.

Value

A list of length three containing generated data, the theoretical mean, and the empirical mean with names y, theo.mean, and emp.mean, respectively.

References

Best, D. J., & Fisher, N. I. (1979). Efficient simulation of the von mises distribution. Applied Statistics, 28, 152-157.

Examples

draw.von.mises(nrep=100000,K=10)

draw.von.mises(nrep=100000,K=0.5)

Generates variates from Weibull distribution

Description

This function implements pseudo-random number generation for a Weibull distribution with pdf

f(xα,β)=αβαxα1e(x/β)αf(x|\alpha,\beta)=\frac{\alpha}{\beta^{\alpha}}x^{\alpha-1}e^{-(x/\beta)^{\alpha}}

for 0x<0 \leq x < \infty and min(α,β)>0\min(\alpha,\beta)>0 where α\alpha and β\beta are the shape and scale parameters, respectively.

Usage

draw.weibull(nrep, alpha, beta)

Arguments

nrep

Number of data points to generate.

alpha

Shape parameter of the desired Weibull distribution.

beta

Scale parameter of the desired Weibull distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

Examples

draw.weibull(nrep=100000, alpha=0.5, beta=1)

draw.weibull(nrep=100000, alpha=5, beta=1)

Generates variates from Zeta (Zipf) distribution

Description

This function implements pseudo-random number generation for a Zeta (Zipf) distribution with pmf

f(xα)=1ζ(α)xαf(x|\alpha)=\frac{1}{\zeta(\alpha)x^{\alpha}}

for x=1,2,3,...x=1,2,3,... and α>1\alpha > 1 where ζ(α)=x=1xα\zeta(\alpha)=\sum_{x=1}^{\infty} x^{-\alpha}.

Usage

draw.zeta(nrep, alpha)

Arguments

nrep

Number of data points to generate.

alpha

Parameter of the desired zeta distribution.

Value

A list of length five containing generated data, the theoretical mean, the empirical mean, the theoretical variance, and the empirical variance with names y, theo.mean, emp.mean, theo.var, and emp.var, respectively.

References

Devroye, L. (1986). Non-Uniform random variate generation. New York: Springer-Verlag.

Examples

draw.zeta(nrep=100000,alpha=4)