# --------------------------------------------------------------------- # Program: ThreeFactorObliqueCov-OpenMx100221.R # Author: Steven M. Boker # Date: Sun Feb 21 15:03:46 EST 2010 # # This program fits a covariance three factor oblique covariance model to the # factorExample1.csv simulated data. # # # --------------------------------------------------------------------- # Revision History # -- Sun Feb 21 15:03:52 EST 2010 # Created ThreeFactorObliqueCov-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 three factor blique covariance model with fixed variance indicators <- names(factorExample1) latents <- c("F1", "F2", "F3") loadingLabels <- c(paste("b_F1", indicators, sep=""), paste("b_F2", indicators, sep=""), paste("b_F3", indicators, sep="")) uniqueLabels <- paste("U_", indicators, sep="") meanLabels <- paste("M_", indicators, sep="") factorVarLabels <- paste("Var_", latents, sep="") factorCovLabels <- paste("Cov_", rep(latents, length(latents)), rep(latents, each=length(latents)), sep="") threeFactorObliqueCov1 <- mxModel("Three Factor Oblique Covariance 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, to=latents, arrows=2, all=TRUE, free=TRUE, values=.2, labels=factorCovLabels), mxPath(from=latents, arrows=2, free=FALSE, values=1, labels=factorVarLabels), mxData(observed=cov(factorExample1), type="cov", numObs=500) ) threeFactorObliqueCov1Out <- mxRun(threeFactorObliqueCov1) summary(threeFactorObliqueCov1Out) round(mxEval(A[1:9,10:12], threeFactorObliqueCov1Out), 3) # ---------------------------------- # Build an OpenMx three factor oblique covariance model with fixed loading threeFactorObliqueCov2 <- mxModel("Three Factor Oblique Covariance 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, to=latents, arrows=2, all=TRUE, free=TRUE, values=.2, labels=factorCovLabels), mxPath(from=latents, arrows=2, free=TRUE, values=.8, labels=factorVarLabels), mxPath(from=latents, to=c("x4", "x9", "x7"), arrows=1, free=FALSE, values=1), mxData(observed=cov(factorExample1), type="cov", numObs=500) ) threeFactorObliqueCov2Out <- mxRun(threeFactorObliqueCov2) summary(threeFactorObliqueCov2Out) round(mxEval(A[1:9,10:12], threeFactorObliqueCov2Out), 3)