This function generates observed sample data from a specified factor model. It supports continuous or categorical indicators, missingness, correlated latent factors, optional cross-loadings, local dependence, and structured residual covariance. The function can simulate: - Standard CFA models - Bifactor models - MTMM models - Models with cross-loading perturbations - Models with local residual correlations - Categorical response data - Missing data mechanisms

sim_data(
  N = 1000,
  lam,
  phi = 0.3,
  ecm = NULL,
  ecr = 0,
  necw = 0,
  necb = 0,
  fixloading = 0,
  Kg = 0,
  std = T,
  cati = NULL,
  noc = c(4),
  misp = 0,
  fac_score = FALSE,
  rseed = 333,
  digits = 4
)

Arguments

N

Integer. Sample size.

lam

Matrix. True loading

phi

Numeric/Matrix. Correlation among latent factors.

ecm

Matrix. Residual covariance matrix. If NULL, generated internally.

ecr

Numeric. Residual correlation strength.

necw

Integer. Number of residual covariance elements within blocks.

necb

Integer. Number of residual covariance elements between blocks.

fixloading

Logical or numeric indicator for identification constraints.

Kg

Integer. Number of general factors (0 corresponds to simple CFA).

std

Logical. Whether to standardize latent variables.

cati

Numeric vector. The set of polytomous items in sequence number (i.e., can be any number set in between 1 and J); NULL for no and -1 for all .

noc

Numeric vector. Number of levels for polytomous items. (if categorical).

misp

Numeric. Proportion of missingness..

fac_score

Logical. Whether to return true latent factor scores.

rseed

Integer. Random seed for reproducibility.

digits

Integer. Rounding precision of output.

Value

A list containing:

lam

Loading matrix used for data generation.

PHI

Latent factor correlation matrix.

Eigen

common variance contributed by each factor.

scale

Empirical item standard deviations.

var_ie

residual (unique) variance proportion.

fac

True latent factor scores (returned if fac_score = TRUE).

dat

Simulated observed data matrix.

fixloading

Identification constraint indicator for fixed loadings.

std

Logical flag indicating whether latent variables were standardized.

Details

Data are generated according to the factor model:

X = Lambda F + epsilon