library(OpenMx)
library(metaSEM)
my.df <- readLowTriMat(file = "test.dat", no.var = 5,
na.strings = "NA")
n<-c(1421,161,175,28,66,41,187,214,102,212,190,180,210,69,212,460,41,187,214,102)
#STAGE 1
random1<- tssem1(my.df, n, method = "REM",RE.type="Diag")
summary(random1)
coef(random1)
#STAGE 2
# Matrix A #
A1 <- create.mxMatrix(c(0,0,"0.2*X1X3","0.2*X1X4","0.2*X1X5",0,0,"0.2*X2X3","0.2*X2X4","0.2*X2X5",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0),
type="Full", ncol=5, nrow=5, name="A1",dimnames=list(c("X1","X2","X3","X4","X5"), c("X1","X2","X3","X4","X5")))
A1
# Matrix s #
S1 <- create.mxMatrix(c(1,"0.2*CorX1X2",0,0,0,"0.2*CorX1X2",1,0,0,0,0,0,"0.2*ErrorVarX3",0,0,0,0,0,"0.2*ErrorVarX4",0,0,0,0,0,"0.2*ErrorVarX5"),
name="S1", nrow=5, ncol=5, dimnames=list(c("X1","X2","X3","X4","X5"), c("X1","X2","X3","X4","X5")))
S1
random2<- tssem2(random1, Amatrix = A1,
Smatrix = S1, intervals = "LB",diag.constraints=TRUE,
model.name="TSSEM2 random effects model")
summary(random2)