# --------------------------------------------------------------------- # Program: ThreeLatentMultipleRegTest1.R # Author: Steven M. Boker # Date: Sun Mar 14 15:21:00 EDT 2010 # # This program tests variations on a latent variable multiple regression # using a standard RAM. # # --------------------------------------------------------------------- # Revision History # -- Sun Mar 14 14:42:39 EDT 2010 # Created ThreeLatentMultipleRegTest1.R. # # --------------------------------------------------------------------- # ---------------------------------- # Read libraries and set options. options(width=100) require(psych) require(OpenMx) source("GenEpiHelperFunctions.R") # ---------------------------------- # Read the data and print descriptive statistics. latentMultipleRegExample1 <- read.csv("latentMultipleRegExample1.csv") describe(latentMultipleRegExample1) numberFactors <- 3 indicators <- names(latentMultipleRegExample1) numberIndicators <- length(indicators) totalVars <- numberIndicators + numberFactors # ---------------------------------- # Build an Old-style RAM OpenMx single factor FIML model with fixed variance latents <- paste("F", 1:numberFactors, sep="") loadingLabels <- paste("b_F", rep(1:numberFactors, each=numberIndicators), rep(indicators, numberFactors), sep="") loadingLabels uniqueLabels <- paste("U_", indicators, sep="") meanLabels <- paste("M_", indicators, sep="") factorVarLabels <- paste("Var_", latents, sep="") latents1 <- latents[1] indicators1 <- indicators[1:4] loadingLabels1 <- paste("b_F1", indicators[1:4], sep="") latents2 <- latents[2] indicators2 <- indicators[5:8] loadingLabels2 <- paste("b_F2", indicators[5:8], sep="") latents3 <- latents[3] indicators3 <- indicators[9:12] loadingLabels3 <- paste("b_F3", indicators[9:12], sep="") threeLatentOrthoRaw1 <- mxModel("threeLatentOrthogonal", type="RAM", manifestVars=indicators, latentVars=latents, mxPath(from=latents1, to=indicators1, arrows=1, all=TRUE, free=TRUE, values=.2, labels=loadingLabels1), mxPath(from=latents2, to=indicators2, arrows=1, all=TRUE, free=TRUE, values=.2, labels=loadingLabels2), mxPath(from=latents3, to=indicators3, arrows=1, all=TRUE, free=TRUE, values=.2, labels=loadingLabels3), mxPath(from=latents1, to=indicators1[1], arrows=1, free=FALSE, values=1), mxPath(from=latents2, to=indicators2[1], arrows=1, free=FALSE, values=1), mxPath(from=latents3, to=indicators3[1], arrows=1, free=FALSE, values=1), mxPath(from=indicators, arrows=2, free=TRUE, values=.8, labels=uniqueLabels), mxPath(from=latents, arrows=2, free=TRUE, values=.8, labels=factorVarLabels), mxPath(from="one", to=indicators, arrows=1, free=TRUE, values=.1, labels=meanLabels), mxData(observed=latentMultipleRegExample1, type="raw") ) threeLatentOrthoRaw1Out <- mxRun(threeLatentOrthoRaw1) summary(threeLatentOrthoRaw1Out) round(mxEval(A[1:numberIndicators,(numberIndicators+1):totalVars], threeLatentOrthoRaw1Out), 3) threeLatentObliqueRaw1 <- mxModel(threeLatentOrthoRaw1, mxPath(from=latents,to=latents,all=TRUE, arrows=2, free=TRUE, values=.3), mxPath(from=latents, arrows=2, free=TRUE, values=.8, labels=factorVarLabels), name="threeLatentOblique" ) threeLatentObliqueRaw1Out <- mxRun(threeLatentObliqueRaw1) summary(threeLatentObliqueRaw1Out) round(mxEval(A[1:numberIndicators,(numberIndicators+1):totalVars], threeLatentObliqueRaw1Out), 3) threeLatentMultipleReg1 <- mxModel(threeLatentOrthoRaw1, mxPath(from="F1",to="F2", arrows=2, free=TRUE, values=.3), mxPath(from=c("F1","F2"), to="F3", arrows=1, free=TRUE, values=.2, labels=c("b1", "b2")), name="threeLatentMultipleReg" ) threeLatentMultipleReg1Out <- mxRun(threeLatentMultipleReg1) summary(threeLatentMultipleReg1Out) round(mxEval(A[1:numberIndicators,(numberIndicators+1):totalVars], threeLatentMultipleReg1Out), 3) threeLatentMultipleReg2 <- mxModel(threeLatentMultipleReg1, mxPath(from="F1",to="F3", arrows=1, free=FALSE, values=0), name="threeLatentMultipleReg2" ) threeLatentMultipleReg2Out <- mxRun(threeLatentMultipleReg2) summary(threeLatentMultipleReg2Out) round(mxEval(A[1:numberIndicators,(numberIndicators+1):totalVars], threeLatentMultipleReg2Out), 3) threeLatentMultipleReg3 <- mxModel(threeLatentMultipleReg1, mxPath(from="F2",to="F3", arrows=1, free=FALSE, values=0), name="threeLatentMultipleReg3" ) threeLatentMultipleReg3Out <- mxRun(threeLatentMultipleReg3) summary(threeLatentMultipleReg3Out) round(mxEval(A[1:numberIndicators,(numberIndicators+1):totalVars], threeLatentMultipleReg3Out), 3) tableFitStatistics(threeLatentObliqueRaw1Out, c(threeLatentMultipleReg1Out, threeLatentMultipleReg2Out, threeLatentMultipleReg3Out, threeLatentOrthoRaw1Out))