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

Description Usage Arguments Value Examples

View source: R/draw.d.variate.normal.R

Description

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

f(x|μ,Σ)=c\exp{(-\frac{1}{2}(x-μ)^{T}Σ^{-1}(x-μ))}

for -∞ < x < ∞ and c=(2π)^{-d/2}|Σ|^{-1/2}, Σ is symmetric and positive definite, where μ and Σ are the mean vector and the variance-covariance matrix, respectively.

Usage

1
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

1
2
3
4
5
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

Example output

[1]  0.0013719518 -0.0000101128 -0.0022601673
              [,1]          [,2]          [,3]
[1,]  0.0000000000 -0.0006649065 -0.0037267434
[2,] -0.0006649065  0.0000000000  0.0009286447
[3,] -0.0037267434  0.0009286447  0.0000000000

MultiRNG documentation built on March 6, 2021, 1:06 a.m.