# \donttest{
Digman97
##### Fixed-effects TSSEM
fixed1 <- tssem1(Digman97$data, Digman97$n, method="FEM")
summary(fixed1)
## Two-factor CFA model in lavaan syntax
model <- "## Factor loadings
Alpha=~A+C+ES
Beta=~E+I
## Factor correlation
Alpha~~Beta"
## Display the model
plot(model)
RAM <- lavaan2RAM(model, obs.variables=c("A","C","ES","E","I"),
A.notation="on", S.notation="with")
RAM
## ## Equivalent RAM specification
## Phi <- matrix(c(1,"0.3*cor","0.3*cor",1), ncol=2, nrow=2)
## Psi <- Diag(c("0.2*e1","0.2*e2","0.2*e3","0.2*e4","0.2*e5"))
## S1 <- bdiagMat(list(Psi, Phi))
## dimnames(S1)[[1]] <- dimnames(S1)[[2]] <- c("A","C","ES","E","I","Alpha","Beta")
## S1
##
## Lambda <- matrix(c(".3*Alpha_A",".3*Alpha_C",".3*Alpha_ES",rep(0,5),
## ".3*Beta_E",".3*Beta_I"), ncol=2, nrow=5)
## A1 <- rbind( cbind(matrix(0,ncol=5,nrow=5), Lambda),
## matrix(0, ncol=7, nrow=2) )
## dimnames(A1)[[1]] <- dimnames(A1)[[2]] <- c("A","C","ES","E","I","Alpha","Beta")
## A1
##
## F1 <- create.Fmatrix(c(1,1,1,1,1,0,0), as.mxMatrix=FALSE)
fixed2 <- tssem2(fixed1, RAM=RAM,
model.name="TSSEM2 Digman97")
summary(fixed2)
## Display the model with the parameter estimates
plot(fixed2)
#### Fixed-effects TSSEM with several clusters
#### Create a variable for different samples
#### Younger participants: Children and Adolescents
#### Older participants: others
cluster <- ifelse(Digman97$cluster %in% c("Children","Adolescents"),
yes="Younger participants", no="Older participants")
#### Show the cluster
cluster
## Example of Fixed-effects TSSEM with several clusters
fixed1.cluster <- tssem1(Digman97$data, Digman97$n, method="FEM",
cluster=cluster)
summary(fixed1.cluster)
fixed2.cluster <- tssem2(fixed1.cluster, RAM=RAM)
#### Please note that the estimates for the younger participants are problematic.
summary(fixed2.cluster)
## Setup two plots
layout(t(1:2))
## Plot the first group
plot(fixed2.cluster[[1]])
title("Younger participants")
## Plot the second group
plot(fixed2.cluster[[2]])
title("Older participants")
#### Random-effects TSSEM with random effects on the diagonals
random1 <- tssem1(Digman97$data, Digman97$n, method="REM",
RE.type="Diag")
summary(random1)
random2 <- tssem2(random1, RAM=RAM)
summary(random2)
## Display the model with the parameter estimates
plot(random2, color="green")
# }
Run the code above in your browser using DataLab