mvrnormArma {anMC} | R Documentation |
Simulates realizations from a multivariate normal with mean mu and covariance matrix sigma.
mvrnormArma(n, mu, sigma, chol)
n |
number of simulations. |
mu |
mean vector. |
sigma |
covariance matrix or Cholesky decomposition of the matrix (see chol). |
chol |
integer, if 0 sigma is a covariance matrix, otherwise it is the Cholesky decomposition of the matrix. |
A matrix of size d x n containing the samples.
# Simulate 1000 realizations from a multivariate normal vector mu <- rep(0,200) Sigma <- diag(rep(1,200)) realizations<-mvrnormArma(n=1000,mu = mu,sigma=Sigma, chol=0) empMean<-rowMeans(realizations) empCov<-cov(t(realizations)) # check if the sample mean is close to the actual mean maxErrorOnMean<-max(abs(mu-empMean)) # check if we can estimate correctly the covariance matrix maxErrorOnVar<-max(abs(rep(1,200)-diag(empCov))) maxErrorOnCov<-max(abs(empCov[lower.tri(empCov)])) ## Not run: plot(density(realizations[2,])) ## End(Not run)