View source: R/ctmaOptimizeFit.R

ctmaOptimizeFit | R Documentation |

Replaces deprecated `ctmaOptimizeInit`

, which was limited to initial fitting
(i.e., applies `ctmaInit`

) of a primary study reFits times to capitalize on chance for obtaining
a hard-to-find optimal fit.
Now, optimizing a CoTiMA model generated with `ctmaFit`

can also be done.
Using `ctmaOptimizeFit`

could be helpful if a model yields out-of-range estimates, which could happen if the fitting
algorithm unfortunately used random start values that resulted in a locally but not globally optimal fit. Essentially, using
`ctmaOptimizeFit`

is like gambling, hoping that at least one set of starting values (the number it tries is specified in the reFits argument)
enables finding the global optimal fit.

```
ctmaOptimizeFit(
activateRPB = FALSE,
activeDirectory = NULL,
coresToUse = c(2),
CoTiMAStanctArgs = NULL,
ctmaFitFit = NULL,
ctmaInitFit = NULL,
customPar = FALSE,
finishsamples = NULL,
iter = 5000,
primaryStudies = NULL,
problemStudy = NULL,
randomPar = FALSE,
randomScaleTI = FALSE,
randomScaleTime = c(1, 1),
saveModelFits = FALSE,
shuffleStudyList = FALSE,
reFits = NULL,
scaleTime = NULL,
scaleTI = NULL,
verbose = 1
)
```

`activateRPB` |
set to TRUE to receive push messages with 'CoTiMA' notifications on your phone |

`activeDirectory` |
activeDirectory |

`coresToUse` |
if neg., the value is subtracted from available cores, else value = cores to use |

`CoTiMAStanctArgs` |
parameters that can be set to improve model fitting of the |

`ctmaFitFit` |
a object fitted with |

`ctmaInitFit` |
the ctmaInitFit object that was used to create the ctmaFitFit object with |

`customPar` |
logical. If set TRUE leverages the first pass using priors and ensure that the drift diagonal cannot easily go too negative (helps since ctsem > 3.4) |

`finishsamples` |
number of samples to draw (either from hessian based covariance or posterior distribution) for final results computation (default = 1000). |

`iter` |
number of iterations (default = 5000) |

`primaryStudies` |
list of primary study information created with |

`problemStudy` |
number (position in list) where the problem study in primaryStudies is found |

`randomPar` |
logical (default = FALSE). Overrides arguments used for customPar and randomly sets customPar either TRUE or FALSE |

`randomScaleTI` |
logical (default = FALSE). Overrides arguments used for scaleTI and randomly sets scaleTI either TRUE or FALSE |

`randomScaleTime` |
lower and upper limit (default = c(1,1)) of uniform distribution from which timeScale argument for ctmaInit is uniformly shuffled (integer) |

`saveModelFits` |
save the fit of each Fit attempt (default = FALSE). |

`shuffleStudyList` |
(default = FALSE) randomly re-arranges studies in primaryStudyList. We encountered a few cases where this mattered, even though it should not. Only works if ctmaFit is optimized. |

`reFits` |
how many reFits should be done |

`scaleTime` |
scale time (interval) - sometimes desirable to improve fitting |

`scaleTI` |
scale TI predictors - not recommended until version 0.5.3.1. Does not change aggregated results anyways, just interpretation of effects for dummies representing primary studies. |

`verbose` |
integer from 0 to 2. Higher values print more information during model fit – for debugging |

returns a list with bestFit (= the best fit achieved), all_minus2ll (= all -2ll values for all fitted models), and summary, which is printed if the summary function is applied to the returned object, and which shows the summary information of the ctsem model with the best fit.

```
## Not run:
optimFit313 <- ctmaOptimizeFit(primaryStudies=CoTiMAstudyList_3,
activeDirectory="/Users/tmp/", # adapt!
problemStudy=which(CoTiMAstudyList_3$studyNumbers == 313),
reFits=10,
n.latent=2)
summary(optimFit313)
## End(Not run)
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.