rmnorm {fastmatrix} | R Documentation |
Multivariate normal random deviates
Description
Random number generation from the multivariate normal (Gaussian) distribution.
Usage
rmnorm(n = 1, mean = rep(0, nrow(Sigma)), Sigma = diag(length(mean)))
Arguments
n |
the number of samples requested |
mean |
a vector giving the means of each variable |
Sigma |
a positive-definite covariance matrix |
Details
The function rmnorm
is an interface to C
routines, which make calls
to subroutines from LAPACK. The matrix decomposition is internally done using the
Cholesky decomposition. If Sigma
is not non-negative definite then there
will be a warning message.
Value
If n = 1
a vector of the same length as mean
, otherwise a
matrix of n
rows of random vectors.
References
Devroye, L. (1986). Non-Uniform Random Variate Generation. Springer-Verlag, New York.
See Also
Examples
# covariance parameters
Sigma <- matrix(c(10,3,3,2), ncol = 2)
Sigma
# generate the sample
y <- rmnorm(n = 1000, Sigma = Sigma)
var(y)
# scatterplot of a random bivariate normal sample with mean
# vector zero and covariance matrix 'Sigma'
par(pty = "s")
plot(y, xlab = "", ylab = "")
title("bivariate normal sample", font.main = 1)
# QQ-plot of transformed distances
z <- WH.normal(y)
par(pty = "s")
qqnorm(z, main = "Transformed distances QQ-plot")
abline(c(0,1), col = "red", lwd = 2, lty = 2)
[Package fastmatrix version 0.5-772 Index]