Title: | Multivariate Pseudo-Random Number Generation |
---|---|
Description: | Pseudo-random number generation for 11 multivariate distributions: Normal, t, Uniform, Bernoulli, Hypergeometric, Beta (Dirichlet), Multinomial, Dirichlet-Multinomial, Laplace, Wishart, and Inverted Wishart. The details of the method are explained in Demirtas (2004) <DOI:10.22237/jmasm/1099268340>. |
Authors: | Hakan Demirtas, Rawan Allozi, Ran Gao |
Maintainer: | Ran Gao <[email protected]> |
License: | GPL-2 | GPL-3 |
Version: | 1.2.4 |
Built: | 2024-11-16 04:03:44 UTC |
Source: | https://github.com/cran/MultiRNG |
This package implements the algorithms described in Demirtas (2004) for pseudo-random number generation of 11 multivariate distributions. The following multivariate distributions are available: Normal, , Uniform, Bernoulli, Hypergeometric, Beta (Dirichlet), Multinomial, Dirichlet-Multinomial, Laplace, Wishart, and Inverted Wishart.
This package contains 11 main functions and 2 auxiliary functions. The methodology for each random-number generation procedure varies and each distribution has its own function. For multivariate normal, draw.d.variate.normal
employs the Cholesky decomposition and a vector of univariate normal draws and for multivariate ,
draw.d.variate.t
employs the Cholesky decomposition and a vector of univariate normal and chi-squared draws. draw.d.variate.uniform
is based on cdf of multivariate normal deviates (Falk, 1999) and draw.correlated.binary
generates correlated binary variables using an algorithm developed by Park, Park and Shin (1996) and makes use of the auxiliary function loc.min
. draw.multivariate.hypergeometric
employs sequential generation of succeeding conditionals which are univariate hypergeometric. Furthermore, draw.dirichlet
uses the ratios of gamma variates with a common scale parameter and draw.multinomial
generates data via sequential generation of marginals which are binomials. draw.dirichlet.multinomial
is a mixture distribution of a multinomial that is a realization of a random variable having a Dirichlet distribution. draw.multivariate.laplace
is based on generation of a point s on the d-dimensional sphere and utilizes the auxiliary function generate.point.in.sphere
. draw.wishart
and draw.inv.wishart
employs Wishart variates that follow d-variate normal distribution.
Package: | MultiRNG |
Type: | Package |
Version: | 1.2.4 |
Date: | 2021-03-05 |
License: | GPL-2 | GPL-3 |
Hakan Demirtas, Rawan Allozi, Ran Gao
Maintainer: Ran Gao <[email protected]>
Demirtas, H. (2004). Pseudo-random number generation in R for commonly used multivariate distributions. Journal of Modern Applied Statistical Methods, 3(2), 485-497.
Falk, M. (1999). A simple approach to the generation of uniformly distributed random variables with prescribed correlations. Communications in Statistics, Simulation and Computation, 28(3), 785-791.
Park, C. G., Park, T., & Shin D. W. (1996). A simple method for generating correlated binary variates. The American Statistician, 50(4), 306-310.
This function implements pseudo-random number generation for a multivariate normal distribution with pdf
for and
,
is symmetric and positive definite, where
and
are the mean vector and the variance-covariance matrix, respectively.
draw.d.variate.normal(no.row,d,mean.vec,cov.mat)
draw.d.variate.normal(no.row,d,mean.vec,cov.mat)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
mean.vec |
Vector of means. |
cov.mat |
Variance-covariance matrix. |
A matrix of generated data.
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) meanvec=c(0,3,7) mydata=draw.d.variate.normal(no.row=1e5,d=3,mean.vec=meanvec,cov.mat=cmat) apply(mydata,2,mean)-meanvec cor(mydata)-cmat
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) meanvec=c(0,3,7) mydata=draw.d.variate.normal(no.row=1e5,d=3,mean.vec=meanvec,cov.mat=cmat) apply(mydata,2,mean)-meanvec cor(mydata)-cmat
This function implements pseudo-random number generation for a multivariate distribution with pdf
for and
,
is symmetric and positive definite,
, where
,
, and
are the mean vector, the variance-covariance matrix, and the degrees of freedom, respectively.
draw.d.variate.t(dof,no.row,d,mean.vec,cov.mat)
draw.d.variate.t(dof,no.row,d,mean.vec,cov.mat)
dof |
Degrees of freedom. |
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
mean.vec |
Vector of means. |
cov.mat |
Variance-covariance matrix. |
A matrix of generated data.
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) meanvec=c(0,3,7) mydata=draw.d.variate.t(dof=5,no.row=1e5,d=3,mean.vec=meanvec,cov.mat=cmat) apply(mydata,2,mean)-meanvec cor(mydata)-cmat
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) meanvec=c(0,3,7) mydata=draw.d.variate.t(dof=5,no.row=1e5,d=3,mean.vec=meanvec,cov.mat=cmat) apply(mydata,2,mean)-meanvec cor(mydata)-cmat
This function implements pseudo-random number generation for a multivariate uniform distribution with specified mean vector and covariance matrix.
draw.d.variate.uniform(no.row,d,cov.mat)
draw.d.variate.uniform(no.row,d,cov.mat)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
cov.mat |
Variance-covariance matrix. |
A matrix of generated data.
Falk, M. (1999). A simple approach to the generation of uniformly distributed random variables with prescribed correlations. Communications in Statistics, Simulation and Computation, 28(3), 785-791.
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) mydata=draw.d.variate.uniform(no.row=1e5,d=3,cov.mat=cmat) apply(mydata,2,mean)-rep(0.5,3) cor(mydata)-cmat
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) mydata=draw.d.variate.uniform(no.row=1e5,d=3,cov.mat=cmat) apply(mydata,2,mean)-rep(0.5,3) cor(mydata)-cmat
This function implements pseudo-random number generation for a multivariate beta (Dirichlet) distribution with pdf
for ,
, and
, where
are the shape parameters and
is a common scale paramter.
draw.dirichlet(no.row,d,alpha,beta)
draw.dirichlet(no.row,d,alpha,beta)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
alpha |
Vector of shape parameters. |
beta |
Scale parameter common to |
A matrix of generated data.
alpha.vec=c(1,3,4,4) mydata=draw.dirichlet(no.row=1e5,d=4,alpha=alpha.vec,beta=2) apply(mydata,2,mean)-alpha.vec/sum(alpha.vec)
alpha.vec=c(1,3,4,4) mydata=draw.dirichlet(no.row=1e5,d=4,alpha=alpha.vec,beta=2) apply(mydata,2,mean)-alpha.vec/sum(alpha.vec)
This function implements pseudo-random number generation for a Dirichlet-multinomial distribution. This is a mixture distribution that is multinomial with parameter that is a realization of a random variable having a Dirichlet distribution with shape vector
.
is the sample size and
is a common scale parameter.
draw.dirichlet.multinomial(no.row,d,alpha,beta,N)
draw.dirichlet.multinomial(no.row,d,alpha,beta,N)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
alpha |
Vector of shape parameters. |
beta |
Scale parameter common to |
N |
Sample size. |
A matrix of generated data.
draw.dirichlet
, draw.multinomial
alpha.vec=c(1,3,4,4) ; N=3 mydata=draw.dirichlet.multinomial(no.row=1e5,d=4,alpha=alpha.vec,beta=2, N=3) apply(mydata,2,mean)-N*alpha.vec/sum(alpha.vec)
alpha.vec=c(1,3,4,4) ; N=3 mydata=draw.dirichlet.multinomial(no.row=1e5,d=4,alpha=alpha.vec,beta=2, N=3) apply(mydata,2,mean)-N*alpha.vec/sum(alpha.vec)
This function implements pseudo-random number generation for an inverted Wishart distribution with pdf
is positive definite,
, and
is symmetric and positive definite, where
and
are the degrees of freedom and the inverse scale matrix, respectively.
draw.inv.wishart(no.row,d,nu,inv.sigma)
draw.inv.wishart(no.row,d,nu,inv.sigma)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
nu |
Degrees of freedom. |
inv.sigma |
Inverse scale matrix. |
A matrix ofcontaining Wishart deviates in the form of rows. To obtain the Inverted-Wishart matrix, convert each row to a matrix where rows are filled first.
mymat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) draw.inv.wishart(no.row=1e5,d=3,nu=5,inv.sigma=mymat)
mymat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) draw.inv.wishart(no.row=1e5,d=3,nu=5,inv.sigma=mymat)
This function implements pseudo-random number generation for a multivariate multinomial distribution with pdf
for ,
, and
, where
are cell probabilities and
is the size.
draw.multinomial(no.row,d,theta,N)
draw.multinomial(no.row,d,theta,N)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
theta |
Vector of cell probabilities. |
N |
Sample Size. Must be at least 2. |
A matrix of generated data.
theta.vec=c(0.3,0.3,0.25,0.15) ; N=4 mydata=draw.multinomial(no.row=1e5,d=4,theta=c(0.3,0.3,0.25,0.15),N=4) apply(mydata,2,mean)-N*theta.vec
theta.vec=c(0.3,0.3,0.25,0.15) ; N=4 mydata=draw.multinomial(no.row=1e5,d=4,theta=c(0.3,0.3,0.25,0.15),N=4) apply(mydata,2,mean)-N*theta.vec
This function implements pseudo-random number generation for a multivariate hypergeometric distribution.
draw.multivariate.hypergeometric(no.row,d,mean.vec,k)
draw.multivariate.hypergeometric(no.row,d,mean.vec,k)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
mean.vec |
Number of items in each category. |
k |
Number of items to be sampled. Must be a positive integer. |
A matrix of generated data.
Demirtas, H. (2004). Pseudo-random number generation in R for commonly used multivariate distributions. Journal of Modern Applied Statistical Methods, 3(2), 485-497.
meanvec=c(10,10,12) ; myk=5 mydata=draw.multivariate.hypergeometric(no.row=1e5,d=3,mean.vec=meanvec,k=myk) apply(mydata,2,mean)-myk*meanvec/sum(meanvec)
meanvec=c(10,10,12) ; myk=5 mydata=draw.multivariate.hypergeometric(no.row=1e5,d=3,mean.vec=meanvec,k=myk) apply(mydata,2,mean)-myk*meanvec/sum(meanvec)
This function implements pseudo-random number generation for a multivariate Laplace (double exponential) distribution with pdf
for and
,
is symmetric and positive definite, where
,
, and
are the mean vector, the variance-covariance matrix, and the shape parameter, respectively.
draw.multivariate.laplace(no.row,d,gamma,mu,Sigma)
draw.multivariate.laplace(no.row,d,gamma,mu,Sigma)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
gamma |
Shape parameter. |
mu |
Vector of means. |
Sigma |
Variance-covariance matrix. |
A matrix of generated data.
Ernst, M. D. (1998). A multivariate generalized Laplace distribution. Computational Statistics, 13, 227-232.
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) mu.vec=c(0,3,7) mydata=draw.multivariate.laplace(no.row=1e5,d=3,gamma=2,mu=mu.vec,Sigma=cmat) apply(mydata,2,mean)-mu.vec cor(mydata)-cmat
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) mu.vec=c(0,3,7) mydata=draw.multivariate.laplace(no.row=1e5,d=3,gamma=2,mu=mu.vec,Sigma=cmat) apply(mydata,2,mean)-mu.vec cor(mydata)-cmat
This function implements pseudo-random number generation for a Wishart distribution with pdf
is positive definite,
, and
is symmetric and positive definite, where
and
are positive definite and the scale matrix, respectively.
draw.wishart(no.row,d,nu,sigma)
draw.wishart(no.row,d,nu,sigma)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
nu |
Degrees of freedom. |
sigma |
Scale matrix. |
A matrix of Wishart deviates in the form of rows.To obtain the Wishart matrix, convert each row to a matrix where rows are filled first.
mymat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) draw.wishart(no.row=1e5,d=3,nu=5,sigma=mymat)
mymat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) draw.wishart(no.row=1e5,d=3,nu=5,sigma=mymat)
This function generates s points on a d-dimensional sphere.
generate.point.in.sphere(no.row,d)
generate.point.in.sphere(no.row,d)
no.row |
Number of rows to generate. |
d |
Number of variables to generate. |
A matrix of coordinates of points in sphere.
Marsaglia, G. (1972). Choosing a point from the surface of a sphere. Annals of Mathematical Statistics, 43, 645-646.
generate.point.in.sphere(no.row=1e5,d=3)
generate.point.in.sphere(no.row=1e5,d=3)
This function identifies the location of the minimum value in a square matrix.
loc.min(my.mat,d)
loc.min(my.mat,d)
my.mat |
A square matrix. |
d |
Dimensions of the matrix. |
A vector containing the row and column number of the minimum value.
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) loc.min(my.mat=cmat, d=3)
cmat<-matrix(c(1,0.2,0.3,0.2,1,0.2,0.3,0.2,1), nrow=3, ncol=3) loc.min(my.mat=cmat, d=3)