mvnorm: The Multivariate Normal Distribution In lcmix: Layered and chained mixture models

Description

Density and random generation functions for the multivariate normal distribution.

Usage

 ```1 2``` ```dmvnorm(x, mean=rep(0, ncol(x)), cov=diag(ncol(x)), log=FALSE) rmvnorm(n, mean=NULL, cov=NULL) ```

Arguments

 `x` a numeric matrix of which each row represents an observation. `mean` a vector of column means. `cov` a covariance matrix. `log` logical; if `TRUE`, density is given as the log-density. `n` number of vectors to simulate.

Details

See Evans et al. (2000) for one of many references on the multivariate normal density.

For `rmvnorm`, if the `mean` argument is `NULL`, then the scalar 0 will be used by default, unless `cov` is not `NULL`, in which case `mean = rep(0, nrow(cov))` will be used. If the `cov` argument is `NULL`, then `diag(length(mean))` will be used by default. Thus `rmvnorm(n)` is equivalent to `rnorm(n)`.

Value

For `dmvnorm`, a vector of densities. For `rmvnorm`, a vector with `n` rows and `length(mean)` columns representing a sample from the multivariate normal distribution with the specified parameters.

Daniel Dvorkin

References

Evans, M., Hastings, N., and Peacock, B. (2000) Statistical Distributions, third edition, John Wiley & Sons.

`mvgamma`, `mvweisd` for related distributions; `Normal` in package `stats`; `dmvnorm` and `rmvnorm` in package `mixtools`.
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16``` ```set.seed(123) m = c(-3, 0, 3) v = cov(matrix(rnorm(90), ncol=3)) x = rmvnorm(5, m, v) print(x) # [,1] [,2] [,3] # [1,] -2.0498637 0.3599609 3.218045 # [2,] -3.7479240 1.2302183 2.290916 # [3,] -0.9852752 1.1433559 2.790147 # [4,] -3.9353966 -0.5451158 3.223321 # [5,] -3.2864769 -0.1672326 2.201353 dmvnorm(x, m, v) # 0.048079901 0.025591976 0.002587824 0.041810685 0.054688032 ```