THard=-n
Posted on
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
Thanks for any answer in advance,
Han Oud
So help the discussion,
Can this functionality be replicated in R? Somebody more knowledgeable than I will hopefully answer this question.
Log in or register to post comments
In reply to So help the discussion, by mspiegel
You can replicate THard by re-running the fitted model
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.
Log in or register to post comments
In reply to You can replicate THard by re-running the fitted model by tbrick
Presumably you'd want to turn
Log in or register to post comments
In reply to You can replicate THard by re-running the fitted model by tbrick
trying tryHard
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
>
Log in or register to post comments
In reply to trying tryHard by HanOud
it worked, just need to put the output into a model for summary
LatDepModelUn <- tryHard(LatDepModelUn,10)
summary(LatDepModelUn)
Log in or register to post comments
In reply to it worked, just need to put the output into a model for summary by tbates
trying tryHard
Log in or register to post comments