| multinormal | R Documentation |
Vectorized versions of rmvnorm and dmvnorm
from the mvtnorm package, providing random deviates and density for the multivariate
normal distribution with varying vectors of means and varying covariance matrices.
rmultinormal(n, mean, sigma, method = c("eigen", "svd", "chol"))
dmultinormal(x, mean, sigma, log = FALSE)
n |
number of observations. If ‘length(n) > 1’, the length is taken to be the number required. |
mean |
vector or matrix of means. If a matrix, each row is taken to be a mean vector. Default is a vector of 0 of convenient length. |
sigma |
covariance vector corresponding to the coercion of the covariance matrix into a vector (if unique for all ‘n’ or ‘x’) or array of covariance vectors (if varying). Default is a diagonal matrix of convenient size. |
method |
matrix decomposition used to determine the matrix root of sigma. Possible methods are eigenvalue decomposition (‘"eigen"’, default), singular value decomposition (‘"svd"’), and Cholesky decomposition (‘"chol"’). |
x |
vector or matrix of quantiles. If x is a matrix, each row is taken to be a quantile. |
log |
logical; if ‘TRUE’, densities d are given as ‘log(d)’. |
‘rmvnorm(n, m, s)’ is equivalent to ‘rmultinormal(n, m, as.vector(s))’. ‘dmvnorm(x, m, s)’ is equivalent to ‘dmultinormal(x, m, as.vector(s))’.
If ‘mean’ and/or ‘sigma’ is a matrix, the first random deviate will use the first row of ‘mean’ and/or ‘sigma’, the second will use the second row, ... recycling being permitted by row.
If ‘mean’ is a vector of length ‘l’ or is a matrix with ‘l’ columns, ‘sigma’ should be a vector of length ‘l x l’ or a matrix with ‘l^2’ columns.
The use of a varying sigma may be very time consuming.
## mean and sigma as vectors
(mean <- c(10, 0))
(sigma <- matrix(c(1, 2, 2, 10), ncol = 2))
sigma <- as.vector(sigma)
(x <- matrix(c(9, 8, 1, -1), ncol = 2))
round(rmultinormal(10, mean, sigma))
dmultinormal(x, mean, sigma)
## mean as matrix
(mean <- matrix(c(10, 0, 0, 10), ncol = 2))
round(rmultinormal(10, mean, sigma))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.