ctmaFit: ctmaFit

View source: R/ctmaFit.R

ctmaFitR Documentation

ctmaFit

Description

Fits a ctsem model with invariant drift effects across primary studies, possible multiple moderators (but all of them of the the same type, either "cont" or "cat"), and possible cluster (e.g., countries where primary studies were conducted).

Usage

ctmaFit(
  activateRPB = FALSE,
  activeDirectory = NULL,
  allInvModel = FALSE,
  binaries = NULL,
  catsToCompare = NULL,
  chains = NULL,
  cint = 0,
  cluster = NULL,
  coresToUse = c(2),
  CoTiMAStanctArgs = NULL,
  ctmaInitFit = NULL,
  customPar = FALSE,
  digits = 4,
  drift = NULL,
  driftsToCompare = NULL,
  equalDrift = NULL,
  finishsamples = NULL,
  fit = TRUE,
  ind.mod.names = NULL,
  ind.mod.number = NULL,
  ind.mod.type = "cont",
  indVarying = FALSE,
  indVaryingT0 = NULL,
  inits = NULL,
  invariantDrift = NULL,
  iter = NULL,
  lambda = NULL,
  manifestMeans = 0,
  manifestVars = 0,
  mod.names = NULL,
  mod.number = NULL,
  mod.type = "cont",
  moderatedDrift = NULL,
  modsToCompare = NULL,
  optimize = TRUE,
  primaryStudyList = NULL,
  priors = FALSE,
  randomIntercepts = FALSE,
  sameInitialTimes = FALSE,
  scaleClus = TRUE,
  scaleMod = TRUE,
  scaleTI = TRUE,
  scaleTime = NULL,
  T0means = 0,
  T0var = "auto",
  transfMod = NULL,
  useSampleFraction = NULL,
  verbose = 0,
  WEC = FALSE
)

Arguments

activateRPB

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

activeDirectory

defines another active directory than the one used in ctmaInitFit

allInvModel

estimates a model with all parameters invariant (DRIFT, DIFFUSION, T0VAR) if set TRUE (defautl = FALSE)

binaries

which manifest is a binary. Still experimental

catsToCompare

when performing contrasts for categorical moderators, the categories (values, not positions) for which effects are set equal

chains

number of chains to sample, during HMC or post-optimization importance sampling.

cint

default 'auto' (= 0). Are set free if random intercepts model with varying cints is requested (by indVarying='cint')

cluster

vector with cluster variables (e.g., countries). Has to be set up carfully. Will be included in ctmaPrep in later 'CoTiMA' versions.

coresToUse

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

CoTiMAStanctArgs

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

ctmaInitFit

object to which all single ctsem fits of primary studies has been assigned to (i.e., what has been returned by ctmaInit)

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)

digits

Number of digits used for rounding (in outputs)

drift

labels for drift effects. Have to be either of the type 'V1toV2' or '0' for effects to be excluded.

driftsToCompare

when performing contrasts for categorical moderators, the (subset of) drift effects analyzed

equalDrift

Constrains all listed effects to be equal (e.g., equalDrift = c("V1toV2", "V2toV1")). Note that this is not required for testing the assumption that two effects are equal in the population. Use the invariantDrift argument and then ctmaEqual)

finishsamples

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

fit

TRUE (default) fits the requested model. FALSE returns the ctsem code CoTiMA uses to set up the model, the ctsemmodelbase which can be modified to match users requirements, and the data set (in long format created). The model can then be fitted using ctStanFit)

ind.mod.names

vector of names for individual level (!) moderators used in output

ind.mod.number

which in the vector of individual level (!) moderator values shall be used (e.g., 2 for a single moderator or 1:3 for 3 moderators simultaneously)

ind.mod.type

'cont' or 'cat' of the individual level (!) moderators (mixing them in a single model not yet possible)

indVarying

allows continuous time intercepts to vary at the individual level (random intercepts model, accounts for unobserved heterogeneity)

indVaryingT0

deprecated. Automatically set to NULL.

inits

vector of start values

invariantDrift

drift labels for drift effects that are set invariant across primary studies (default = all drift effects).

iter

number of iterations (defaul = 1000). Sometimes larger values could be required fom Bayesian estimation

lambda

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

manifestMeans

default = 0. Are automatically set free if indVarying is set to TRUE. Can be assigned labels to estimate them freely.

manifestVars

define the error variances (default = 0) of the manifests with a single time point using R-type lower triangular matrix with nrow=n.manifest & ncol=n.manifest.

mod.names

vector of names for moderators used in output

mod.number

which in the vector of moderator values shall be used (e.g., 2 for a single moderator or 1:3 for 3 moderators simultaneously)

mod.type

'cont' or 'cat' (mixing them in a single model not yet possible)

moderatedDrift

labels for drift effects that are moderated (default = all drift effects)

modsToCompare

when performing contrasts for categorical moderators, the moderator numbers (position in mod.number) that is used

optimize

if set to FALSE, Stan’s Hamiltonian Monte Carlo sampler is used (default = TRUE = maximum a posteriori / importance sampling) .

primaryStudyList

could be a list of primary studies compiled with ctmaPrep that defines the subset of studies in ctmaInitFit that should actually be used

priors

if FALSE, any priors are disabled – sometimes desirable for optimization

randomIntercepts

(default = FALSE) Experimental. Overrides ctsem's default mode for modelling indVarying cints.

sameInitialTimes

Only important for raw data. If TRUE (default=FALSE), T0MEANS occurs for every subject at the same time, rather than just at the earliest observation.

scaleClus

scale vector of cluster indicators - TRUE (default) yields avg. drift estimates, FALSE yields drift estimates of last cluster

scaleMod

scale moderator variables - TRUE (default) recommended for continuous and categorical moderators, to separate withing and betwen efeccts

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.

scaleTime

scale time (interval) - sometimes desirable to improve fitting

T0means

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

T0var

(default = 'auto')

transfMod

more general option to change moderator values. A vector as long as number of moderators analyzed (e.g., c("mean(x)", "x - median(x)"))

useSampleFraction

to speed up debugging. Provided as fraction (e.g., 1/10).

verbose

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

WEC

(default = FALSE) Experimental. Uses weighted effect coding of TIpred representing the dummies of the primary studies. Returns drift matrices for all primary studies.

Value

ctmaFit returns a list containing somearguments supplied, the fitted model, different elements summarizing the main results, model type, and the type of plot that could be performed with the returned object. The arguments in the returned object are activeDirectory, coresToUse, moderator names (mod.names), and moderator type (mod.type). Further arguments, which are just copied from the init-fit object supplied, are, n.latent, studyList, parameterNames, and statisticsList. The fitted model is found in studyFitList, which is a large list with many elements (e.g., the ctsem model specified by CoTiMA, the rstan model created by ctsem, the fitted rstan model etc.). Further results returned are n.studies = 1 (required for proper plotting), data (created pseudo raw data), and a list with modelResults (i.e., DRIFT=model_Drift_Coef, DIFFUSION=model_Diffusion_Coef, T0VAR=model_T0var_Coef, CINT=model_Cint_Coef, MOD=modTI_Coeff, and CLUS=clusTI_Coeff). Possible invariance constraints are included in invariantDrift. The number of moderators simultaneously analyzed are included in ' n.moderators. The most important new results are returned as the list element "summary", which is printed if the summary function is applied to the returned object. The summary list element comprises "estimates" (the aggregated effects), possible randomEffects (not yet fully working), the minus2ll value and its n.parameters, the opt.lag sensu Dormann & Griffin (2015) and the max.effects that occur at the opt.lag, clus.effects and mod.effects, and possible warning messages (message). Plot type is plot.type=c("drift") and model.type="stanct" ("omx" was deprecated).

Examples

## Not run: 
# Example 1. Fit a CoTiMA to all primary studies previously fitted one by one
# with the fits assigned to CoTiMAInitFit_6
CoTiMAFullFit_6 <- ctmaFit(ctmaInitFit=CoTiMAInitFit_6)
summary(CoTiMAFullFit_6)

## End(Not run)

## Not run: 
# Example 2. Fit a CoTiMA with only 2 cross effects invariant (not the auto
# effects) to all primary studies previously fitted one by one with the fits
# assigned to CoTiMAInitFit_6
CoTiMAInitFit_6$activeDirectory <- "/Users/tmp/" # adapt!
CoTiMAFullInv23Fit_6 <- ctmaFit(ctmaInitFit=CoTiMAInitFit_6,
                        invariantDrift=c("V1toV2", "V2toV1"))
summary(CoTiMAFullInv23Fit_6)

## End(Not run)

## Not run: 
# Example 3. Fit a moderated CoTiMA
CoTiMAInitFit_6$activeDirectory <- "/Users/tmp/" # adapt!
CoTiMAMod1onFullFit_6 <- ctmaFit(ctmaInitFit=CoTiMAInitFit_6,
                                 mod.number=1, mod.type="cont",
                                 mod.names=c("Control"))
summary(CoTiMAMod1onFullFit_6)

## End(Not run)


CoTiMA documentation built on May 29, 2024, 11:39 a.m.

Related to ctmaFit in CoTiMA...