######INPUT data library(sem) S.wh <- read.moments(names=c('Anomia67','Powerless67','Anomia71', 'Powerless71','Education','SEI')) 11.834 6.947 9.364 6.819 5.091 12.532 4.783 5.028 7.495 9.986 -3.839 -3.889 -3.841 -3.625 9.610 -21.899 -18.831 -21.748 -18.775 35.522 450.288 S.wh2<- S.wh S.wh2[upper.tri(S.wh2)]<-t(S.wh2)[upper.tri(S.wh2)] ############################## ###### model with OpenMx ############################## library(OpenMx) nameD<-colnames(S.wh) manifests.67 <- nameD[grep("67", nameD)] manifests.71 <- nameD[grep("71", nameD)] manifests.SES <- c("Education", "SEI") latents <- c("SES", "Alienation67", "Alienation71") factorModel <- mxModel("SEM", type="RAM", manifestVars = nameD, latentVars = latents, #FROM SES mxPath(from=latents[1], to=manifests.SES[2]), #SES mxPath(from=latents[1], to="Education", free=F, values=1), #SES mxPath(from=latents[1], to=latents[2:3]), #SES mxPath(from=manifests.SES, arrows=2), #from Alienation67 mxPath(from=latents[2], to="Anomia67",free=F, values=1), mxPath(from=latents[2], to="Powerless67", free=F, values=0.833), mxPath(from=latents[2], to=latents[3]), mxPath(from="Anomia67", arrows=2, labels="the1"), # mxPath(from="Anomia71", arrows=2, labels="the1"), # #from Alienation71 mxPath(from=latents[3], to="Powerless71", free=F, values=0.833),# mxPath(from=latents[3], to="Anomia71", free=F, values=1),# mxPath(from="Powerless67", arrows=2, labels="the2"), # mxPath(from="Powerless71", arrows=2, labels="the2"), # #cross indicators mxPath(from="Anomia71", to="Anomia67", arrows=2), # mxPath(from=latents, arrows=2), #var of latents #var of latents mxData(S.wh2, type="cov", numObs=nrow(S.wh))) Run<-mxRun(factorModel) summary(Run) omxGraphviz(factorModel) ############################## ###### model with sem ############################## model.wh.1 <- specify.model() Alienation67 -> Anomia67, NA, 1 Alienation67 -> Powerless67, NA, 0.833 Alienation71 -> Anomia71, NA, 1 Alienation71 -> Powerless71, NA, 0.833 SES -> Education, NA, 1 SES -> SEI, lamb, NA SES -> Alienation67, gam1, NA Alienation67 -> Alienation71, beta, NA SES -> Alienation71, gam2, NA Anomia67 <-> Anomia67, the1, NA Anomia71 <-> Anomia71, the1, NA Powerless67 <-> Powerless67, the2, NA Powerless71 <-> Powerless71, the2, NA Education <-> Education, the3, NA SEI <-> SEI, the4, NA Anomia67 <-> Anomia71, the5, NA Powerless67 <-> Powerless71, the5, NA Alienation67 <-> Alienation67, psi1, NA Alienation71 <-> Alienation71, psi2, NA SES <-> SES, phi, NA sem.wh.1 <- sem(model.wh.1, S.wh, 932) summary(sem.wh.1) path.diagram(sem.wh.1, ignore.double=F, edge.labels="values")