Differences in df Between R (lavaan) and Mplus

70 views
Skip to first unread message

Serena

unread,
May 29, 2025, 4:06:33 AM5/29/25
to lavaan

Hi all,

I'm running a two-level SEM model in both R (lavaan) and Mplus and noticed some differences in the number of estimated parameters and degrees of freedom (df). I’d appreciate any insights on this.

R code
mod <-"
  level:1
  lris1W =~ dr_t1 + ss_t1 + pt_t1 + fb_t1 + gi_t1
  lris2W =~ dr_t2 + ss_t2 + pt_t2 + fb_t2 + gi_t2
  ae2W   =~ ae8 + ae12 + ae16 + ae20

  ae2W + lris2W ~ lris1W

  # covariates
  age  =~ 1*Age
  Age.x ~~ 0*Age

  gndr =~ 1*Gender
  Gender.x ~~ 0*Gender

  ae2W + 
lris2W ~ age + gndr

  level:2
  lris1B =~ dr_t1 + ss_t1 + pt_t1 + fb_t1 + gi_t1
  lris2B =~ dr_t2 + ss_t2 + pt_t2 + fb_t2 + gi_t2
  ae2B   =~ ae8 + ae12 + ae16 + ae20

  ae2B + lris2B ~ lris1B
"
fit <- sem(mod, dataset, estimator = "MLR", cluster = "id", meanstructure = TRUE)
summary(fit, fit.measures = TRUE, standardized = TRUE, ci = TRUE)

Mplus code
CLUSTER IS id;
MODEL:
    %WITHIN%
    lris1W BY dr_t1 ss_t1 pt_t1 fb_t1 gi_t1;
    lris2W BY dr_t2 ss_t2 pt_t2 fb_t2 gi_t2;
    ae2W  BY ae8 ae12 ae16 ae20;

    ae2W lris2W ON lris1W;

    ! covariates
    age  BY Age@1;
    Age@0;

    gndr BY Gender@1;
    Gender@0;

    lris2W ae2W ON age gndr;

    %BETWEEN%
    lris1B BY dr_t1 ss_t1 pt_t1 fb_t1 gi_t1;
    lris2B BY dr_t2 ss_t2 pt_t2 fb_t2 gi_t2;
    ae2B  BY ae8 ae12 ae16 ae20;

    ae2B lris2B ON lris1B;

ANALYSIS:
    TYPE = TWOLEVEL;
    ESTIMATOR = MLR;


Output Comparison:

  • R (lavaan):

    • Parameters estimated: 87

    • Degrees of freedom: 170

  • Mplus:

    • Parameters estimated: 89

    • Degrees of freedom: 199


I reviewed the parameter listings and identified that Mplus includes 2 additional parameters—specifically, it appears to estimate a covariance between the two covariates (age and gender), which lavaan does not unless explicitly specified.

What’s puzzling to me is the larger difference in degrees of freedom (199 vs 170), even though the parameter count only differs by two. I'm wondering if this is due to how each software handles multilevel data structures.

Any thoughts on this discrepancy or suggestions on what else I should be checking?

Thanks for your attention.

Best,
Serena

Edward Rigdon

unread,
May 29, 2025, 4:34:16 AM5/29/25
to lav...@googlegroups.com
(Quickly) Are observed means and mean structure parameters counted the same? A difference would not surprise me.
(In transit)

--
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.
To view this discussion visit https://groups.google.com/d/msgid/lavaan/147e8d10-bf98-4468-8ff9-22bf2647a173n%40googlegroups.com.

Serena

unread,
May 29, 2025, 9:36:03 AM5/29/25
to lavaan
Hi Edward,

Thanks for your message — good point!

I’ve checked the observed and latent means in both lavaan and Mplus.

In lavaan:
    Within level: Only the means of the covariates (age and gender) are estimated; all other observed items have fixed means (0).
    Between level: The means of the 14 observed items (5 + 5 + 4) are estimated.
    Latent means: All fixed at 0.

In Mplus:
    Within level: All observed means are fixed at 0 (including age and gender).
    Between level: The means of age, gender, and the 14 observed items are estimated.
    Latent means: All fixed at 0.

Please let me know if I’m missing anything or if you have any thoughts on this.

Best,
Serena
Reply all
Reply to author
Forward
0 new messages