You are here

estimate CI

5 posts / 0 new
Last post
Yuan's picture
Joined: 02/13/2015 - 14:46
estimate CI

Hi everyone,

I'm recently learning the univariate twin analysis. According to the documents, I got the a2, c2, and e2. How could I estimate the confidence intervals for each value? Thanks.

AdminRobK's picture
Joined: 01/24/2014 - 12:15

You'll want to include an MxCI object in your MxModel. For instance, if the labels of those free parameters are literally "a2", "c2", and "e2", then include something like


in your mxModel() statement. Or, create an MxCI object, e.g.,

confInt <- mxCI(c("a2","c2","e2"))

and be sure to pass object confInt along with your MxMatrices etc. to mxModel().

Then, be sure to include argument intervals=TRUE when you invoke mxRun(), e.g.

myModelFit <- mxRun(myModel, intervals=TRUE)

For details, see the documentation for mxCI().

olleee's picture
Joined: 07/28/2016 - 16:42
Error in free[i, j] : subscript out of bounds

I tried both approaches AdminRobK mentions in the response, but I always receive the following error message when running the model: Error in free[i, j] : subscript out of bounds. Can you please check what might be wrong with how I adjusted the UnivariateTwinAnalysis_PathRaw.R code (see below)? Or might there be a bug in the software version I'm running? Thanks!

Load Data


Select Variables for Analysis

selVars <- c('bmi1','bmi2')
aceVars <- c("A1","C1","E1","A2","C2","E2")

Select Data for Analysis

mzData <- subset(twinData, zyg==1, selVars)
dzData <- subset(twinData, zyg==3, selVars)

Generate Descriptive Statistics


Path objects for Multiple Groups


variances of latent variables

latVariances <- mxPath( from=aceVars, arrows=2,
+ free=FALSE, values=1 )

means of latent variables

latMeans <- mxPath( from="one", to=aceVars, arrows=1,
+ free=FALSE, values=0 )

means of observed variables

obsMeans <- mxPath( from="one", to=selVars, arrows=1,
+ free=TRUE, values=20, labels="mean" )

path coefficients for twin 1

pathAceT1 <- mxPath( from=c("A1","C1","E1"), to="bmi1", arrows=1,
+ free=TRUE, values=.5, label=c("a","c","e") )

path coefficients for twin 2

pathAceT2 <- mxPath( from=c("A2","C2","E2"), to="bmi2", arrows=1,
+ free=TRUE, values=.5, label=c("a","c","e") )

covariance between C1 & C2

covC1C2 <- mxPath( from="C1", to="C2", arrows=2,
+ free=FALSE, values=1 )

covariance between A1 & A2 in MZ twins

covA1A2_MZ <- mxPath( from="A1", to="A2", arrows=2,
+ free=FALSE, values=1 )

covariance between A1 & A2 in DZ twins

covA1A2_DZ <- mxPath( from="A1", to="A2", arrows=2,
+ free=FALSE, values=.5 )

Data objects for Multiple Groups

dataMZ <- mxData( observed=mzData, type="raw" )
dataDZ <- mxData( observed=dzData, type="raw" )

Combine Groups

paths <- list( latVariances, latMeans, obsMeans,
+ pathAceT1, pathAceT2, covC1C2 )

mxAlgebra( (ace%^%2) %x% solve(t(ace)%*%ace), name="StdVarComp",dimnames=list(c("a2","c2","e2"),NULL) )

modelMZ <- mxModel(model="MZ", type="RAM", manifestVars=selVars,
+ latentVars=aceVars, paths, covA1A2_MZ, dataMZ, mxCI("StdVarComp"))
modelDZ <- mxModel(model="DZ", type="RAM", manifestVars=selVars,
+ latentVars=aceVars, paths, covA1A2_DZ, dataDZ )
minus2ll <- mxAlgebra( expression=MZ.fitfunction + DZ.fitfunction,
+ name="minus2loglikelihood" )
obj <- mxFitFunctionAlgebra( "minus2loglikelihood" )
modelACE <- mxModel(model="ACE", modelMZ, modelDZ, minus2ll, obj )

Run Model

fitACE <- mxRun(modelACE, intervals=TRUE)
Error in free[i, j] : subscript out of bounds

AdminRobK's picture
Joined: 01/24/2014 - 12:15
mxVersion()? "StdVarComp"?

What version of OpenMx are you running? I believe this is the result of a bug that was repaired several minor-version releases ago. In a more recent release, you should get an error about OpenMx not recognizing a name given to mxCI() doesn't appear that you actually ever put an object with name "StdVarComp" into the MxModel you're passing to mxRun().

AdminNeale's picture
Joined: 03/01/2013 - 14:09
What Rob said

Also see my response and repaired script in this thread