Learn R Programming

ctsem (version 2.1.0)

ctStanKalman: ctStanKalman

Description

Outputs predicted, updated, and smoothed estimates of manifest indicators and latent states, with covariances, for specific subjects from data fit with ctStanFit.

Usage

ctStanKalman(ctstanfitobj, datalong = NULL, timerange = "asdata", timestep = "asdata", subjects = 1, plot = FALSE, ...)

Arguments

ctstanfitobj
fit object as generated by ctStanFit.
datalong
Optional long format data object as used by ctStanFit. If not included, data from ctstanfitobj will used.
timerange
Either 'asdata' to just use the observed data range, or a numeric vector of length 2 denoting start and end of time range, allowing for estimates outside the range of observed data.
timestep
Either 'asdata' to just use the observed data (which also requires 'asdata' for timerange) or a positive numeric value indicating the time step to use for interpolating values.
subjects
vector of integers denoting which subjects (from 1 to N) to plot predictions for.
plot
Logical. If TRUE, plots output instead of returning it. See ctStanKalmanPlot for the possible arguments.
...
additional arguments to pass to ctStanKalmanPlot.

Value

Returns a list containing matrix objects etaprior, etaupd, etasmooth, y, yprior, yupd, ysmooth, prederror, time, loglik, with values for each time point in each row. eta refers to latent states and y to manifest indicators - y itself is thus just the input data. Covariance matrices etapriorcov, etaupdcov, etasmoothcov, ypriorcov, yupdcov, ysmoothcov, are returned in a row * column * time array. If plot=TRUE, nothing is returned but a plot is generated.

Examples

Run this code
#Basic
ctStanKalman(ctstantestfit, timerange=c(0,60), timestep=.5, plot=TRUE)

#Multiple subjects, y and yprior, showing plot arguments
ctStanKalman(ctstantestfit, timerange=c(0,60), timestep=.1, plot=TRUE,
  subjects=2:3, 
  kalmanvec=c('y','yprior'),
  errorvec=c(NA,'ypriorcov'), #'auto' would also have achieved this
  ltyvec="auto",
  colvec='auto', 
  lwdvec='auto', 
  subsetindices=2, #Only plotting 2nd dimension of y and yprior
  pchvec='auto', typevec='auto',grid=TRUE,legend=TRUE,
  plotcontrol=list(xlim=c(0,55),main='Observations and priors'),
  polygoncontrol=list(density=20))

Run the code above in your browser using DataLab