rmvtnorm: Random multivariate normal variables

Description Usage Arguments Details Value Author(s) Examples

View source: R/rmvtnorm.R

Description

Draw vectors from a multivariate normal distribution.

Usage

1
rmvtnorm (n = 1, k = 2, means = rep (0, k), sigma = diag (k))

Arguments

n

The number of vectors to be drawn.

k

The dimension of the vectors to be drawn.

means

A vector of means, one for each dimension.

sigma

The covariance matrix of the distribution. If a number between 0 and 1 is provided, this is assumed to be the correlation parameter for a bivariate standard normal distribution.

Details

If means and sigma are not specified, a standard normal distribution is assumed along every dimensions, and dimensions are assumed to be uncorrelated. If the number of dimensions is not specified, a bivariate distribution is assumed.

Value

A matrix with rows equal to n and columns equal to k, where each row indicates a single observation, and each column represents a different dimension.

Author(s)

Santiago Barreda <[email protected]>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
## Examples of draws from different bivariate normal distributions
## and standard deviation ellipses drawn to fit them.
par (mfrow = c(2,2))
draws = rmvtnorm (n = 1000, k = 2, sigma = .3)
plot (draws)
sdellipse (draws, stdev = 3, lwd = 3, col = 2)

draws = rmvtnorm (n = 1000, k = 2, sigma = -.3)
plot (draws)
sdellipse (draws, stdev = 3, lwd = 3, col = 2)

draws = rmvtnorm (n = 1000, k = 2, sigma = -.7)
plot (draws)
sdellipse (draws, stdev = 3, lwd = 3, col = 2)

draws = rmvtnorm (n = 1000, k = 2, sigma = .7)
plot (draws)
sdellipse (draws, stdev = 3, lwd = 3, col = 2)

phonTools documentation built on May 29, 2017, 9 a.m.