# Generate hierarchical factor data
# 4 lower-order factors (2 per higher-order factor), 2 higher-order factors
hierarchical <- simulate_hierarchical_factors(
lower_factors = 4, # lower-order factors = 4
variables = 6, # variables per lower-order factor = 6
lower_loadings = 0.55, # lower-order loadings = 0.45 to 0.65
lower_cross_loadings = 0.05, # lower-order cross-loadings N(0, 0.05)
higher_factors = 2, # higher-order factors = 2
higher_loadings = 0.60, # higher-order loadings = 0.50 to 0.70
higher_cross_loadings = 0.05, # higher-order cross-loadings N(0, 0.05)
higher_correlations = 0.30, # correlation between higher-order factors = 0.30
off_disturbances = 0.10, # off-diagonal (correlated) disturbances = 0.10
sample_size = 1000 # number of cases = 1000
)
# Different number of lower-order factors per higher-order factor
# 6 lower-order factors (2 on higher-order factor A, 4 on higher-order factor B)
hierarchical_uneven <- simulate_hierarchical_factors(
lower_factors = 6, variables = 6,
lower_loadings = 0.55, lower_cross_loadings = 0.05,
higher_factors = 2, higher_variables = c(2, 4), # A = 2 factors, B = 4 factors
higher_loadings = 0.60, higher_cross_loadings = 0.05,
higher_correlations = 0.30, off_disturbances = 0.10,
sample_size = 1000
)
# Randomly vary higher-order loadings
hierarchical_loadings <- simulate_hierarchical_factors(
lower_factors = 4, variables = 6,
lower_loadings = 0.55, lower_cross_loadings = 0.05,
higher_factors = 2,
higher_loadings_range = c(0.40, 0.80), # higher-order loadings = 0.40 to 0.80
higher_cross_loadings = 0.05,
higher_correlations = 0.30,
off_disturbances_range = c(0.00, 0.20), # off-diagonal disturbances = 0.00 to 0.20
sample_size = 1000
)
# Generate dichotomous data
hierarchical_dichotomous <- simulate_hierarchical_factors(
lower_factors = 4, variables = 6,
lower_loadings = 0.55, lower_cross_loadings = 0.05,
higher_factors = 2, higher_loadings = 0.60,
higher_cross_loadings = 0.05, higher_correlations = 0.30,
off_disturbances = 0.10, sample_size = 1000,
variable_categories = 2 # dichotomous data
)
# Supply a target lower-order correlation matrix directly instead of `off_disturbances`;
# the disturbances are implied (solved for) and may end up correlated
hierarchical_lower_correlations <- simulate_hierarchical_factors(
lower_factors = 4, variables = 6,
lower_loadings = 0.55, lower_cross_loadings = 0.05,
lower_correlations = 0.40, # target correlation of 0.40 between all lower-order factors
higher_factors = 2, higher_loadings = 0.60,
higher_cross_loadings = 0.05, higher_correlations = 0.30,
sample_size = 1000
)
# Omit `higher_correlations` when `lower_correlations` is supplied: it is implied
# (rather than the disturbances) from the target lower-order correlations and `higher_loadings`
hierarchical_implied_correlations <- simulate_hierarchical_factors(
lower_factors = 4, variables = 6,
lower_loadings = 0.55, lower_cross_loadings = 0.05,
lower_correlations = 0.40, # target correlation of 0.40 between all lower-order factors
higher_factors = 2, higher_loadings = 0.60,
higher_cross_loadings = 0.05,
sample_size = 1000
)
Run the code above in your browser using DataLab