different scaled rmsea for lavaan and mplus

119 views
Skip to first unread message

Hao

unread,
Jul 18, 2023, 5:21:34 AM7/18/23
to lavaan

Hi Everyone,

I have a simple three-factor model that I've been trying to estimate using both Mplus and the 'lavaan'. However, I've noticed a difference in the Root Mean Square Error of Approximation (RMSEA) results obtained from both. Mplus is 0.103 and Lavaan is 0.150. The degree of freedom and tli and cfi is same.  I'm not sure whether this is typical or if it's something I need to be concerned about.

lavaan  mod <- cfa(mod, mimic = "Mplus",  estimator = "WLSMV",  ordered = T)
The attachment is dat file and mplus syntax
Thank you, 
Hao
Mptext2.inp
2X.dat

Yves Rosseel

unread,
Jul 18, 2023, 5:56:45 AM7/18/23
to lav...@googlegroups.com
Even the X^2 the statistic is different.

lavaan does give a warning:

In lav_samplestats_step2(UNI = FIT, wt = wt, ov.names = ov.names, :
lavaan WARNING: correlation between variables X22 and X21 is (nearly) 1.0

This is the frequency table:

> table(Data$X21, Data$X22)

1 2 3 4 5
1 18 1 0 0 0
2 2 27 16 1 0
3 0 10 216 32 0
4 0 3 22 648 30
5 0 1 0 38 729


lavaan estimates the correlation to be 0.990, while Mplus gives 0.929.
(Psych:::polychoric gives 0.9715).

lavaan and Mplus often give different results if some polychoric
correlations are very high (say > 0.95). The Mplus correlations always
seem to be lower (in absolute value) in these cases.

Yves.
> --
> You received this message because you are subscribed to the Google
> Groups "lavaan" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to lavaan+un...@googlegroups.com
> <mailto:lavaan+un...@googlegroups.com>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/lavaan/0b083609-55be-4fd4-944f-b18dd1984e3fn%40googlegroups.com <https://groups.google.com/d/msgid/lavaan/0b083609-55be-4fd4-944f-b18dd1984e3fn%40googlegroups.com?utm_medium=email&utm_source=footer>.

Hao

unread,
Jul 20, 2023, 11:22:52 PM7/20/23
to lavaan
Hi Yves, 

It's a little bit strange. I ran 100 simulated datasets. Mplus, lavaan, and psych::polychoric all produced identical results. 
But why does the above dataset give different estimation results?   The following is my code. 
 
Hao
# Load necessary packages
library(MplusAutomation)
library(mvtnorm)
library(lavaan)

generate_mplus_model <- function(sampleSize, cor, thresh1, thresh2, seed = 1) {
 
  set.seed(seed)
 
  corMat <- matrix(c(1, cor, cor, 1), 2, 2)
  Data <- as.data.frame(rmvnorm(sampleSize, sigma = corMat))
 
  Data[, 1] <- as.numeric(cut(Data[, 1], breaks = c(-Inf, thresh1, Inf)))
  Data[, 2] <- as.numeric(cut(Data[, 2], breaks = c(-Inf, thresh2, Inf)))
 
  mod <- mplusObject(TITLE = "Poly;",
                     VARIABLE ="categorical are all;",
                     ANALYSIS = "ESTIMATOR IS WLSMV;",
                     OUTPUT = "sampstat; standardized;",
                     usevariables = colnames(Data),
                     rdata = Data)
 
  m_basic_fit <- mplusModeler(mod,
                              dataout = paste0("dataset_", seed, ".dat"),
                              modelout = paste0("model_", seed, "_basic_Lab1.inp"),
                              check = TRUE,
                              run = TRUE,
                              hashfilename = F)
 
  # Extract model summary
  summary <- get_sampstat(m_basic_fit)
 
  # Calculate lavCor correlation matrix
  lavCor_mat <- lavCor(Data, order = T)
  psych_mat <- psych::polychoric(Data)$rho
 
  # Return model fit, sample statistics, and lavCor correlation matrix
  return(data.frame( "mplus_poly" = summary$correlations.vardiag[2, 1],
                     "lav_poly" = round(lavCor_mat[2, 1], 3),
                     "psych_poly" = round(psych_mat[2, 1], 3))
         )
}



# Generate 100 datasets and run Mplus models
results <- list()
for(i in 1:100) {
  results[[i]] <- generate_mplus_model(
    sampleSize = 1794,
    cor = 0.97,
    thresh1 = c(-2.285 , -1.818, -0.930,  0.194),
    thresh2 = c(-2.267, -1.949 , -0.988 , 0.163),
    seed = i
  )
}

results <- results %>%
  bind_rows() 
Reply all
Reply to author
Forward
0 new messages