Tidying an object of class mediate

Hi! I have been trying to run the tidy() function on a mediate object and I get the following error:

 Error: No tidy method for objects of class mediate

Here is a minimal example:

library(broom)
library(mediation)
#> Loading required package: MASS
#> Loading required package: Matrix
#> Loading required package: mvtnorm
#> Loading required package: sandwich
#> mediation: Causal Mediation Analysis
#> Version: 4.5.0

model_med <- lm(vs ~ wt, data = mtcars)
model_out <- lm(am ~ wt*vs, data = mtcars)
mediation <- mediate(model_med, model_out, sims = 1000, treat = "wt", mediator = "vs", treat.value = 2.5, control.value = 3.5)

tidy(mediation)
#> Error: No tidy method for objects of class mediate

I can't seem to find any information on this error. I thought mediate objects could be passed to the tidy function. Does anyone have any clue why this is happening? Thanks!

This reprex shows a little more of what's going on.

library(broom)
library(mediation)
#> Loading required package: MASS
#> Loading required package: Matrix
#> Loading required package: mvtnorm
#> Loading required package: sandwich
#> mediation: Causal Mediation Analysis
#> Version: 4.5.0
model_med <- lm(vs ~ wt, data = mtcars)
model_out <- lm(am ~ wt*vs, data = mtcars)
mediation <- mediate(model_med, model_out, sims = 1000, treat = "wt", mediator = "vs", treat.value = 2.5, control.value = 3.5)

tidy(mediation)
#> Error: No tidy method for objects of class mediate
class(mediation)
#> [1] "mediate"

Created on 2020-04-09 by the reprex package (v0.3.0)

The error message indeed correctly identified mediation as an object of class mediate and class(mediate) confirms it.

The next step is to look at help(tidy), trace back to the index and see the raft of tidy.X method, where X deals with different types of objects, such as tidy.lm, tidy.glm, etc. Without a thorough search I can't confirm that none of these can take an argument of class mediate but it sure looks that way, simply from the class names.

argument_glossary() %>% print(n = Inf)

doesn't seem to offer anything likely.

Thank you for your input. I am confused because tidy.mediate seems to exist, at least according to this documentation: https://broom.tidyverse.org/reference/tidy.mediate.html

Is there a way to check if it has been deprecated?

1 Like

Good sleuthing. I didn't dig that deep. The last release did have some hard deprecations, but none identified as tidy.mediate are mentioned in NEWS

OK, this should be supported

But not for me

library(mediation)
#> Loading required package: MASS
#> Loading required package: Matrix
#> Loading required package: mvtnorm
#> Loading required package: sandwich
#> mediation: Causal Mediation Analysis
#> Version: 4.5.0
library(broom)
data(jobs)

b <- lm(job_seek ~ treat + econ_hard + sex + age, data = jobs)
c <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data = jobs)
mod <- mediate(b, c, sims = 50, treat = "treat", mediator = "job_seek")
tidy(mod)
#> Error: No tidy method for objects of class mediate

Created on 2020-04-09 by the reprex package (v0.3.0)

Under

sessionInfo()
#> R version 3.6.3 (2020-02-29)
#> Platform: x86_64-apple-darwin15.6.0 (64-bit)
#> Running under: macOS Catalina 10.15.3
#> 
#> Matrix products: default
#> BLAS:   /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRblas.0.dylib
#> LAPACK: /Library/Frameworks/R.framework/Versions/3.6/Resources/lib/libRlapack.dylib
#> 
#> locale:
#> [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] compiler_3.6.3  magrittr_1.5    tools_3.6.3     htmltools_0.4.0
#>  [5] yaml_2.2.1      Rcpp_1.0.4      stringi_1.4.6   rmarkdown_2.1  
#>  [9] highr_0.8       knitr_1.28      stringr_1.4.0   xfun_0.12      
#> [13] digest_0.6.25   rlang_0.4.5     evaluate_0.14

Created on 2020-04-09 by the reprex package (v0.3.0)

The only difference is 4.4.6 vs 4.5.0 for me. I don't know if it is due to macOS. Nor does it work in LinuxLand. Do want to post the issue on github

1 Like

We have an answer. tidy.mediate() is only available in the development version of broom.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.