Hi Henrik,
I am definitely not the main person to answer this. But, upon checking the source code (lav_model_vcov.R; specifically, under the "3. defined parameters" step in the last function lav_model_vcov_se), it seems like you are right.
If doing it manually, one also obtains the same results:
set.seed(1)
n <- 20; y1 <- rnorm(n, mean = 8, sd = 3); y2 <- rnorm(n, mean = 10, sd = 3)
data <- data.frame(y1 = y1, y2 = y2)
model <-
"
y1 ~ m1*1
y2 ~ m2*1
diff := m2 - m1
"
fit <- sem(model, data = data); summary(fit)
#lavaan_diff <- parameterEstimates(fit)[parameterEstimates(fit)$label == "diff", "est"]
lavaan_se <- parameterEstimates(fit)[parameterEstimates(fit)$label == "diff", "se"]; (lavaan_se)
# manual calculation using tge delta method:
vcov_matrix <- vcov(fit)[c("m1", "m2"), c("m1", "m2")]; vcov_matrix
# f(m1, m2) = m2 - m1
# jacobian wrt to m1 = -1 and wrt to m2 = 1
jacobian <- matrix(c(-1, 1), nrow = 1)
# delta method: var(diff) = j * Cov * j'
var_diff <- jacobian %*% vcov_matrix %*% t(jacobian); sqrt(var_diff[1,1])
Anyway, I will double check it or someone will hopefully correct me if I am wrong.
Best,
Felipe.