THard=-n

Posted on
Picture of user. HanOud Joined: 12/20/2009
I have had good experience with the Mx option THard=-n in Mx, also called Automatic Cold Restart. Is this option still available in OpenMx and, if not, why is it taken out?
Thanks for any answer in advance,
Han Oud
Replied on Thu, 03/08/2012 - 11:23
Picture of user. mspiegel Joined: 07/31/2009

So help the discussion, here's the description of Mx option THard=-n:

During optimization, an estimate of the covariance matrix of the estimated parameters is constructed. Sometimes, this covariance matrix is inaccurate and optimization fails to converge to the correct solution, a problem that is usually flagged by an IFAIL parameter of 6. Option TH=-n can be used to restart the optimization n times from the current solution, but with the parameter covariance matrix reset to zero.

Can this functionality be replicated in R? Somebody more knowledgeable than I will hopefully answer this question.

Replied on Thu, 03/08/2012 - 12:21
Picture of user. tbrick Joined: 07/31/2009

In reply to by mspiegel

You can replicate THard by re-running the fitted model, if I understand the THard argument right (Mike N., correct me if I'm wrong on that). We start cold every time you re-run the model, so it should automatically reset the estimated covariance of the parameters.

A helper function can replicate this effect by just calling mxRun repeatedly on the model. Admittedly, there's some overhead involved in doing so, since the model has to be re-flattened and reprocessed by the back-end. If we want a full implementation of this, it should be done in the back-end for the sake of performance. We'll put the feature on the list and you can use the helper in the meantime.

The helper function would be something like this (sorry it's messy--this is off the top of my head).

tryHard <- function(model, n, ...) {
fit <- mxRun(model)
while(fit@output$status[[1]] == 6 & n > 2) {
print(paste("Trying hard...", n-1, "more times."))
fit <- mxRun(fit)
n <- n - 1
}
fit <- mxRun(fit, ...)
return(fit)
}

The last re-run includes the original arguments, so it will do things like calculate confidence intervals, etc.
There are a few cases where it'll run an extra time to calculate CIs, but if it's already converged, the last run should be quick.

Replied on Sat, 03/10/2012 - 19:10
Picture of user. HanOud Joined: 12/20/2009

In reply to by tbrick

Thanks, Timothy, for helping with tryHard. I had a try but did not get any relevant output. Did I do something wrong? See below input and output.

tryHard <- function(model,n){
+ fit<-mxRun(model)
+ while(fit@output$status[[1]]==6 & n>2){
+ print(paste("Trying hard...",n-1, "more times."))
+ fit<-mxRun(fit)
+ summary(fit)
+ n <- n-1
+ }
+ return(fit)
+ }
>
> model<-LatDepModelUn
> n<-10
> tryHard(model,n)
Running LatDepModelUn
MxModel 'LatDepModelUn'
type : default
@matrices : 'A', 'S', 'F', and 'M'
@algebras :
@constraints :
@intervals :
@latentVars : none
@manifestVars : none
@data : 49 x 10
@data means : NA
@data type: 'raw'
@submodels :
@objective : MxRAMObjective
@independent : FALSE
@options :
@output : TRUE
>