Parameter estimates and fit statistics of latent change score models

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>"
)
library(lcsm)
library(lavaan)

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:

Create univariate models

# First fit some latent change score models

# No change model
uni_lcsm_01 <- fit_uni_lcsm(data = data_uni_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_uni_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_uni_lcsm, 
                            var = c("x1", "x2", "x3", "x4", "x5"),
                            model = list(alpha_constant = TRUE, 
                                         beta = TRUE, 
                                         phi = FALSE))

Extract fit statistics

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")

Extract parameters

# 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")

TODOs



Try the lcsm package in your browser

Any scripts or data that you put into this service are public.

lcsm documentation built on July 25, 2020, 1:06 a.m.