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.A table of the description of all parameters that can be estimated is shown here.
# First create a lavaan object
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))
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))
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
.
# Now extract parameter estimates
# Only extract first 7 columns for this example by adding [ , 1:7]
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 |