binary outcome in mediation

1,225 views
Skip to first unread message

NewInMediation

unread,
Aug 30, 2017, 12:03:40 PM8/30/17
to lavaan
Hi all,

I am using binary outcome measures with continuous predictors and mediators. I tried http://lavaan.ugent.be/tutorial/cat.html says by declaring the binary outcome as "ordered" and using "ordered" argument. But I am getting different error messages.

The method from http://lavaan.ugent.be/tutorial/cat.html did not work for me to declare them as "ordered":

m[,"myOutcome"] <-
    lapply(m[,"myOutcome"],ordered)

Here is how I ordered the outcome (0 was for not having the outcome and 1 was for having the outcome):

m$myOutcome<-ordered(m$myOutcome,
                                                             levels=0:1, 
                                                             labels=c("noOutcome","Outcome"))

Here is my model: 

p16a18c24 <- ' # direct effect
myOutcome ~ c*myPredictor
# mediator
myMediator ~ a*myPredictor
myOutcome ~ b*myMediator
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
'

fit.p16a18c24 <- sem(p16a18c24,data=m,missing="fiml",se="bootstrap",ordered="MyOutcome")
Error in lav_options_set(opt) : use (D)WLS estimator for bootstrap

Hence I tried without bootstrap: 

fit.p16a18c24 <- sem(p16a18c24,data=m,missing="fiml",ordered="myOutcome")
Error in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing,  : 
  lavaan ERROR: multilevel + conditional.x not supported yet
In addition: Warning message:
In lav_options_set(opt) :
  lavaan WARNING: information will be set to “expected” for se = “robust.sem”

fit.p16a18c24 <- sem(p16a18c24,data=m,missing="fiml")
Error in lav_samplestats_from_data(lavdata = lavdata, missing = lavoptions$missing,  : 
  lavaan ERROR: multilevel + conditional.x not supported yet
In addition: Warning message:
In lav_options_set(opt) :
  lavaan WARNING: information will be set to “expected” for se = “robust.sem”

Do these error messages mean that lavaan does not support binary outcomes? If not, how can I get results with the binary outcome measures?

I would really appreciate your answer.

NewInMediation


NewInMediation

unread,
Aug 30, 2017, 12:52:55 PM8/30/17
to lavaan
Thanks Yves, now it seems to work. I really appreciate your quick reply.

Can we not use bootstrap with binary outcomes?

fit.p16a18c24 <- sem(p16a18c24,data=m,missing="fiml",se="bootstrap",ordered="MyOutcome")
Error in lav_options_set(opt) : use (D)WLS estimator for bootstrap

fit.p16a18c24 <- sem(p16a18c24,data=m,missing="fiml",ordered="MyOutcome")
This line worked.

summary(fit.p16a18c24,fit.measures=TRUE,standardized=TRUE,rsquare=TRUE)
boot.fit<-parameterEstimates(fit.p16a18c24,boot.ci.type="bca.simple",level=0.95,ci=TRUE,standardized=FALSE)
boot.fit

These lines gave me confidence intervals, but I imagine they are not from bootstrap. How I can get bootstrap results with binary outcomes? I would really appreciate your answer.

Thanks in advance,
NewInMediation


On Wed, Aug 30, 2017 at 9:25 AM, Yves Rosseel
 wrote:
remove the missing="fiml" argument, as it is not supported with categorical data (which uses WLSMV as default)

(I will fix the faulty error message)

Yves.

Yves Rosseel

unread,
Aug 30, 2017, 2:19:20 PM8/30/17
to lav...@googlegroups.com
On 08/30/2017 06:03 PM, NewInMediation wrote:
> fit.p16a18c24 <- sem(p16a18c24,data=m,missing="fiml",ordered="myOutcome")
> Error in lav_samplestats_from_data(lavdata = lavdata, missing =
> lavoptions$missing, :
> lavaan ERROR: multilevel + conditional.x not supported yet

the error message should read:

lavaan ERROR: missing = "ml" + conditional.x not supported yet

(fixed in 0.6)

Yves.

Yves Rosseel

unread,
Aug 30, 2017, 2:41:05 PM8/30/17
to lav...@googlegroups.com
On 08/30/2017 06:52 PM, NewInMediation wrote:
> Thanks Yves, now it seems to work. I really appreciate your quick reply.
>
> Can we not use bootstrap with binary outcomes?

Yes, you can.

> fit.p16a18c24 <-
> sem(p16a18c24,data=m,missing="fiml",se="bootstrap",ordered="MyOutcome")
> Error in lav_options_set(opt) : use (D)WLS estimator for bootstrap

(note, "MyOutcome" should be "myOutcome")

When at least one observed variable is categorical, the default
estimator is WLSMV, which implied estimator = "DWLS", se = "robust", and
test = "scaled.shifted".

So to use the bootstrap, you need to specify the estimator as "DWLS":

fit.p16a18c24 <- sem(p16a18c24, data = m, se = "bootstrap", ordered =
"myOutcome", estimator = "DWLS", verbose = TRUE)

Yves.

NewInMediation

unread,
Aug 30, 2017, 2:52:25 PM8/30/17
to lavaan
Thank you so much Yves for your quick reply and clarification, what a lifesaver!

I get the part about DWLS for categorical data, but I am a bit confused about missing="fiml" argument. Is missingness considered in lavaan for binary outcomes without using an argument for 'missing'? How can we use bootstrap and deal with missingness in lavaan at the same time? 

(I am sorry this question sounds stupid, I googled to find it out, but I could not...) I would really appreciate some clarification.

Thanks in advance,
NewInMediation

NewInMediation

unread,
Aug 31, 2017, 12:00:57 PM8/31/17
to lavaan
Hi Yves (or anyone who knows),

Is lavaan set to use listwise deletion for binary outcome (estimator = "DWLS")? I see only 210 participants were used out of 320. 

When I allow paramters to be different by gender, DF became -2 ( 3) below). Chisq different test ( 4) below) did not show me results. I suspect it's about fewer number of subjects. It didn't happen when I used FIML. 

Is there any way to use FIML for binary outcomes in lavaan?

Here is my model: 

1)

p16a18c24 <- ' # direct effect
myOutcome ~ c*myPredictor
# mediator
myMediator ~ a*myPredictor
myOutcome ~ b*myMediator
# indirect effect (a*b)
ab := a*b
# total effect
total := c + (a*b)
'
fit.p16a18c24 <- sem(p16a18c24, data = m, se = "bootstrap", ordered = 
"myOutcome", estimator = "DWLS", verbose = TRUE) 
summary(fit.p16a18c24,fit.measures=TRUE,standardized=TRUE,rsquare=TRUE)

lavaan (0.5-23.1097) converged normally after  24 iterations

                                                  Used       Total
  Number of observations                           210         320

  Estimator                                       DWLS
  Minimum Function Test Statistic                0.000
  Degrees of freedom                                 0
  Minimum Function Value               0.0000000000000

Model test baseline model:

  Minimum Function Test Statistic               25.446
  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

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:

  SRMR                                           0.000

Weighted Root Mean Square Residual:

  WRMR                                           0.000

Parameter Estimates:

  Information                                 Observed
  Standard Errors                            Bootstrap
  Number of requested bootstrap draws             1000
  Number of successful bootstrap draws            1000


2) add group="Gender", force parameters to be the same between gender:

lavaan (0.5-23.1097) converged normally after  33 iterations

                                                  Used       Total
  Number of observations per group         
  Female                                           125         193
  Male                                              85         127

  Estimator                                       DWLS
  Minimum Function Test Statistic                4.772
  Degrees of freedom                                 4
  P-value (Chi-square)                           0.311

Chi-square for each group:

  Female                                         1.330
  Male                                           3.442

Model test baseline model:

  Minimum Function Test Statistic               24.908
  Degrees of freedom                                 6
  P-value                                        0.000

User model versus baseline model:

  Comparative Fit Index (CFI)                    0.959
  Tucker-Lewis Index (TLI)                       0.939

Root Mean Square Error of Approximation:

  RMSEA                                          0.043
  90 Percent Confidence Interval          0.000  0.160
  P-value RMSEA <= 0.05                          0.440

Standardized Root Mean Square Residual:

  SRMR                                           0.045

Weighted Root Mean Square Residual:

  WRMR                                           0.892

Parameter Estimates:

  Information                                 Observed
  Standard Errors                            Bootstrap
  Number of requested bootstrap draws             1000
  Number of successful bootstrap draws            1000


3) allow parameters to be different between gender: 

                                                  Used       Total
  Number of observations per group         
  Female                                           125         193
  Male                                              85         127

  Estimator                                       DWLS
  Minimum Function Test Statistic                   NA
  Degrees of freedom                                -2
  Minimum Function Value               0.0000000000000

Chi-square for each group:

  Female                                            NA
  Male                                              NA

User model versus baseline model:

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

Root Mean Square Error of Approximation:

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

Standardized Root Mean Square Residual:

  SRMR                                           0.000

Weighted Root Mean Square Residual:

  WRMR                                              NA

Parameter Estimates:

  Information                                 Observed
  Standard Errors                            Bootstrap
  Number of requested bootstrap draws             1000
  Number of successful bootstrap draws            1000


4) check if the two models are different
> anova(fit.p16a18c24,fit.p16a18c24.d)
Chi Square Difference Test

                Df AIC BIC  Chisq Chisq diff Df diff Pr(>Chisq)
fit.p16a18c24.d -2                                             
fit.p16a18c24    4         4.7721                  6

Thanks in advance,
NewInMediation

Terrence Jorgensen

unread,
Sep 2, 2017, 7:30:44 AM9/2/17
to lavaan
Is there any way to use FIML for binary outcomes in lavaan?

No, FIML means ML estimation, which is only available for continuous outcomes. 

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

NewInMediation

unread,
Sep 2, 2017, 11:15:15 AM9/2/17
to lavaan
Thank you for your reply Terrence,

Then in lavaan, how is missingness dealt with for binary outcomes (estimator = "DWLS")? Is there an argument I should use for missing data?

Thanks in advance,
NewInMediation

Yves Rosseel

unread,
Sep 2, 2017, 11:36:27 AM9/2/17
to lav...@googlegroups.com
missing = "pairwise"
> <http://www.uva.nl/profile/t.d.jorgensen>
>
> --
> 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 post to this group, send email to lav...@googlegroups.com
> <mailto:lav...@googlegroups.com>.
> Visit this group at https://groups.google.com/group/lavaan.
> For more options, visit https://groups.google.com/d/optout.

NewInMediation

unread,
Sep 2, 2017, 12:35:32 PM9/2/17
to lavaan
Thank you so much for your answer Yves! I really appreciate it.
Reply all
Reply to author
Forward
0 new messages