ctmaOptimizeFit: ctmaOptimizeFit

View source: R/ctmaOptimizeFit.R

ctmaOptimizeFitR Documentation

ctmaOptimizeFit

Description

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. On unix-like machines (e.g. MacOS), this could be done in parallel mode if coresToUse > 1.

Usage

ctmaOptimizeFit(
  primaryStudies = NULL,
  activeDirectory = NULL,
  problemStudy = NULL,
  reFits = NULL,
  finishsamples = NULL,
  n.latent = NULL,
  coresToUse = c(1),
  indVarying = FALSE,
  scaleTime = NULL,
  randomScaleTime = c(1, 1),
  activateRPB = FALSE,
  checkSingleStudyResults = FALSE,
  customPar = FALSE,
  T0means = 0,
  manifestMeans = 0,
  CoTiMAStanctArgs = NULL,
  CoTiMAFit = NULL,
  CoTiMAInitFit = NULL,
  randomPar = FALSE,
  posLL = TRUE,
  lambda = NULL,
  manifestVars = NULL
)

Arguments

primaryStudies

list of primary study information created with ctmaPrep or ctmaFitToPrep

activeDirectory

activeDirectory

problemStudy

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

reFits

how many reFits should be done

finishsamples

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

n.latent

number of latent variables of the model (hast to be specified)!

coresToUse

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

indVarying

control for unobserved heterogeneity by having randomly (inter-individually) varying manifest means

scaleTime

scale time (interval) - sometimes desirable to improve fitting

randomScaleTime

lower and upper limit of uniform distribution from which timeScale argument for ctmaInit is uniformly shuffled (integer)

activateRPB

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

checkSingleStudyResults

displays estimates from single study 'ctsem' models and waits for user input to continue.

customPar

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

T0means

Default 0 (assuming standardized variables). Can be assigned labels to estimate them freely.

manifestMeans

Default 0 (assuming standardized variables). Can be assigned labels to estimate them freely.

CoTiMAStanctArgs

parameters that can be set to improve model fitting of the ctStanFit Function

CoTiMAFit

a object fitted with ctmaFit

CoTiMAInitFit

the ctmaInitFit object that was used to create the CoTiMAFit object with ctmaFit

randomPar

logical. Overrides arguments used fo customPar and randomly selects customPar either TRUE or FALSE

posLL

logical. Allows (default = TRUE) of positive loglik (neg -2ll) values

lambda

R-type matrix with pattern of fixed (=1) or free (any string) loadings.

manifestVars

define the error variances of the manifests within a single time point using R-type lower triangular matrix with nrow=n.manifest & ncol=n.manifest. Useful to check estimates before they are saved.

Value

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.

Note

All but one of multiple cores are used on unix-type machines for parallel fitting

During fitting, not output is generated. Be patient.

Examples

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


CoTiMA documentation built on Nov. 10, 2022, 5:16 p.m.