Science Score: 36.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
2 of 6 committers (33.3%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (17.1%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Hierarchical continuous time state space modelling
Statistics
- Stars: 43
- Watchers: 5
- Forks: 17
- Open Issues: 2
- Releases: 0
Topics
Metadata Files
README.md
See the NEWS file for recent updates, and below for quick start!
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).
The current manual is at https://cran.r-project.org/package=ctsem/vignettes/hierarchicalmanual.pdf. The original ctsem is documented in a JSS publication (Driver, Voelkle, Oud, 2017), and in R vignette form at https://cran.r-project.org/package=ctsemOMX/vignettes/ctsem.pdf, however these OpenMx based functions have been split off into a sub package, ctsemOMX. For most use cases the newer formulation (with Kalman filtering coded in Stan) is faster, more robust, and more flexible, and both default to maximum likelihood. For cases with many subjects, few time points, and no individual differences in timing, ctsemOMX may be faster.
For questions (or to see past answers) please use https://github.com/cdriveraus/ctsem/discussions
For some tutorials and another quick start, see . The very quick start is below.
To cite ctsem please use the citation(“ctsem”) command in R.
To install the github version, first install rstan and Rtools, then from a fresh R session:
r
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:
r
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).
Place this line in ~/.R/makevars.win , and if there are other lines, delete them:
CXX17FLAGS += -mtune=native -Wno-ignored-attributes -Wno-deprecated-declarations
For compile issues, check if you can use rstan, check forum posts on
In case of compile errors like g++ not found, ensure the devtools
package is installed:
r
install.packages('devtools')
Quick start – univariate panel data with covariate effects on parameters
#’ The basic long data structure. Diet, (our covariate) is a categorical variable so needs dummy / ‘one hot’ encoding.
r
head(ChickWeight)
#’ Setup dummy coding
r
library(data.table)
library(mltools)
chickdata <- one_hot(as.data.table(ChickWeight),cols = 'Diet')
#’ Scaling of continuous variables makes for easier estimation and more sensible default priors (if used). Time intervals can also benefit
r
chickdata$weight <- scale(chickdata$weight)
head(chickdata) #now we have the four diet categories
#’ Setup continuous time model – in this case we are estimating a regular first order autoregressive
``` r library(ctsem)
m <- ctModel( LAMBDA=diag(1), #Factor loading matrix of latent processes on measurements, fixed to 1 type = 'ct', #Could specify 'dt' here for discrete time. tipredDefault = FALSE, #limit covariate effects on parameters to those explicitly specified manifestNames='weight', #Observed measurements of the latent processes latentNames='Lweight', #Names here simply make parameters and plots more interpretable TIpredNames = paste0('Diet',2:4), #Covariates, in this case one category needs to be baseline... DRIFT='a11 | param', #normally self feedback (diagonal drift terms) are restricted to negative MANIFESTMEANS=0, #For identification CINT is normally zero with this freely estimated CINT='cint ||||Diet2,Diet3,Diet4', #diet covariates specified in 5th 'slot' (four '|' separators) time='Time', id='Chick') ```
#’ View model in pdf/ latex form
r
ctModelLatex(m)
#’ Fit model to data – here using priors because Hessian problems are reported otherwise
r
f <- ctStanFit(chickdata,m,priors=TRUE)
#’ Summarise fit, view covariate effects – Diets 3 and 4 seem most obviously successful
``` r s=summary(f)
print(s$tipreds ) ```
#’ Predictions conditional on all earlier data
r
ctKalman(f,plot=TRUE,subjects=2:4,kalmanvec=c('yprior','ysmooth'))
#’ Predictions conditional only on covariates, showing 1 chick from each diet
r
ctKalman(f,plot=T,
subjects=as.numeric(chickdata$Chick[!duplicated(ChickWeight$Diet)]),
removeObs = T,polygonalpha=0)
#’ Plot temporal regression coefficients conditional on time interval – increases in this case!
r
ctStanDiscretePars(f,plot=T)
#’ Other useful functions:
#’ Compare two fits: ctChisqTest()
#’ Fit and summarise / plot a list of models: ctFitMultiModel()
#’ Add samples to fit to increase estimate precision: ctAddSamples()
#’ Return dynamic system parameters in matrix forms: ctStanContinuousPars()
#’ Compute cross validation statistics: ctLOO()
#’ Plot time independent predictor (covariate effects on parameters): ctStanTIpredEffects()
#’ Generate data from a specified model of fixed parameters: ctGenerate()
#’ Generate data from a specified model of fixed and free parameters / priors: ctStanGenerate()
#’ Generate data from a fitted model: ctStanGenerateFromFit()
#’ Get samples from the fitted object: ctExtract()
#’ In samples, popDRIFT refers to the population drift matrix, subjDRIFT refers to the subject matrix. Subject matrices only computed for max likelihood / posterior mode by default, and found in the $stanfit$transformedparsfull object.
Owner
- Name: Charles Driver
- Login: cdriveraus
- Kind: user
- Repositories: 4
- Profile: https://github.com/cdriveraus
GitHub Events
Total
- Watch event: 2
- Push event: 26
- Create event: 1
Last Year
- Watch event: 2
- Push event: 26
- Create event: 1
Committers
Last synced: over 2 years ago
Top Committers
| Name | Commits | |
|---|---|---|
| cdriveraus | c****s@g****m | 992 |
| Charles Driver | d****r@m****e | 53 |
| evelynmitchell | e****b@l****m | 1 |
| Ben Goodrich | g****n@g****m | 1 |
| Michael Krause | k****e@m****e | 1 |
| Joshua Nathaniel Pritikin | j****n@p****m | 1 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 11 months ago
All Time
- Total issues: 15
- Total pull requests: 6
- Average time to close issues: 6 months
- Average time to close pull requests: 6 days
- Total issue authors: 11
- Total pull request authors: 5
- Average comments per issue: 7.07
- Average comments per pull request: 2.33
- Merged pull requests: 4
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- ryanoisin (3)
- emstruong (2)
- bgoodri (2)
- marutter (1)
- SteveBronder (1)
- ruan2ruan (1)
- stemangiola (1)
- Kyabdro (1)
- blainmorin (1)
- beew (1)
Pull Request Authors
- andrjohns (2)
- evelynmitchell (1)
- octomike (1)
- jpritikin (1)
- bgoodri (1)
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- cran 691 last-month
- Total docker downloads: 1,419
- Total dependent packages: 2
- Total dependent repositories: 7
- Total versions: 54
- Total maintainers: 1
cran.r-project.org: ctsem
Continuous Time Structural Equation Modelling
- Homepage: https://github.com/cdriveraus/ctsem
- Documentation: http://cran.r-project.org/web/packages/ctsem/ctsem.pdf
- License: GPL-3
-
Latest release: 3.10.4
published about 1 year ago
Rankings
Maintainers (1)
Dependencies
- R >= 3.5.0 depends
- Rcpp >= 0.12.16 depends
- Deriv * imports
- MASS * imports
- Matrix * imports
- RcppParallel * imports
- cOde * imports
- data.table >= 1.12.8 imports
- datasets * imports
- expm * imports
- ggplot2 * imports
- grDevices * imports
- graphics * imports
- methods * imports
- mize * imports
- mvtnorm * imports
- parallel * imports
- plyr * imports
- rstan >= 2.19.0 imports
- stats * imports
- tibble * imports
- tools * imports
- utils * imports
- DEoptim * suggests
- arules * suggests
- devtools * suggests
- gridExtra * suggests
- knitr * suggests
- lme4 * suggests
- shiny * suggests
- testthat * suggests
- tinytex * suggests
- actions/checkout v3 composite
- r-lib/actions/check-r-package v2 composite
- r-lib/actions/setup-pandoc v2 composite
- r-lib/actions/setup-r v2 composite
- r-lib/actions/setup-r-dependencies v2 composite
- r-lib/actions/setup-tinytex v2 composite