rmvn.Rd
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
############################################################################# # 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) }