Multilevel analysis code

75 views
Skip to first unread message

Daniel Groß

unread,
Jan 13, 2019, 8:41:23 AM1/13/19
to lavaan

Hi,

I would like to do a multilevel analysis (two level) with lavaan. On level 2 I calculate a mediation. The only level 1 variable is UZUF. I would like to know whether my code is correct.


UZUF = Students' satisfaction with the lessons (level 1)

PAallgL = positive affect teacher (level 2)

MHL_12 = activity teacher (level 2)

cd = Students class


model1 <- '
level: 1
UZUF ~~ UZUF

level: 2
PAallgL ~ a*MHL_12
UZUF ~ b*PAallgL + c*MHL_12

indirect := a*b
direct := c
total := c + (a*b)
'


fit
<- sem(model1, data = data1, cluster = "cd")

summary
(fit, standardized=T, fit.measures=T, rsq = T)



Thank you for your help.


Daniel

Jeremy Miles

unread,
Jan 13, 2019, 1:44:11 PM1/13/19
to lav...@googlegroups.com
What happens when you run it?

--
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 post to this group, send email to lav...@googlegroups.com.
Visit this group at https://groups.google.com/group/lavaan.
For more options, visit https://groups.google.com/d/optout.

Daniel Groß

unread,
Jan 13, 2019, 3:40:31 PM1/13/19
to lavaan
> model1 <- '
+     level: 1
+ UZUF ~~ UZUF
+ level: 2
+ PAallgL ~ a*MHL_12
+           UZUF ~ b*PAallgL + c*MHL_12
+
+ indirect := a*b
+ direct := c
+ total := c + (a*b)
+ '

> fit <- sem(model1, data = data1, cluster = "cd")
>
> summary(fit, standardized=T, fit.measures=T, rsq = T)

lavaan 0.6-2 ended normally after 26 iterations

  Optimization method                           NLMINB
  Number of free parameters                          8

  Number of observations                           945
  Number of clusters [cd]                           49

  Estimator                                         ML
  Model Fit Test Statistic                       0.000
  Degrees of freedom                                 0

Model test baseline model:

  Minimum Function Test Statistic               24.255
  Degrees of freedom                                 3
  P-value                                        0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    1.000
  Tucker-Lewis Index (TLI)                       1.000

Loglikelihood and Information Criteria:

  Loglikelihood user model (H0)               -879.156
  Loglikelihood unrestricted model (H1)       -879.156

  Number of free parameters                          8
  Akaike (AIC)                                1774.313
  Bayesian (BIC)                              1813.122
  Sample-size adjusted Bayesian (BIC)         1787.715

Root Mean Square Error of Approximation:

  RMSEA                                          0.000
  90 Percent Confidence Interval          0.000  0.000
  P-value RMSEA <= 0.05                             NA

Standardized Root Mean Square Residual (corr metric):

  SRMR (within covariance matrix)                0.000
  SRMR (between covariance matrix)               0.000

Parameter Estimates:

  Information                                 Observed
  Observed information based on                Hessian
  Standard Errors                             Standard


Level 1 [within]:

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .UZUF              0.000                               0.000    0.000

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .UZUF              0.314    0.015   21.174    0.000    0.314    1.000


Level 2 [cd]:

Regressions:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
  PAallgL ~                                                             
    MHL_12     (a)    0.659    0.157    4.196    0.000    0.659    0.514
  UZUF ~                                                                
    PAallgL    (b)    0.270    0.113    2.394    0.017    0.270    0.393
    MHL_12     (c)    0.082    0.145    0.566    0.571    0.082    0.093

Intercepts:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PAallgL           1.524    0.468    3.257    0.001    1.524    3.313
   .UZUF              1.492    0.408    3.653    0.000    1.492    4.713

Variances:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
   .PAallgL           0.156    0.031    4.950    0.000    0.156    0.736
   .UZUF              0.080    0.020    4.064    0.000    0.080    0.799

R-Square:
                   Estimate
    PAallgL           0.264
    UZUF              0.201

Defined Parameters:
                   Estimate  Std.Err  z-value  P(>|z|)   Std.lv  Std.all
    indirect          0.178    0.086    2.079    0.038    0.178    0.202
    direct            0.082    0.145    0.566    0.571    0.082    0.093
    total             0.260    0.132    1.977    0.048    0.260    0.295

Terrence Jorgensen

unread,
Jan 15, 2019, 7:37:33 AM1/15/19
to lavaan

I would like to know whether my code is correct.


Looks fine to me.

Terrence D. Jorgensen
Assistant Professor, Methods and Statistics
Research Institute for Child Development and Education, the University of Amsterdam

Daniel Groß

unread,
Jan 15, 2019, 8:48:55 AM1/15/19
to lav...@googlegroups.com
Thank you for confirming my results and analysis.

--
You received this message because you are subscribed to a topic in the Google Groups "lavaan" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lavaan/Wmko2wbi7NQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lavaan+un...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages