# \donttest{
## These are correlation matrices; set a missing diagonal to 1 when the
## corresponding variable has a reported correlation.
roorda_cor <- lapply(Roorda11$data, function(S) {
observed <- vapply(seq_len(nrow(S)), function(i) any(!is.na(S[i, -i])), logical(1))
d <- diag(S)
d[is.na(d) & observed] <- 1
diag(S) <- d
S
})
## Random-effects model: First stage analysis
random1 <- tssem1(Cov = roorda_cor, n = Roorda11$n, method = "REM",
RE.type = "Diag")
summary(random1)
## Model specification in lavaan syntax
model <- "## Regression paths
enga ~ b31*pos + b32*neg
achiev ~ b43*enga
## Variances of pos and neg are fixed at 1
pos ~~ 1*pos
neg ~~ 1*neg
## Correlation between pos and neg
pos ~~ p21*neg
## Error variances
enga ~~ p33*enga
achiev ~~ p44*achiev"
RAM <- lavaan2RAM(model, obs.variables=c("pos", "neg", "enga", "achiev"))
RAM
## ## Equivalent RAM specification using create.mxMatrix()
## varnames <- c("pos", "neg", "enga", "achiev")
## A <- create.mxMatrix(c(0,0,0,0,
## 0,0,0,0,
## "0.1*b31","0.1*b32",0,0,
## 0,0,"0.1*b43",0),
## type = "Full", nrow = 4, ncol = 4, byrow = TRUE,
## name = "A", as.mxMatrix = FALSE)
## dimnames(A) <- list(varnames, varnames)
## A
##
## S <- create.mxMatrix(c(1,
## ".5*p21",1,
## 0,0,"0.6*p33",
## 0,0,0,"0.6*p44"),
## type="Symm", byrow = TRUE,
## name="S", as.mxMatrix = FALSE)
## dimnames(S) <- list(varnames, varnames)
## S
## Random-effects model: Second stage analysis
## Calculate dependent-variable residual variances implicitly.
random2 <- tssem2(random1, RAM=RAM, diag.constraints=FALSE,
intervals.type="LB")
summary(random2)
## Display the model with the parameter estimates
plot(random2)
# }
Run the code above in your browser using DataLab