# confidence intervals with mxTryHardOrdinal optimizer

5 posts / 0 new Offline
Joined: 07/21/2017 - 13:13
confidence intervals with mxTryHardOrdinal optimizer

Hi,
I would like to compute confidence intervals for the ACE components in a univariate twins analysis.
Since I have categorical covariates in the model, the only way I could make the model work was by replacing the mxRun optimizer with mxTryHardOrdinal optimizer. However, according to the R documentation of the mxCI function, the mxCI could not run with other optimizers except for mxRun. Similarly, even though I ask for "intervals=TRUE" in the model, the lbound and ubound of the summary output are NAs.

1) is this really the problem?
2) if it is, how would you advice me to calculate the confidence intervals?

Thank you so much,
Lior Offline
Joined: 01/24/2014 - 12:15
You should probably post the

You should probably post the syntax you're trying to run. You can get confidence intervals with mxTryHardOrdinal(). You need to include the appropriate MxInterval object (which is created from mxCI()) in your mxModel() statement, and include argument intervals=TRUE to mxTryHardOrdinal(). Offline
Joined: 07/21/2017 - 13:13
confidence intervals

Thank you.
In the meantime I decided to drop one of my covariates and now I can run the model with mxRun. This is the syntax, I hope it would help to understand the problem.

# Select Variables for Analysis
selVars <- c('NAFAC_1_Res','NAFAC_2_Res','LabHome6')
aceVars <- c("A1","C1","E1","A2","C2","E2")

# Select Data for Analysis
mzM <- subset(D.impWide, zygosity==1 & sex_a=='sex1',selVars)
mzF <- subset(D.impWide, zygosity==1 & sex_a=='sex2',selVars)
dzM <- subset(D.impWide, zygosity==2 & sex_a=='sex1',selVars)
dzF <- subset(D.impWide, zygosity==2 & sex_a=='sex2',selVars)

# Path objects for Multiple Groups
manifestVars=selVars
latentVars=aceVars

# specify paths for the variances and means of the latent variables
latVariances <- mxPath( from=aceVars, arrows=2, free=FALSE, values=1 )

varCovar <- mxPath( from= c('LabHome6'), arrows=2, free=(c(FALSE)), values=1, label='placeVar' )

# means of latent variables
latMeans <- mxPath( from="one", to=aceVars, arrows=1, free=FALSE, values=0 )

#specify paths for the means of the observed variables. Because the scores are residual scores from sex and age, I constrain the means to be the same for boys and girls.
obsMeansM <- mxPath( from="one", to=selVars, arrows=1, free=c(T,T,F), values=c(StartMean, StartMean,                               0), labels=c("meanFAC","meanFAC","meanPlace") )

obsMeansF <- mxPath( from="one", to=selVars, arrows=1, free=c(T,T,F), values=c(StartMean, StartMean,                               0), labels=c("meanFAC","meanFAC","meanPlace") )

# path coefficients for twin 1.
pathAceTM1 <- mxPath( from=c("A1","C1","E1", "LabHome6"), to="NAFAC_1_Res", arrows=1, free=TRUE, values=StartVar.ACE,label=c("aM","cM","eM","place") )

pathAceTF1 <- mxPath( from=c("A1","C1","E1","LabHome6"), to="NAFAC_1_Res", arrows=1, free=TRUE, values=StartVar.ACE, label=c("aF","cF","eF","place") )

# path coefficients for twin 2
pathAceTM2 <- mxPath( from=c("A2","C2","E2","LabHome6"), to="NAFAC_2_Res", arrows=1,free=TRUE, values=StartVar.ACE, label=c("aM","cM","eM", "place") )

pathAceTF2 <- mxPath( from=c("A2","C2","E2", "LabHome6"), to="NAFAC_2_Res", arrows=1,free=TRUE, values=StartVar.ACE, label=c("aF","cF","eF", "place") )

# covariance between C1 & C2
covC1C2 <- mxPath( from="C1", to="C2", arrows=2,free=FALSE, values=1 )

# covariance between A1 & A2 in MZ's
covA1A2_MZ <- mxPath( from="A1", to="A2", arrows=2, free=FALSE, values=1 )
# covariance between A1 & A2 in DZ's
covA1A2_DZ <- mxPath( from="A1", to="A2", arrows=2, free=FALSE, values=.5 )

#call the data.frame with the MZ raw data, mzData, and the DZ raw data
dataMZM <- mxData( observed=mzM, type="raw" )
dataMZF <- mxData( observed=mzF, type="raw" )
dataDZM <- mxData( observed=dzM, type="raw" )
dataDZF <- mxData( observed=dzF, type="raw" )

# Combine Groups
#arrange together all the paths that are the same for MZ and DZ
pathsM <- list(latVariances, latMeans, obsMeansM, pathAceTM1, pathAceTM2, covC1C2, varCovar )

pathsF <- list( latVariances, latMeans, obsMeansF, pathAceTF1, pathAceTF2, covC1C2, varCovar )

#Build a model seperately for MZ and DZ and for each sex
modelMZM <- mxModel(model="MZM", type="RAM", manifestVars=selVars,
latentVars=aceVars, pathsM, threshold, covA1A2_MZ, dataMZM )
modelDZM <- mxModel(model="DZM", type="RAM", manifestVars=selVars,
latentVars=aceVars, pathsM, threshold, covA1A2_DZ, dataDZM )

modelMZF <- mxModel(model="MZF", type="RAM", manifestVars=selVars,
latentVars=aceVars, pathsF, threshold, covA1A2_MZ, dataMZF )
modelDZF <- mxModel(model="DZF", type="RAM", manifestVars=selVars,
latentVars=aceVars, pathsF, threshold, covA1A2_DZ, dataDZF )

minus2ll <- mxAlgebra(expression=MZM.fitfunction + DZM.fitfunction +MZF.fitfunction + DZF.fitfunction,
name="minus2loglikelihood" )
obj <- mxFitFunctionAlgebra( "minus2loglikelihood" )
modelACE.Hetero <- mxModel(model="ACE_Hetero", modelMZM, modelDZM,modelMZF, modelDZF, minus2ll, obj )

fitACE.Hetero <- mxRun(modelACE.Hetero, intervals=TRUE)
sumACE.Hetero <- summary(fitACE.Hetero)

mxCI('fitACE.Hetero') Offline
Joined: 07/31/2009 - 15:26
If you like it put it in your model

Thanks for posting the code. That helps a lot! Please see the documentation and especially the example for ?mxCI. From that

The mxCI function creates MxCI objects, which can be used as arguments in MxModel objects. When models containing MxCI objects are optimized using mxRun with the ‘intervals’ argument set to TRUE, likelihood-based confidence intervals are returned.

Basically, you should create a confidence interval object with the mxCI function. Your call to this function should refer to free parameters, matrices, or algebras by name. You then put that CI object in the model before you run it. Offline
Joined: 07/21/2017 - 13:13
Thank you

Thank you! I understand my syntax mistake, and it works now