Unlimited learning, half price | 50% off

Last chance! 50% off unlimited learning

Sale ends in


⚠️There's a newer version (3.10.2) of this package.Take me there.

See the NEWS file for recent updates!

ctsem allows for easy specification and fitting of a range of continuous and discrete time dynamic models, including multiple indicators (dynamic factor analysis), multiple, potentially higher order processes, and time dependent (varying within subject) and time independent (not varying within subject) covariates. Classic longitudinal models like latent growth curves and latent change score models are also possible. Version 1 of ctsem provided SEM based functionality by linking to the OpenMx software, allowing mixed effects models (random means but fixed regression and variance parameters) for multiple subjects. For version 2 of the R package ctsem, we include a hierarchical specification and fitting routine that uses the Stan probabilistic programming language, via the rstan package in R. This allows for all parameters of the dynamic model to individually vary, using an estimated population mean and variance, and any time independent covariate effects, as a prior. Version 3 allows for state dependencies in the parameter specification (i.e. time varying parameters). ctsem V1 is documented in a JSS publication (Driver, Voelkle, Oud, 2017), and in R vignette form at https://cran.r-project.org/package=ctsem/vignettes/ctsem.pdf .While the more recent updates are outlined at https://github.com/cdriveraus/ctsem/raw/master/vignettes/hierarchicalmanual.pdf . To cite ctsem please use the citation(“ctsem”) command in R.

To install the github version and (if needed) configure your system, from a fresh R session run:

source(file = 'https://github.com/cdriveraus/ctsem/raw/master/installctsem.R')

If there are problems with the above script, you can try:

Manually install rstan, Rtools

remotes::install_github('cdriveraus/ctsem', INSTALL_opts = "--no-multiarch", dependencies = c("Depends", "Imports"))

Or just use the CRAN version, but rstan compiler setup is needed separately for some models:

install.packages('ctsem')

Troubleshooting Rstan / Rtools install for Windows:

Ensure recent version of R and Rtools is installed. If the installctsem.R code has never been run before, be sure to run that (see above).

Make sure these lines exist in home/.R/makevars.win :

CXX14FLAGS=-O3 -mtune=native
CXX11FLAGS=-O3 -mtune=native
CXX14 = $(BINPREF)g++ -m$(WIN) -std=c++1y

If makevars does not exist, re-run the install code above.

In case of compile errors like g++ not found, ensure the devtools package is installed:

install.packages('devtools')

and include the following in your .Rprofile, replacing c:/Rtools with the appropriate path – sometimes Rbuildtools/3.5/ .

library(devtools)
Sys.setenv(PATH = paste("C:/Rtools/bin", Sys.getenv("PATH"), sep=";"))
Sys.setenv(PATH = paste("C:/Rtools/mingw_64/bin", Sys.getenv("PATH"), sep=";"))
Sys.setenv(BINPREF = "C:/Rtools/mingw_$(WIN)/bin/")

Copy Link

Version

Install

install.packages('ctsem')

Monthly Downloads

612

Version

3.0.9

License

GPL-3

Issues

Pull Requests

Stars

Forks

Maintainer

Charles Driver

Last Published

December 18th, 2019

Functions in ctsem (3.0.9)

AnomAuth

AnomAuth
ctModelHigherOrder

Raise the order of a ctsem model object of type 'omx'.
ctModelLatex

Generate and optionally compile latex equation of subject level ctsem model.
ctExample2level

ctExample2level
ctDiscretePars

ctDiscretePars
ctDensity

ctDensity
ctExample1

ctExample1
ctDeintervalise

ctDeintervalise
ctCompareExpected

ctCompareExpected Compares model implied to observed means and covariances for panel data fit with ctsem.
ctPlot

ctPlot
Oscillating

Oscillating
plot.ctsemFitMeasure

Misspecification plot using ctCheckFit output
ctMultigroupFit

Fits a multiple group continuous time model.
ctstantestfit

ctstantestfit
ctStanTIpredMarginal

Plot marginal relationships between covariates and parameters for a ctStanFit object.
ctStanTIpredeffects

Get time independent predictor effect estimates
ctstantestdat

ctstantestdat
ctCI

ctCI Computes confidence intervals on specified parameters / matrices for already fitted ctsem fit object.
ctDiscretiseData

Discretise long format continuous time (ctsem) data to specific timestep.
plot.ctsemMultigroupFit

Plot function for ctsemMultigroupFit object
ctLongToWide

ctLongToWide Restructures time series / panel data from long format to wide format for ctsem analysis
ctStanFit

ctStanFit
ctKalman

ctKalman
ctStanGenerate

Generate data from a ctstanmodel object
ctExample1TIpred

ctExample1TIpred
ctStanGenerateFromFit

Add a $generated object to ctstanfit object, with random data generated from posterior of ctstanfit object
ctStanDiscreteParsPlot

ctStanDiscreteParsPlot
summary.ctsemFit

Summary function for ctsemFit object
summary.ctsemMultigroupFit

Summary function for ctsemMultigroupFit object
ctExample3

ctExample3
ctStanContinuousPars

ctStanContinuousPars
ctExample4

ctExample4
isdiag

Diagnostics for ctsem importance sampling
ctIndplot

ctIndplot
ctIntervalise

Converts absolute times to intervals for wide format ctsem panel data
ctCollapse

ctCollapse Easily collapse an array margin using a specified function.
ctCheckFit

Check absolute fit of ctFit or ctStanFit object.
longexample

longexample
ctExtract

Extract samples from a ctStanFit object
ctFit

Fit a ctsem object
ctModel

Define a ctsem model
msquare

Right multiply a matrix by its transpose.
ctStanDiscretePars

ctStanDiscretePars
ctStanParMatrices

Returns population system matrices from a ctStanFit object, and vector of values for free parameters.
stan_postcalc

Compute functions of matrices from samples of a stanfit object
ctStanParnames

ctStanParnames
plot.ctKalman

Plots Kalman filter output from ctKalman.
stan_reinitsf

Quickly initialise stanfit object from model and data
datastructure

datastructure
inv_logit

Inverse logit
sdpcor2cov

sdcor2cov
stanWplot

Runs stan, and plots sampling information while sampling.
ctStanUpdModel

Update an already compiled and fit ctStanFit object
ctPlotArray

Plots three dimensional y values for quantile plots
ctStanPlotPost

ctStanPlotPost
ctStanPostPredict

Compares model implied density and values to observed, for a ctStanFit object.
ctPoly

Plots uncertainty bands with shading
ctModelFromFit

Extract a ctsem model structure with parameter values from a ctsem fit object.
ctDocs

Get documentation pdf for ctsem
ctWideNames

ctWideNames sets default column names for wide ctsem datasets. Primarily intended for internal ctsem usage.
ctGenerate

ctGenerate
plot.ctStanModel

Prior plotting
plot.ctsemFit

Plotting function for object class ctsemFit
stanoptimis

Optimize / importance sample a stan or ctStan model.
summary.ctStanFit

summary.ctStanFit
stan_checkdivergences

Analyse divergences in a stanfit object
stan_confidenceRegion

Extract functions of multiple variables from a stanfit object
ctGenerateFromFit

Generates data according to the model estimated in a ctsemFit object.
ctPostPredict

Posterior predictive type check for ctsemFit.
ctRefineTo

ctRefineTo
ctStanKalman

Get Kalman filter estimates from a ctStanFit object
plot.ctKalmanDF

Plots Kalman filter output from ctKalman.
ctsem

ctsem
ctWideToLong

ctWideToLong Convert ctsem wide to long format
ctStanModel

Convert a frequentist (omx) ctsem model specification to Bayesian (Stan).
plot.ctStanFit

plot.ctStanFit
stan_unconstrainsamples

Convert samples from a stanfit object to the unconstrained scale
standatact_specificsubjects

Adjust standata from ctsem to only use specific subjects
ctExample2

ctExample2
Kalman

Kalman