#final exam M & E II

#SEM saturated model
m <- 'sat =~ sat1+sat2+sat3+sat4+sat5+sat6+sat7
tru =~ tru1+tru2+tru3+tru4
ctrl =~ ctrl1+ctrl2+ctrl3+ctrl4
und =~ und1+und2+und3+und4+und5
sat ~ tru + ctrl + und
tru ~ ctrl 
ctrl ~ und + cfn*fname + cfp*fprofile
und ~ un*name + up*profile'
fit <- sem(m, data=tw2, ordered=names(tw2[6:25]), std.lv=T)
summary(fit, rsquare=T, fit.measures=T)

m <- 'sat =~ sat1+sat2+sat3+sat4+sat5+sat6+sat7
tru =~ tru1+tru2+tru3+tru4
ctrl =~ ctrl1+ctrl2+ctrl3+ctrl4
und =~ und1+und2+und3+und4+und5
sat ~ tru + ctrl + und
tru ~ ctrl
ctrl ~ und + cfn*fname + cfp*fprofile
und ~ un*name + up*profile'
fit <- sem(m, data=tw2, ordered=names(tw2[6:25]), std.lv=T)
summary(fit, rsquare=T, fit.measures=T)

lavTestWald(fit, "cfn == 0; cfp == 0")
lavTestWald(fit, "un == 0; up == 0")
lavTestWald(fit, "cn ==0; cp == 0")
lavTestWald(fit, "uf == 0")

mods <- modindices(fit)
mods
mods <- mods[grep("\\*", mods$decision),]
mods
