rmvn | R Documentation |
Simulates a dataset from a multivariate or univariate normal distribution that exactly fulfils the specified mean vector and the covariance matrix.
# multivariate normal distribution
rmvn(N, mu, Sigma, exact=TRUE)
# univariate normal distribution
ruvn(N, mean=0, sd=1, exact=TRUE)
N |
Sample size |
mu |
Mean vector |
Sigma |
Covariance matrix |
exact |
Logical indicating whether |
mean |
Numeric value for mean |
sd |
Numeric value for standard deviation |
A dataframe or a vector
mvtnorm::rmvnorm
, mgcv::rmvn
#############################################################################
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.