Skip to content

Instantly share code, notes, and snippets.

@cdriveraus
Created May 14, 2021 08:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cdriveraus/e21fb2bb8797617d5f6338fe841e75dd to your computer and use it in GitHub Desktop.
Save cdriveraus/e21fb2bb8797617d5f6338fe841e75dd to your computer and use it in GitHub Desktop.
Simple bivariate ctsem
# The current manual is here:
# https://cran.r-project.org/web/packages/ctsem/vignettes/hierarchicalmanual.pdf
# A few blog posts with examples are here: https://cdriver.netlify.app/
# Here's a bivariate panel example script:
library(ctsem)
data(AnomAuth)
longdat <- ctDeintervalise(ctWideToLong(AnomAuth,Tpoints = 5,n.manifest = 2))
sm<-ctModel(type='stanct',id='id',time = 'time',
manifestNames = c('Y1','Y2'),
MANIFESTVAR=0, #disables measurement error for this example
LAMBDA=matrix(c(1, 0, 0, 1), nrow=2, ncol=2))
ctModelLatex(sm)
#default is to allow 'trait' type effects -- individual variation in intercept parameters. One way to disable is:
sm$pars$indvarying<- FALSE
sf=ctStanFit(longdat, ctstanmodel = sm,cores=6)
s=summary(sf)
print(s)
ctKalman(sf,plot=TRUE,kalmanvec=c('y','ysmooth'),subjects = c(1,3))
ctStanDiscretePars(sf,plot=TRUE)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment