#mixed model that I'm trying to match SEM to (data is in long format) #fixed slope, fixed intercept for students #random intercept only for Schools MixedModel <- lme(ESA ~ Time, random = list(School = ~1, idChild = ~1), weights =varIdent(School), corr = corCompSymm(form= ~Time), data=DataSet, na.action="na.omit", method = "REML") #Single-level SEM, with treatment group removed for simplicity #All of the estimated parameters match the mixed model except for the intercept variance (School variance) #data is in wide format here data1 = DataSimESA_Change_WIDE[,c("ESA_T1", "ESA_T2", "ESA_T3", "idChild", "School")] SingleLevelModel= mxModel( "One Level Model", type="RAM", manifestVars=c("ESA_T1", "ESA_T2", "ESA_T3"), latentVars=c("I", "S", "S2"), mxData(observed=data1, type="raw"), #compound symmetry covariance structure mxPath(from=c("ESA_T1", "ESA_T2", "ESA_T3"), arrows=2, free=T, values=c(1,1,1), labels=c("variance", "variance", "variance")), mxPath(from="ESA_T1", to=c("ESA_T2", "ESA_T3"), arrows=2, free=T, values=c(.5, .5), labels=c("covar", "covar")), mxPath(from="ESA_T2", to="ESA_T3", arrows=2, free=T, values=.5, labels="covar"), #two slopes (S, S2) for T1 to T2, and T1 to T3 mxPath(from=c("I", "S", "S2"), arrows=2, connect="unique.pairs", free=c(F, F, F, F, F, F), values=c(0, 0, 0, 0, 0, 0)), mxPath(from="I", to=c("ESA_T1", "ESA_T2", "ESA_T3"), arrows=1, free=F, values=c(1, 1, 1)), mxPath(from="S", to=c("ESA_T1", "ESA_T2"), arrows=1, free=F, values=c(0, 1)), mxPath(from="S2", to=c("ESA_T1", "ESA_T3"), arrows=1, free=F, values=c(0, 1)), #manifest means not estimated mxPath(from="one", to=c("ESA_T1", "ESA_T2", "ESA_T3"), arrows=1, free=F, values=c(0, 0, 0)), #latent means estimated mxPath(from="one", to=c("I", "S", "S2"), arrows=1, free=T, values=c(1, 1, 1), labels=c("meanI", "meanS", "meanS2"))) SingleLevelModel = mxRun(SingleLevelModel) summary(SingleLevelModel)