rmvn: Simulation of a Multivariate Normal Distribution with Exact...

View source: R/rmvn.R

rmvnR Documentation

Simulation of a Multivariate Normal Distribution with Exact Moments

Description

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 and Sigma should be exactly reproduced.

mean

Numeric value for mean

sd

Numeric value for standard deviation

Value

A dataframe or a vector

See Also

mvtnorm::rmvnorm, mgcv::rmvn

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")

## Not run: 
#############################################################################
# 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)

## End(Not run)

alexanderrobitzsch/sirt documentation built on March 18, 2024, 1:29 p.m.