mfrowOld<-par()$mfrow
par(mfrow=c(2, 3))
### example from Driver, Oud, Voelkle (2015),
### simulated happiness and leisure time with unobserved heterogeneity.
data(ctExample1)
traitmodel <- ctModel(n.manifest=2, n.latent=2, Tpoints=6, LAMBDA=diag(2),
manifestNames=c('LeisureTime', 'Happiness'),
latentNames=c('LeisureTime', 'Happiness'), TRAITVAR="auto")
traitfit <- ctFit(datawide=ctExample1, ctmodelobj=traitmodel)
summary(traitfit)
plot(traitfit, wait=FALSE)
###Example from Voelkle, Oud, Davidov, and Schmidt (2012) - anomia and authoritarianism.
data(AnomAuth)
AnomAuthmodel <- ctModel(LAMBDA = matrix(c(1, 0, 0, 1), nrow = 2, ncol = 2),
Tpoints = 5, n.latent = 2, n.manifest = 2, MANIFESTVAR=diag(0, 2), TRAITVAR = NULL)
AnomAuthfit <- ctFit(AnomAuth, AnomAuthmodel)
summary(AnomAuthfit)
### Single subject time series - using Kalman filter (OpenMx statespace expectation)
data('ctExample3')
model <- ctModel(n.latent = 1, n.manifest = 3, Tpoints = 100,
LAMBDA = matrix(c(1, 'lambda2', 'lambda3'), nrow = 3, ncol = 1),
MANIFESTMEANS = matrix(c(0, 'manifestmean2', 'manifestmean3'), nrow = 3,
ncol = 1))
fit <- ctFit(data = ctExample3, ctmodelobj = model, objective = 'Kalman',
stationary = c('T0VAR'))
###Oscillating model from Voelkle & Oud (2013).
data(Oscillating)
inits <- c(-38,-.5,1,10,10)
names(inits)<-c('cross','auto','diffusion22','T0var11','T0var22')
oscillatingm<-ctModel(n.latent = 2, n.manifest=1, Tpoints=11,
MANIFESTVAR=matrix(c(0), nrow=1, ncol=1),
LAMBDA=matrix(c(1, 0), nrow=1, ncol=2),
DRIFT=matrix(c(0, "cross", 1, "auto"), nrow=2, ncol=2),
CINT=matrix(c(0,0), ncol=1, nrow=2, ),
DIFFUSION=matrix(c(0, 0, 0, "diffusion22"), nrow=2, ncol=2),
startValues = inits)
oscillatingf<-ctFit(Oscillating, oscillatingm, optimizer='SLSQP')
summary(oscillatingf)Run the code above in your browser using DataLab