# ========================================== # = MIMIC model = # ========================================== This is an example from chapter 13 Schumacker and Lomax Beginner's guide to SEM require(sem) require(OpenMx) # Often you will see data presented as a lower diagonal. # the readMoments() function in the sem package is a nice helper to read this from the screen: data = sem::readMoments(file = "", diag = T) 1 .304 1 .305 .344 1 .100 .156 .158 1 .284 .192 .324 .360 1 .176 .136 .226 .210 .265 1 # terminates with an empty line: see ?readMoments for more help # now letsfill in the upper triangle with a flipped version of the lower data[upper.tri(data, diag=F)] = t(data)[upper.tri(data, diag=F)] # Set up manifest variables manifests = c("income", "occup", "educ", "church", "member", "friends") # Use these to create names for our dataframe dimnames(data) = list(manifests, manifests) # And latents latents = "social" # 1 latent, with three formative inputs, and three reflective outputs (each with residuals) # Just to be helpful to myself, I've made lists of the formative sources, and the reflective receiver variables in this MIMIC model receivers = manifests[4:6] sources = manifests[1:3] MIMIC <- mxModel("MIMIC", type="RAM", manifestVars = manifests, latentVars = latents, # Factor loadings mxPath(from = sources , to = "social" , values), mxPath(from = "social", to = receivers, values), # Correlated formative sources for F1, each with variance = 1 mxPath(from = sources, connect = "unique.bivariate", arrows = 2), mxPath(from = sources, arrows = 2, values = 1, free=F ), # Residual variance on receivers mxPath(from = receivers, arrows = 2), mxData(data, type = "cov", numObs = 530) ) MIMIC= mxRun(MIMIC); summary(MIMIC) # And the results # data: # $MIMIC.data # $MIMIC.data$cov # income occup educ church member friends # income 1.000 0.304 0.305 0.100 0.284 0.176 # occup 0.304 1.000 0.344 0.156 0.192 0.136 # educ 0.305 0.344 1.000 0.158 0.324 0.226 # church 0.100 0.156 0.158 1.000 0.360 0.210 # member 0.284 0.192 0.324 0.360 1.000 0.265 # friends 0.176 0.136 0.226 0.210 0.265 1.000 # # # The final iterate satisfies the optimality conditions to the accuracy requested, but the sequence of iterates has not yet converged. NPSOL was terminated because no further improvement could be made in the merit function (Mx status GREEN). # # free parameters: # name matrix row col Estimate Std.Error lbound ubound # 1 A social income 0.13244947 5.51420454 # 2 A social occup 0.05701774 2.37389629 # 3 A social educ 0.19511219 8.12304135 # 4 A church social 0.60971866 25.38489597 # 5 A member social 1.28671307 53.56883563 # 6 A friends social 0.86519046 36.02017596 # 7 S income occup 0.30399991 0.03764547 # 8 S income educ 0.30499977 0.03761111 # 9 S occup educ 0.34399974 0.03618180 # 10 S church church 0.96770471 0.05954356 # 11 S member member 0.85617184 0.05267749 # 12 S friends friends 0.93497178 0.05749125 # # observed statistics: 21 # estimated parameters: 12 # degrees of freedom: 9 # -2 log likelihood: 2893.752 # saturated -2 log likelihood: 2804.686 # number of observations: 530 # chi-square: 89.06589 # p: 2.506216e-15 # Information Criteria: # df Penalty Parameters Penalty Sample-Size Adjusted # AIC 71.06589 113.0659 NA # BIC 32.61000 164.3404 126.249 # CFI: 0.7740255 # TLI: 0.6233758 # RMSEA: 0.1295581 # timestamp: 2012-03-30 12:52:20 # frontend time: 0.1000018 secs # backend time: 0.01217008 secs # independent submodels time: 3.099442e-05 secs # wall clock time: 0.1122029 secs # cpu time: 0.1122029 secs # openmx version number: 1.2.0-1926