Learn R Programming

MultiRNG (version 1.2.4)

draw.d.variate.normal: Pseudo-Random Number Generation under Multivariate Normal Distribution

Description

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

$$f(x|\mu,\Sigma)=c\exp{(-\frac{1}{2}(x-\mu)^{T}\Sigma^{-1}(x-\mu))}$$

for \(-\infty < x < \infty\) and \(c=(2\pi)^{-d/2}|\Sigma|^{-1/2}\), \(\Sigma\) is symmetric and positive definite, where \(\mu\) and \(\Sigma\) are the mean vector and the variance-covariance matrix, respectively.

Usage

draw.d.variate.normal(no.row,d,mean.vec,cov.mat)

Arguments

no.row

Number of rows to generate.

d

Number of variables to generate.

mean.vec

Vector of means.

cov.mat

Variance-covariance matrix.

Value

A \(no.row \times d\) matrix of generated data.

Examples

Run this code
# NOT RUN {
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
# }

Run the code above in your browser using DataLab