Hi all,
After attending the Workshop in March, we now tried to work with OpenMx for the first time without help... Not completely succesful yet. We only mildly adjusted a script provided at the workshop but it gives an error message: 'The observed data associated with the FIML objective in model 'MZ' does not contain dimnames'. Please find the script below, it seems to us that we did define dimnames (dimnames=selVars). What do we do wrong?
Many thanks in advance for your efforts.
Cathy & Marcel
require(OpenMx)
require(psych)
source("http://www.vipbg.vcu.edu/~vipbg/Tc24/GenEpiHelperFunctions.R")
Prepare Data
-----------------------------------------------------------------------
data(mean_schousbou_aus_mzm)
describe(mean_schousbou_aus_mzm)
Vars <- 'bmi'
nv <- 1
selVars <- paste(Vars,c(rep(1,nv),rep(2,nv)),sep="")
ntv <- nv*2
mzData <- mean_schousbou_aus_mzm
dzData <- mean_schousbou_aus_dzm
Print Descriptive Statistics
-----------------------------------------------------------------------
describe(mean_schousbou_aus_mzm)
colMeans(mean_schousbou_aus_mzm,na.rm=TRUE)
cov(mzData,use="complete")
describe(dzData)
colMeans(dzData,na.rm=TRUE)
cov(dzData,use="complete")
Fit ACE Model with RawData and Matrices Input
-----------------------------------------------------------------------
univACEModel <- mxModel("univACE",
mxModel("ACE",
# Matrices a, c, and e to store a, c, and e path coefficients
mxMatrix( type="Lower", nrow=nv, ncol=nv, free=TRUE, values=.6, label="a11", name="a" ), #X
mxMatrix( type="Lower", nrow=nv, ncol=nv, free=TRUE, values=.6, label="c11", name="c" ), #Y
mxMatrix( type="Lower", nrow=nv, ncol=nv, free=TRUE, values=.6, label="e11", name="e" ), #Z
# Matrices A, C, and E compute variance components
mxAlgebra( expression=a %% t(a), name="A" ),
mxAlgebra( expression=c %% t(c), name="C" ),
mxAlgebra( expression=e %% t(e), name="E" ),
# Algebra to compute total variances and standard deviations (diagonal only)
mxAlgebra( expression=A+C+E, name="V" ),
mxMatrix( type="Iden", nrow=nv, ncol=nv, name="I"),
mxAlgebra( expression=solve(sqrt(IV)), name="iSD"),
## Note that the rest of the mxModel statements do not change for bivariate/multivariate case
# Matrix & Algebra for expected means vector
mxMatrix( type="Full", nrow=1, ncol=nv, free=TRUE, values= 20, label="mean", name="Mean"),
mxAlgebra( expression= cbind(Mean,Mean), name="expMean"),
# Algebra for expected variance/covariance matrix in MZ
mxAlgebra( expression= rbind ( cbind(A+C+E , A+C),
cbind(A+C , A+C+E)), name="expCovMZ" ),
# Algebra for expected variance/covariance matrix in DZ, note use of 0.5, converted to 1*1 matrix
mxAlgebra( expression= rbind ( cbind(A+C+E , 0.5%x%A+C),
cbind(0.5%x%A+C , A+C+E)), name="expCovDZ" )
),
mxModel("MZ",
mxData( observed=mzData, type="raw" ),
mxFIMLObjective( covariance="ACE.expCovMZ", means="ACE.expMean", dimnames=selVars)
),
mxModel("DZ",
mxData( observed=dzData, type="raw" ),
mxFIMLObjective( covariance="ACE.expCovDZ", means="ACE.expMean", dimnames=selVars)
),
mxAlgebra( expression=MZ.objective + DZ.objective, name="minus2sumll" ),
mxAlgebraObjective("minus2sumll")
)
univACEFit <- mxRun(univACEModel)
univACESumm <- summary(univACEFit)
univACESumm