Hi,
I noticed that in mulitlevel SEM, in the estimate of the between-group covariance matrix (Sigma_B) negative variances and related covariances are set to 0. However, I did not find any information on this procedure in the official sources. Did I miss any sources? What is the reason for this procedure? I put a minimal example below.
Thanks in advance!
Best,
Julia
#######################
library(lavaan)
library(Morpho)
set.seed(1499)
# set population model (unstructured bivariate model)
Sigma_W <- "y ~~ 1*y;
x ~~ 1*x;
y ~~ 0.5*x"
Sigma_B <- "y ~~ 0.2*y;
x ~~ 0.2*x;
y ~~ 0.1*x"
# set sample sizes
n <- 4 # cluster size
g <- 5 # number of clusters
data_W <- simulateData(Sigma_W, sample.nobs=n*g, model.type="lavaan")
data_B <- simulateData(Sigma_B, sample.nobs=g, model.type="lavaan")
groups <- rep(1:g, each=n) # grouping variable
data_T <- data_W # create final total data matrix (that we would sample) in the following
data_T[,] <- 0
for (j in unique(groups)){
for (i in min(which(groups == j)):max(which(groups == j)))
data_T[i,] <- data_W[i,] + data_B[j,]
}
data_T$groups <- as.factor(groups)
data_T$persons <- rep(1:n, g)
# estimate model (same as population model)
model <- '
level: 1
y ~~ y
x ~~ x
y ~~ x
level: 2
y ~~ y
x ~~ x
y ~~ x
'
fit <- sem(model, data = data_T, cluster = "groups")
# estimate (sample) covariance matrices (I rebuild lavaans estimation of the between-group level sample covariance matrices here, see also Muthen 1989, 1990, 1994 for the estimators)
S_pw <- covW(data=data_T[,1:2], groups=data_T[,3])
group_means <- attr(S_pw, "means")
attr(S_pw, "means") <- NULL
grand_means <- colMeans(data_T[,1:2], na.rm = TRUE)
datac <- t(t(group_means) - grand_means)
S_B <- lavaan:::lav_matrix_crossprod(datac * n, datac)/(g - 1)
Sigma_B <- (S_B - S_pw) / n
# compare the Sigma_B
Sigma_B # Muthen (1989, 1990, 1994)
fit@SampleStats@YLp[[1]][[2]][["Sigma.B"]] # lavaan's implementation of Muthen (1989, 1990, 1994)
# the variance of x, and the related covariance xy, are set to zero in lavaan
#######################
References:
Muthén, B. O. (1989). Latent variable modeling in heterogeneous populations. Psychometrika, 54(4), 557–585.
https://doi.org/10.1007/BF02296397Muthén, B. O. (1990). Mean and covariance structure analysis of hierarchical data. 88.
Muthén, B. O. (1994). Multilevel Covariance Structure Analysis. Sociological Methods & Research, 22(3), 376–398.
https://doi.org/10.1177/0049124194022003006