Mvnorm {mvtnorm} | R Documentation |
Multivariate Normal Density and Random Deviates
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 = rep(0, p), sigma = diag(p), log = FALSE, checkSymmetry = TRUE)
rmvnorm(n, mean = rep(0, nrow(sigma)), sigma = diag(length(mean)),
method=c("eigen", "svd", "chol"), pre0.9_9994 = FALSE,
checkSymmetry = TRUE, rnorm = stats::rnorm)
Arguments
x |
vector or matrix of quantiles. When |
n |
number of observations. |
mean |
mean vector, default is |
sigma |
covariance matrix, default is |
log |
logical; if |
method |
string specifying the matrix decomposition used to
determine the matrix root of |
pre0.9_9994 |
logical; if |
checkSymmetry |
logical; if |
rnorm |
a function with the same interface as
|
Details
dmvnorm
computes the density function of the multivariate normal
specified by mean and the covariance matrix sigma
.
rmvnorm
generates multivariate normal variables.
See Also
pmvnorm
, rnorm
, qmvnorm
,
vignette("lmvnorm_src", package = "mvtnorm")
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)
dS <- dmvnorm(x, sigma = sigma)
### alternative interface
C <- t(chol(sigma))
(C <- ltMatrices(C[lower.tri(C, diag = TRUE)], diag = TRUE))
dC <- exp(ldmvnorm(obs = t(x), chol = C, logLik = FALSE))
all.equal(dS, dC)
x <- rmvnorm(n=500, mean=c(1,2), sigma=sigma, method="chol")
colMeans(x)
var(x)
plot(x)