multinormal {mc2d}R Documentation

The Vectorized Multivariate Random Deviates

Description

This function is the vectorized version of the rmvnorm from the mvtnorm library. It provides a random number generator for the multivariate normal distribution with varying vectors of means and varying covariance matrixes.

Usage

rmultinormal(n, mean, sigma, method=c("eigen", "svd", "chol"))

Arguments

n Number of observations.
mean Vector of means (if unique for all n) or array of means (if varying according to n).
sigma Covariance vector corresponding to the coercion of the covariance matrix into a vector (if unique for all n) or array of covariance vectors (if varying according to n).
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").

Details

rmvnorm(n, m, s) is equivalent to rmultinormal(n, 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 random deviate will use the second row of mean and/or sigma, ... recycling being permitted by raw. 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 of number of l x 2 columns.

Note

The use of a varying sigma may be very time consumming.

Examples

(mean <- c(10, 0))
(sigma <- matrix(c(1, 2, 2, 10), ncol=2))
(sigma <- as.vector(sigma))
round(rmultinormal(10, mean, sigma)) 

(mean <- matrix(c(10, 0, 0, 10), ncol=2))
round(rmultinormal(10, mean, sigma))

(mean <- c(10, 0))
(sigma <- matrix(c(1, 2, 2, 10, 10, 2, 2, 1), nrow=2, byrow=TRUE))
round(rmultinormal(10, mean, sigma))

(mean <- matrix(c(10, 0, 0, 10), ncol=2))
(sigma <- matrix(c(1, 2, 2, 10, 10, 2, 2, 1), nrow=2, byrow=TRUE))
round(rmultinormal(10, mean, sigma))

(mean <- c(10, 0))
(sigma <- matrix(c(1, 2, 2, 10, 10, 2, 2, 1), nrow=2, byrow=TRUE))
round(x <- rmultinormal(1000, mean, sigma))
plot(x)

[Package mc2d version 0.1-6 Index]