confidence intervals with mxTryHardOrdinal optimizer

Posted on
No user picture. lior abramson Joined: 07/21/2017
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.

I would like to ask:
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

Replied on Sat, 09/09/2017 - 15:19
Picture of user. AdminRobK Joined: 01/24/2014

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().

Replied on Sun, 09/10/2017 - 04:18
No user picture. lior abramson Joined: 07/21/2017

In reply to by AdminRobK

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')

Replied on Sun, 09/10/2017 - 22:32
Picture of user. mhunter Joined: 07/31/2009

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.