kosukeimai / mediation

R package mediation
58 stars 29 forks source link

Summary with ordinal outcome #45

Closed sngiam88 closed 1 year ago

sngiam88 commented 1 year ago

Hi,

I was wondering if there was a potential bug with how headers are reported out for the summary of a mediation object?

I have a 4-level ordinal outcome (No (1), Mild (2), Moderate (3), Severe (4)) analyzed as a factor, a continuous mediator & a binary treatment.

I ran a glm for my mediator ~ treatment & a polr for my outcome ~ treatment + mediator.

When I run the mediation analysis using the 4-level factor outcome where the levels are coded as text, and run summary(), it reports out this way:

Causal Mediation Analysis

Nonparametric Bootstrap Confidence Intervals with the Percentile Method

            Pr(Y=Mild) Pr(Y=Moderate) Pr(Y=No) Pr(Y=Severe)

ACME (control) -0.01801 0.00874 0.00447 0.00480 2.5% -0.02936 0.00262 0.00134 0.00139 97.5% -0.00561 0.01455 0.00773 0.00842 p-value 0.00200 0.00200 0.00200 0.00200

But when I change my outcome to a 4 level factor outcome where the levels are coded as numbers (1 (No), 2 (Mild), 3 (Moderate), 4 (Severe), it reports out this way:

Causal Mediation Analysis

Nonparametric Bootstrap Confidence Intervals with the Percentile Method

             Pr(Y=1) Pr(Y=2) Pr(Y=3) Pr(Y=4)

ACME (control) -0.01801 0.00874 0.00447 0.00480 2.5% -0.02936 0.00262 0.00134 0.00139 97.5% -0.00561 0.01455 0.00773 0.00842 p-value 0.00200 0.00200 0.00200 0.00200

Is this expected behavior or have I made a mistake?

Thanks!

-Stephanie

kosukeimai commented 1 year ago

For a factor variable, there are "levels". You want to make sure those levels are correctly ordered. It looks like your factor variable is ordering its levels alphabetically...