library("metaSEM")
# prepare data
cordat <- readLowTriMat(file = "fan_msceit.dat", no.var = 8,
skip = 1)
N <- c(5000,457,412,655,150,450,138,237,314,405,
375,239,260,266,209,84,192,523,198)
# fixed effects analysis
stage1fixed <- tssem1(Cov = cordat, n = N,
method = "FEM")
summary(stage1fixed)
coef(stage1fixed)
# random efects analysis
stage1random <- tssem1(Cov = cordat, n = N, method = "REM",
RE.type = "Diag")
summary(stage1random)
coef(stage1random)
# Stage 2 analysis
F <- create.Fmatrix(c(1,1,1,1,1,1,1,1,0,0,0), name="F")
lambda <-matrix(
c("0.3*L11",0,0,
"0.3*L21",0,0,
"0.3*L31",0,0,
"0.3*L41",0,0,
0,"0.3*L52",0,
0,"0.3*L62",0,
0,0,"0.3*L73",
0,0,"0.3*L83"),
nrow=8,
ncol=3,
byrow = TRUE)
A <- rbind(cbind(matrix(0,ncol=8,nrow=8),lambda),
matrix(0, nrow=3, ncol=11))
A <- as.mxMatrix(A)
dimnames(A) <- list(c("face","pict","faci","sens","chen","blen","emma","emre","F1","F2","F3"),
c("face","pict","faci","sens","chen","blen","emma","emre","F1","F2","F3"))
theta <- matrix(0,nrow = 8,ncol = 8)
diag(theta) <- c("0.1*t11","0.1*t22","0.1*t33","0.1*t44",
"0.1*t55","0.1*t66","0.1*t77","0.1*t88")
phi <- matrix(
c(1,"0.1*phi21","0.1*phi31",
"0.1*phi21",1,"0.1*phi32",
"0.1*phi31","0.1*phi32",1),
nrow = 3,
ncol = 3)
S <- bdiagMat(list(theta, phi))
S <- as.mxMatrix(S)
dimnames(S) <- list(c("face","pict","faci","sens","chen","blen","emma","emre","F1","F2","F3"),
c("face","pict","faci","sens","chen","blen","emma","emre","F1","F2","F3"))
stage2_random <- tssem2(stage1random, Amatrix=A, Smatrix=S,
Fmatrix=F, diag.constraints=TRUE, intervals="LB")
summary(stage2_random)