Learn R Programming

ctsem (version 1.1.1)

ctFit: Fit a ctsem object

Description

This function fits continuous time SEM models specified via ctModel to a dataset containing one or more subjects.

Usage

ctFit(datawide, ctmodelobj, confidenceintervals = NULL, objective = "auto",
  stationary = c("T0TIPREDEFFECT"), optimizer = "SLSQP",
  retryattempts = 10, iterationSummary = TRUE, carefulFit = FALSE,
  showInits = FALSE, asymptotes = FALSE, meanIntervals = FALSE,
  plotOptimization = F, nofit = FALSE, discreteTime = FALSE,
  verbose = 0, useOptimizer = TRUE, omxStartValues = NULL)

Arguments

datawide
the data you wish to fit a ctsem model to.
ctmodelobj
the ctsem model object you wish to use, specified via the ctModel function.
confidenceintervals
vector of character strings of matrices or single parameters to calculate 95% confidence intervals for. e.g. c("DRIFT", "TRAITVAR").
objective
'auto' selects either 'Kalman', if fitting to single subject data, or 'mxRAM' for multiple subjects. For single subject data, 'Kalman' uses the mxExpectationStateSpace function from OpenMx to implement the Kalman filter. For more than one
stationary
Character vector of T0 matrix names in which to constrain any free parameters to stationarity. Defaults to c('T0TIPREDEFFECT'), constraining only the between subject difference effects. Can be set to NULL to force all T0 matrices to be estimated, can be
optimizer
character string, defaults to the open-source 'SLSQP' optimizer that is distributed in all versions of OpenMx. However, 'NPSOL' may sometimes perform better for these problems, though requires that you have installed OpenMx manually, by running:
retryattempts
Number of times to retry the start value randomisation and fit procedure, if non-convergance or uncertain fits occur.
iterationSummary
if TRUE, outputs limited fit details after every fit attempt.
carefulFit
if TRUE, first fits the specified model with a penalised likelihood function to force MANIFESTVAR, DRIFT, TRAITVAR, MANIFESTTRAITVAR parameters to remain close to 0, then fits the specified model normally, using these estimates as starting values. Can
showInits
if TRUE, prints the list of user specified and auto generated starting values for free parameters.
asymptotes
when TRUE, optimizes over asymptotic parameter matrices instead of continuous time parameter matrices. Can be useful for optimization and model development, but should result in equivalent models if optimization is adequate.
meanIntervals
Use average time intervals for each column for calculation (both faster and inaccurate to the extent that intervals vary across individuals).
plotOptimization
If TRUE, uses checkpointing for OpenMx function mxRun, set to checkpoint every iteration, output checkpoint file to working directory, then creates a plot for each parameter's values over iterations.
nofit
if TRUE, output only openmx model without fitting
discreteTime
Estimate a discrete time model - ignores timing information, parameter estimates will correspond to those of classical vector autoregression models, OpenMx fit object will be directly output, thus ctsem summary and plot functionality will be unavailable
verbose
Integer between 0 and 3. Sets mxComputeGradientDescent messaging level, defaults to 0.
useOptimizer
Logical. Defaults to TRUE. Passes argument to mxRun, useful for using custom optimizers or fitting to specified parameters.
omxStartValues
A named vector containing already transformed (e.g. log(-(driftdiagonalparam)) or log(diffusionvarianceeparam) starting values for free parameters, as captured by OpenMx function omxGetParameters(ctmodelobj$mxobj).

Details

DATA STRUCTURE: Single row per subject. Manifest variables first, grouped by measurement occasion (with later measurements to the right), then 1st time dependent predictor (all observations 1:(Tpoints-1)), further time dependent predictors, time intervals between observations, time independent predictors.

Examples

Run this code
mfrowOld<-par()$mfrow
par(mfrow=c(2, 3))

### example from Driver, Oud, Voelkle (2015),
### simulated happiness and leisure time with unobserved heterogeneity.
data(ctExample1)
traitmodel <- ctModel(n.manifest=2, n.latent=2, Tpoints=6, LAMBDA=diag(2),
  manifestNames=c('LeisureTime', 'Happiness'),
  latentNames=c('LeisureTime', 'Happiness'), TRAITVAR="auto")
traitfit <- ctFit(datawide=ctExample1, ctmodelobj=traitmodel)
summary(traitfit)
plot(traitfit, wait=FALSE)


###Example from Voelkle, Oud, Davidov, and Schmidt (2012) - anomia and authoritarianism.
data(AnomAuth)
AnomAuthmodel <- ctModel(LAMBDA = matrix(c(1, 0, 0, 1), nrow = 2, ncol = 2),
Tpoints = 5, n.latent = 2, n.manifest = 2, MANIFESTVAR=diag(0, 2), TRAITVAR = NULL)
AnomAuthfit <- ctFit(AnomAuth, AnomAuthmodel)
summary(AnomAuthfit)


### Single subject time series - using Kalman filter (OpenMx statespace expectation)
data('ctExample3')
model <- ctModel(n.latent = 1, n.manifest = 3, Tpoints = 100,
  LAMBDA = matrix(c(1, 'lambda2', 'lambda3'), nrow = 3, ncol = 1),
  MANIFESTMEANS = matrix(c(0, 'manifestmean2', 'manifestmean3'), nrow = 3,
    ncol = 1))
fit <- ctFit(data = ctExample3, ctmodelobj = model, objective = 'Kalman',
  stationary = c('T0VAR'))


###Oscillating model from Voelkle & Oud (2013).
data(Oscillating)
inits <- c(-38,-.5,1,10,10)
names(inits)<-c('cross','auto','diffusion22','T0var11','T0var22')
oscillatingm<-ctModel(n.latent = 2, n.manifest=1, Tpoints=11,
 MANIFESTVAR=matrix(c(0), nrow=1, ncol=1),
 LAMBDA=matrix(c(1, 0), nrow=1, ncol=2),
 DRIFT=matrix(c(0, "cross", 1, "auto"), nrow=2, ncol=2),
 CINT=matrix(c(0,0), ncol=1, nrow=2, ),
 DIFFUSION=matrix(c(0, 0, 0, "diffusion22"), nrow=2, ncol=2),
 startValues = inits)
oscillatingf<-ctFit(Oscillating, oscillatingm, optimizer='SLSQP')
summary(oscillatingf)

Run the code above in your browser using DataLab