strengejacke / sjstats

Effect size measures and significance tests
https://strengejacke.github.io/sjstats
189 stars 21 forks source link

mediation() failing on brms object #44

Closed haututu closed 6 years ago

haututu commented 6 years ago

I am trying to use mediation() on the following model;

fit.brms <- brm(bf(descrimFlag ~ maori) +
                  bf(hazardous ~ descrimFlag + maori),
                family = bernoulli(),
                data = dat)

marginal_effects(fit.brms)

mediation(fit.brms, treatment="maoriTRUE", mediator="descrimFlagTRUE")

If I do not include TRUE in the above arguments I would get the following error;

Error in UseMethod("pull") : 
  no applicable method for 'pull' applied to an object of class "NULL"

If I add TRUE then I get;

Error in .subset2(x, i, exact = exact) : 
  attempt to select less than one element in get1index

I used the CRAN version and also the dev version incase there was a difference there, same response.

strengejacke commented 6 years ago

Do you have a reproducible example?

haututu commented 6 years ago

Attached is some synthetic data and reproducible code using brms version 2.5 Im wondering if it is something to do with using boolean variables.

library(tidyverse)
library(brms)
library(sjstats)

dat <- read.csv("syntheticData.txt")

fit.brms <- brm(bf(mediator ~ treatment) +
                  bf(outcome ~ mediator + treatment),
                family = bernoulli(),
                data = dat)

mediator(fit.brms)

syntheticData.txt