# --------------------------------------------------------------------- # Program: OneFactorRaw-OpenMx100221.R # Author: Steven M. Boker # Date: Sun Feb 21 13:23:40 EST 2010 # # This program fits a FIML single factor model to the # factorExample1.csv simulated data. # # # --------------------------------------------------------------------- # Revision History # -- Sun Feb 21 13:23:43 EST 2010 # Created OneFactorRaw-OpenMx100221.R. # # --------------------------------------------------------------------- # ---------------------------------- # Read libraries and set options. options(width=80) require(psych) require(OpenMx) # ---------------------------------- # Read the data and print descriptive statistics. factorExample1 <- read.csv("factorExample1.csv") describe(factorExample1) # ---------------------------------- # Build an OpenMx single factor FIML model with fixed variance indicators <- names(factorExample1) latents <- c("F1") loadingLabels <- paste("b_", indicators, sep="") uniqueLabels <- paste("U_", indicators, sep="") meanLabels <- paste("M_", indicators, sep="") factorVarLabels <- paste("Var_", latents, sep="") oneFactorRaw1 <- mxModel("Single Factor FIML Model with Fixed Variance", type="RAM", manifestVars=indicators, latentVars=latents, mxPath(from=latents, to=indicators, arrows=1, all=TRUE, free=TRUE, values=.2, labels=loadingLabels), mxPath(from=indicators, arrows=2, free=TRUE, values=.8, labels=uniqueLabels), mxPath(from=latents, arrows=2, free=FALSE, values=1, labels=factorVarLabels), mxPath(from="one", to=indicators, arrows=1, free=TRUE, values=.1, labels=meanLabels), mxData(observed=factorExample1, type="raw") ) oneFactorRaw1Out <- mxRun(oneFactorRaw1) summary(oneFactorRaw1Out) # ---------------------------------- # Build an OpenMx single factor FIML model with fixed loading indicators <- names(factorExample1) latents <- c("F1") loadingLabels <- paste("b_", indicators, sep="") uniqueLabels <- paste("U_", indicators, sep="") meanLabels <- paste("M_", indicators, sep="") factorVarLabels <- paste("Var_", latents, sep="") oneFactorRaw2 <- mxModel("Single Factor FIML Model with Fixed Loading", type="RAM", manifestVars=indicators, latentVars=latents, mxPath(from=latents, to=indicators, arrows=1, all=TRUE, free=TRUE, values=.2, labels=loadingLabels), mxPath(from=indicators, arrows=2, free=TRUE, values=.8, labels=uniqueLabels), mxPath(from=latents, arrows=2, free=TRUE, values=1, labels=factorVarLabels), mxPath(from=latents, to=c("x1"), arrows=1, free=FALSE, values=1), mxPath(from="one", to=indicators, arrows=1, free=TRUE, values=.1, labels=meanLabels), mxData(observed=factorExample1, type="raw") ) oneFactorRaw2Out <- mxRun(oneFactorRaw2) summary(oneFactorRaw2Out)