# \donttest{
data(issp05)
#### TSSEM random-effects model with covariance matrices
## Stage 1 analysis
rand1 <- tssem1(issp05$data, issp05$n, method="REM", cor.analysis=FALSE)
summary(rand1)
## Proposed model
model1 <- "JP =~ JP1 + JP2 + JP3
JA =~ JA1 + JA2
CS =~ CS1 + CS2
JP ~~ JA + CS
JA ~~ CS"
ram1 <- lavaan2RAM(model1, obs.variables=c("JP1", "JP2", "JP3", "JA1", "JA2",
"CS1", "CS2"))
## Stage 2 analysis
rand2 <- tssem2(rand1, RAM=ram1)
summary(rand2)
plot(rand2)
#### OSMASEM with covariance matrices
## Create a data frame for the OSMASEM
df <- Cor2DataFrame(issp05$data, n=issp05$n, Means=issp05$means,
cor.analysis=FALSE)
## Standardize idv
idv <- scale(issp05$idv)
## Replace missing values with mean
idv[is.na(idv)] <- mean(idv, na.rm=TRUE)
df$data$idv <- idv
## No moderator
fit1 <- osmasem2(model.name="No_moderator", RAM=ram1, data=df,
cor.analysis=FALSE, mean.analysis=FALSE)
summary(fit1, fitIndices = TRUE)
## Proposed model with idv as a moderator
model2 <- "JP =~ a*JP1 + b*JP2 + c*JP3
JA =~ d*JA1 + e*JA2
CS =~ f*CS1 + g*CS2
JP ~~ JA + CS
JA ~~ CS
a == a0 + a1*data.idv
b == b0 + b1*data.idv
c == c0 + c1*data.idv
d == d0 + d1*data.idv
e == e0 + e1*data.idv
f == f0 + f1*data.idv
g == g0 + g1*data.idv"
ram2 <- lavaan2RAM(model2, obs.variables=c("JP1", "JP2", "JP3", "JA1", "JA2",
"CS1", "CS2"))
fit2 <- osmasem2(RAM=ram2, data=df, cor.analysis=FALSE, mean.analysis=FALSE,
replace.constraints = TRUE)
summary(fit2)
## Compare fit1 and fit2
anova(fit2, fit1)
# }
Run the code above in your browser using DataLab