Simulation of a Multivariate Normal Distribution with Exact Moments
rmvn.Rd
Simulates a dataset from a multivariate or univariate normal distribution that exactly fulfils the specified mean vector and the covariance matrix.
Usage
# multivariate normal distribution
rmvn(N, mu, Sigma, exact=TRUE)
# univariate normal distribution
ruvn(N, mean=0, sd=1, exact=TRUE)
Arguments
- N
Sample size
- mu
Mean vector
- Sigma
Covariance matrix
- exact
Logical indicating whether
mu
andSigma
should be exactly reproduced.- mean
Numeric value for mean
- sd
Numeric value for standard deviation
Examples
#############################################################################
# EXAMPLE 1: Simulate multivariate normal data
#############################################################################
# define covariance matrix and mean vector
rho <- .8
Sigma <- matrix(rho,3,3)
diag(Sigma) <- 1
mu <- c(0,.5,1)
#* simulate data
set.seed(87)
dat <- sirt::rmvn(N=200, mu=mu, Sigma=Sigma)
#* check means and covariances
stats::cov.wt(dat, method="ML")
if (FALSE) {
#############################################################################
# EXAMPLE 2: Simulate univariate normal data
#############################################################################
#* simulate data
x <- sirt::ruvn(N=20, mean=.5, sd=1.2, exact=TRUE)
# check results
stats::var(x)
sirt:::sirt_var(x)
}