#############################################################################
# EXAMPLE 1: Example of Voelkle et al. (2012)
#############################################################################
library(expm)
# path coefficient matrix of Voelkle et al. (2012), but see
# also Kuiper and Ryan (2018)
Phi1 <- matrix( c( .64, .18,
.03, .89 ), nrow=2, ncol=2, byrow=TRUE )
# transformation to time interval 2
mod <- LAM::clpm_to_ctm(Phi1, delta1=1, delta2=2)
print(mod)
if (FALSE) {
#############################################################################
# EXAMPLE 2: Example with two dimensions
#############################################################################
library(STARTS)
library(lavaan)
data(data.starts02, package="STARTS")
dat <- data.starts02$younger_cohort
cormat <- cov2cor(as.matrix(dat$covmat))
#-- estimate CLPM
lavmodel <- "
a2 ~ a1 + b1
b2 ~ a1 + b1
"
mod <- lavaan::sem(lavmodel, sample.cov=cormat, sample.nobs=500)
summary(mod)
#- select parameters
pars <- c("a2~a1", "a2~b1", "b2~a1", "b2~b1")
Phi1 <- matrix( coef(mod)[pars], 2, 2, byrow=TRUE)
Phi1_vcov <- vcov(mod)[ pars, pars ]
# conversion to time interval 1.75
LAM::clpm_to_ctm(Phi1=Phi1, delta1=1, delta2=1.75, Phi1_vcov=Phi1_vcov)
#############################################################################
# EXAMPLE 3: Example with three dimensions
#############################################################################
library(STARTS)
library(lavaan)
data(data.starts02, package="STARTS")
dat <- data.starts02$younger_cohort
cormat <- cov2cor(as.matrix(dat$covmat))
#-- estimate CLPM
lavmodel <- "
a4 ~ a1 + b1 + c1
b4 ~ a1 + b1 + c1
c4 ~ a1 + b1 + c1
"
mod <- lavaan::sem(lavmodel, sample.cov=cormat, sample.nobs=500)
summary(mod)
#- select parameters
pars <- 1:9
Phi1 <- matrix( coef(mod)[pars], 3, 3, byrow=TRUE)
Phi1_vcov <- vcov(mod)[ pars, pars ]
# conversion frpm time interval 3 to time interval 1
LAM::clpm_to_ctm(Phi1=Phi1, delta1=3, delta2=1, Phi1_vcov=Phi1_vcov)
}
Run the code above in your browser using DataLab