Created
May 14, 2021 08:34
-
-
Save cdriveraus/e21fb2bb8797617d5f6338fe841e75dd to your computer and use it in GitHub Desktop.
Simple bivariate ctsem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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