| simulate_factors | R Documentation |
Draws factor scores from a multivariate normal with unit variances and
correlation factor_correlation, then forms each indicator as
intercept + loadings %*% scores + error, where the error standard
deviation is sqrt(uniqueness). The implied population covariance is
loadings %*% factor_correlation %*% t(loadings) + diag(uniquenesses).
Because the factors have unit variance, the loadings are on the
standardized-factor metric.
simulate_factors(
n,
loadings,
uniquenesses = NULL,
factor_correlation = NULL,
intercepts = 0,
include_scores = FALSE,
seed = NULL,
batch = NULL
)
n |
Number of observations. A single whole number of at least 2. |
loadings |
Variable-by-factor loading matrix (one row per indicator,
one column per factor, at least 2 rows), or a tidy data frame with
columns |
uniquenesses |
Residual variances (not standard deviations), a
scalar recycled across indicators or one non-negative value per
indicator. |
factor_correlation |
Optional factor correlation matrix, or a tidy
data frame with columns |
intercepts |
Variable intercepts, a scalar recycled across indicators
(the default, |
include_scores |
Single flag; when |
seed |
Optional random seed. |
batch |
Optional single positive whole number. When given, the
simulator runs |
A simulab_sim base data.frame with one row per observation and
columns id and one per indicator, plus one column per factor when
include_scores = TRUE. A parameters component holds one row per
variable-by-factor combination with columns variable, factor,
loading, uniqueness and intercept; a covariance component holds
the implied population covariance in tidy form, one row per variable
pair, with columns row, column and covariance.
# `loadings` is one row per item and one column per factor.
loadings <- matrix(
c(0.8, 0.7, 0.6, 0, 0, 0,
0, 0, 0, 0.8, 0.7, 0.6),
ncol = 2
)
result <- simulate_factors(n = 300, loadings = loadings, seed = 1)
head(result)
as.data.frame(result, what = "parameters")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.