#############################################################################
# EXAMPLE 1: data.lsem01 | Age differentiation
#############################################################################
data(data.lsem01)
dat <- data.lsem01
# specify lavaan model
lavmodel <- "
F =~ v1+v2+v3+v4+v5
F ~~ 1*F"
# define grid of moderator variable age
moderator.grid <- seq(4,23,1)
#********************************
#*** Model 1: estimate LSEM with bandwidth 2
mod1 <- lsem.estimate( dat , moderator="age" , moderator.grid=moderator.grid ,
lavmodel=lavmodel , h=2 , std.lv=TRUE)
summary(mod1)
plot(mod1 , parindex=1:5)
# perform permutation test for Model 1
pmod1 <- lsem.permutationTest( mod1 , B=10 )
# only for illustrative purposes the number of permutations B is set
# to a low number of 10
summary(pmod1)
plot(pmod1, type="global")
#********************************
#*** Model 2: estimate multiple group model with 4 age groups
# define breaks for age groups
moderator.grid <- seq( 3.5 , 23.5 , len=5) # 4 groups
# estimate model
mod2 <- lsem.estimate( dat , moderator="age" , moderator.grid=moderator.grid ,
lavmodel=lavmodel , type="MGM" , std.lv=TRUE)
summary(mod2)
# output step functions
smod2 <- lsem.MGM.stepfunctions( lsem.object=mod2 , moderator.grid=seq(4,23,1) )
str(smod2)
Run the code above in your browser using DataLab