The main underlying functions to extract parameters and fit statistics come from the broom
package: broom::tidy()
and broom::glance()
. The functions extract_param()
and extract_fit()
offer some tools that I find helpful when running LCS models in R, for example:
extract_param()
: only one row per estimated parameter,extract_fit()
: fit statistics for multiple lavaan
objects can be extracted.# First fit some latent change score models
# No change model
uni_lcsm_01 <- fit_uni_lcsm(data = data_bi_lcsm,
var = c("x1", "x2", "x3", "x4", "x5"),
model = list(alpha_constant = FALSE,
beta = FALSE,
phi = FALSE))
# Constant change only model
uni_lcsm_02 <- fit_uni_lcsm(data = data_bi_lcsm,
var = c("x1", "x2", "x3", "x4", "x5"),
model = list(alpha_constant = TRUE,
beta = FALSE,
phi = FALSE))
# Constant change and proportional change (Dual change model)
uni_lcsm_03 <- fit_uni_lcsm(data = data_bi_lcsm,
var = c("x1", "x2", "x3", "x4", "x5"),
model = list(alpha_constant = TRUE,
beta = TRUE,
phi = FALSE))
This function takes the lavaan
objects as input and returns some fit statistics. More fit statistics can be returned using the argument details = TRUE
.
# Extract fit statistics
fit_uni_lcsm <- extract_fit(uni_lcsm_01, uni_lcsm_02, uni_lcsm_03)
# Print table of parameter estimates
knitr::kable(fit_uni_lcsm,
digits = 3,
caption = "Parameter estimates for bivariate LCSM")
model | chisq | npar | aic | bic | cfi | rmsea | srmr |
---|---|---|---|---|---|---|---|
1 | 6527.339 | 3 | 12138.847 | 12151.490 | 0.000 | 0.875 | 6.265 |
2 | 33.281 | 6 | 5650.789 | 5676.076 | 0.994 | 0.052 | 0.053 |
3 | 33.159 | 7 | 5652.666 | 5682.169 | 0.993 | 0.056 | 0.052 |
# Now extract parameter estimates
param_uni_lcsm_02 <- extract_param(uni_lcsm_03, printp = TRUE)
# Print table of parameter estimates
knitr::kable(param_uni_lcsm_02,
digits = 3,
caption = "Parameter estimates for bivariate LCSM")
label | estimate | std.error | statistic | p.value | conf.low | conf.high | std.lv | std.all | std.nox |
---|---|---|---|---|---|---|---|---|---|
gamma_lx1 | 21.075 | 0.037 | 565.047 | < .001 | 21.002 | 21.149 | 30.574 | 30.574 | 30.574 |
sigma2_lx1 | 0.475 | 0.038 | 12.420 | < .001 | 0.400 | 0.550 | 1.000 | 1.000 | 1.000 |
sigma2_ux | 0.213 | 0.008 | 26.674 | < .001 | 0.198 | 0.229 | 0.213 | 0.310 | 0.310 |
alpha_g2 | -1.803 | 0.118 | -15.282 | < .001 | -2.034 | -1.572 | -3.303 | -3.303 | -3.303 |
sigma2_g2 | 0.298 | 0.023 | 13.149 | < .001 | 0.254 | 0.343 | 1.000 | 1.000 | 1.000 |
sigma_g2lx1 | 0.156 | 0.020 | 7.797 | < .001 | 0.117 | 0.195 | 0.415 | 0.415 | 0.415 |
beta_x | -0.002 | 0.006 | -0.329 | .742 | -0.015 | 0.010 | -0.003 | -0.003 | -0.003 |