Generates an \(n \times k\) multivariate data matrix or a list of \(n \times k\) multivariate data matrices of length R from the multivariate normal distribution $$ \mathbf{X} \sim \mathcal{N}_{k} \left( \boldsymbol{\mu}, \boldsymbol{\Sigma} \right) . %(\#eq:dist-X-mvn) $$ The model-implied matrices used to generate data is derived from the Reticular Action Model (RAM) Matrices.

mvnramsigma2(
  n,
  mu = NULL,
  M = NULL,
  A,
  sigma2,
  F,
  I,
  tol = 1e-06,
  empirical = FALSE,
  df = FALSE,
  varnames = NULL,
  R = NULL,
  par = FALSE,
  ncores = NULL,
  mc = TRUE,
  lb = FALSE,
  cl_eval = FALSE,
  cl_export = FALSE,
  cl_expr,
  cl_vars
)

Arguments

n

Integer. Sample size.

mu

Numeric vector. Location parameter mean vector \(\boldsymbol{\mu}\) of length \(k\).

M

Numeric vector. Mean structure. Vector of means and intercepts.

A

\(\mathbf{A}\) matrix. Asymmetric paths (single-headed arrows), such as regression coefficients and factor loadings.

sigma2

Numeric vector. Vector of variances \(\sigma^2\). The first element should be the variance of an exogenous variable.

F

\(\mathbf{F}\) matrix. Filter matrix used to select the observed variables.

I

\(\mathbf{I}\) matrix. Identity matrix.

tol

Numeric. Tolerance (relative to largest variance) for numerical lack of positive-definiteness in Sigma.

empirical

Logical. If TRUE, mu and Sigma specify the empirical, not population. mean and covariance matrix.

df

Logical. If TRUE, the function returns a data frame. If FALSE, the function returns a matrix.

varnames

Character string. Optional column names with the same length as mu.

R

Integer. Number of Monte Carlo replications. If R is not provided, the function produces a single random data set. If R is an integer greater than 1, (e.g., R = 10), the function produces multiple random data sets stored in each element of a list of length R. par and all succeeding arguments are only relevant when R > 1.

par

Logical. If TRUE, use multiple cores. If FALSE, use lapply().

ncores

Integer. Number of cores to use if par = TRUE. If unspecified, defaults to detectCores() - 1.

mc

Logical. If TRUE, use parallel::mclapply(). If FALSE, use parallel::parLapply() or parallel::parLapplyLB(). Ignored if par = FALSE.

lb

Logical. If TRUE use parallel::parLapplyLB(). If FALSE, use parallel::parLapply(). Ignored if par = FALSE and mc = TRUE.

cl_eval

Logical. Execute parallel::clusterEvalQ() using cl_expr. Ignored if mc = TRUE.

cl_export

Logical. Execute parallel::clusterExport() using cl_vars. Ignored if mc = TRUE.

cl_expr

Expression. Expression passed to parallel::clusterEvalQ() Ignored if mc = TRUE.

cl_vars

Character vector. Names of objects to pass to parallel::clusterExport() Ignored if mc = TRUE.

Value

If R = NULL or R = 1, returns an \(n \times k\) multivariate normal data matrix or data frame . If R is an integer greater than 1, (e.g., R = 10) returns a list of length R of \(n \times k\) multivariate normal data matrix or data frame.

Details

The \(\mathbf{S}\) matrix is derived from a vector of variances sigma2 \(\left( \sigma^2 \right)\) and the proceeds to generating data using the mvnram() function. The first element in sigma2 should be the variance of an exogenous variable.

See also

Other multivariate data functions: mvnram(), mvn()

Examples

mu <- c(100, 100, 100) A <- matrix( data = c(0, sqrt(0.26), 0, 0, 0, sqrt(0.26), 0, 0, 0), ncol = 3 ) sigma2 <- c(225, 225, 225) F <- I <- diag(3) X <- mvnramsigma2(n = 100, mu = mu, A = A, sigma2 = sigma2, F = F, I = I) str(X)
#> num [1:100, 1:3] 83.5 92.2 104.9 95.6 103.7 ... #> - attr(*, "dimnames")=List of 2 #> ..$ : NULL #> ..$ : NULL
Xstar <- mvnramsigma2(n = 100, mu = mu, A = A, sigma2 = sigma2, F = F, I = I, R = 100) str(Xstar, list.len = 6)
#> List of 100 #> $ : num [1:100, 1:3] 98.7 97.1 74.3 113.9 95.2 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : NULL #> $ : num [1:100, 1:3] 87.3 81.4 101.1 92.8 85.4 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : NULL #> $ : num [1:100, 1:3] 123 117 108 119 122 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : NULL #> $ : num [1:100, 1:3] 106 100 113 137 88 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : NULL #> $ : num [1:100, 1:3] 80.3 78.2 103.6 83.7 90.8 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : NULL #> $ : num [1:100, 1:3] 90.1 128.7 107.1 109.1 131.4 ... #> ..- attr(*, "dimnames")=List of 2 #> .. ..$ : NULL #> .. ..$ : NULL #> [list output truncated]