Type: | Package |
Title: | Univariate Pseudo-Random Number Generation |
Version: | 1.2.3 |
Date: | 2021-03-05 |
Author: | Hakan Demirtas, Rawan Allozi, Ran Gao |
Maintainer: | Ran Gao <rgao8@uic.edu> |
Description: | Pseudo-random number generation of 17 univariate distributions proposed by Demirtas. (2005) <doi:10.22237/jmasm/1114907220>. |
License: | GPL-2 | GPL-3 |
NeedsCompilation: | no |
Packaged: | 2021-03-05 17:31:02 UTC; rangao |
Repository: | CRAN |
Date/Publication: | 2021-03-05 18:10:02 UTC |
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 t
, Non-central Chi-squared, Doubly non-central F
, Standard t
, 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/\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 <rgao8@uic.edu>
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(\alpha,\beta)<1
Description
This function implements pseudo-random number generation for a Beta distribution for \max(\alpha,\beta)<1
with pdf
f(x|\alpha,\beta)=\frac{1}{B(\alpha,\beta)}x^{\alpha-1}(1-x)^{\beta-1}
for 0 \leq x \leq 1
, 0 < \alpha < 1
, and 0 < \beta < 1
where \alpha
and \beta
are the shape parameters and 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(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,...
, \alpha>0
, and \beta>0
, where n
is the sample size, \alpha
and \beta
are the shape parameters and 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 \alpha>1
Description
This function implements pseudo-random number generation for a Gamma distribution for \alpha>1
with pdf
f(x|\alpha,\beta)=\frac{1}{\Gamma(\alpha)\beta^{\alpha}}x^{\alpha-1}e^{-x/\beta}
for 0 \leq x < \infty
and \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 \alpha<1
Description
This function implements pseudo-random number generation for a gamma distribution for \alpha<1
with pdf
f(x|\alpha,\beta)=\frac{1}{\Gamma(\alpha)\beta^{\alpha}}x^{\alpha-1}e^{-x/\beta}
for 0 \leq x < \infty
and \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|\mu,\lambda)=(\frac{\lambda}{2\pi})^{1/2}x^{-3/2}e^{-\frac{\lambda(x-\mu)^2}{2\mu^2x}}
for x > 0
, \mu > 0
, and \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|\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|\alpha, \beta) = \frac{1}{(\Gamma(\alpha)-\Gamma_{\tau/\beta}(\alpha))\beta^{\alpha}}x^{\alpha-1}e^{-x/\beta}
for 0<\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|\theta) = - \frac{\theta^{x}}{x\log(1-\theta)}
for x=1,2,3,...
and 0 < \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 doubly non-central F distribution
Description
This function implements pseudo-random number generation for a doubly non-central F
distribution
F=\frac{X_{1}^{2}/n}{X_{2}^{2}/m}
where X_{1}^{2}\sim \chi^{2}(n,\lambda_{1})
, X_{2}^{2}\sim \chi^{2}(m,\lambda_{2})
, n
and m
are numerator and denominator degrees of freedom, respectively, and \lambda_{1}
and \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
Examples
draw.noncentral.F(nrep=100000,dof1=2,dof2=4,ncp1=2,ncp2=4)
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|\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 0 \leq x < \infty
, \lambda>0
, and \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 t distribution
Description
This function implements pseudo-random number generation for a non-central t
distribution
\frac{Y}{\sqrt{U/\nu}}
where U
is a central chi-square random variable with \nu
degrees of freedom and Y
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|\alpha,\beta)=\frac{ab^{a}}{x^{a+1}}
for 0 < b \leq x < \infty
and a>0
where a
and b
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|\sigma)=\frac{x}{\sigma^2}e^{-x^2/2\sigma^2}
for x \geq 0
and \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-t
distribution with pdf
f(x|\nu)=\frac{\Gamma(\frac{\nu+1}{2})}{\Gamma(\frac{\nu}{2})\sqrt{\nu\pi}}(1+\frac{x^2}{\nu})^{-(\nu+1)/2}
for -\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(x|K)=\frac{1}{2\pi I_{0}(K)}e^{Kcos(x)}
for -\pi \leq x \leq \pi
and K > 0
where 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|\alpha,\beta)=\frac{\alpha}{\beta^{\alpha}}x^{\alpha-1}e^{-(x/\beta)^{\alpha}}
for 0 \leq x < \infty
and \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|\alpha)=\frac{1}{\zeta(\alpha)x^{\alpha}}
for x=1,2,3,...
and \alpha > 1
where \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)