Mvnorm {mvtnorm}R Documentation

Multivariate Normal Density and Random Numbers

Description

These functions provide the density function and a random number generator for the multivariate normal distribution with mean equal to mean and covariance matrix sigma.

Usage

dmvnorm(x, mean, sigma, log=FALSE)
rmvnorm(n, mean, sigma, method=c("svd", "chol"))

Arguments

x Vector or matrix of quantiles. If x is a matrix, each row is taken to be a quantile.
n Number of observations.
mean Mean vector, default is rep(0, length = ncol(x)).
sigma Covariance matrix, default is diag(ncol(x)).
log Logical; if TRUE, densities d are given as log(d).
method Matrix decomposition used to determine the matrix root of sigma, possible methods are singular value decomposition ("svd", default) and Cholesky decomposition ("chol").

Details

SVD will work even for numerically negative definite sigma (with a warning), while the Cholesky decomposition is possible only for non-negative definite sigma and issues a warning for positive semi-definiteness. Using method = "chol" may be faster and more stable for higher dimensional sigma.

Author(s)

Friedrich Leisch <Friedrich.Leisch@R-project.org>, Fabian Scheipl

See Also

pmvnorm, rnorm, qmvnorm

Examples

dmvnorm(x=c(0,0))
dmvnorm(x=c(0,0), mean=c(1,1))

sigma <- matrix(c(4,2,2,3), ncol=2)
x <- rmvnorm(n=500, mean=c(1,2), sigma=sigma)
colMeans(x)
var(x)

x <- rmvnorm(n=500, mean=c(1,2), sigma=sigma, method="chol")
colMeans(x)
var(x)

plot(x)

[Package mvtnorm version 0.8-1 Index]