tidymodels / broom

Convert statistical analysis objects from R into tidy format
https://broom.tidymodels.org
Other
1.46k stars 304 forks source link

tidy for summary() from package 'mediation' #275

Closed douglas24 closed 5 years ago

douglas24 commented 6 years ago

Please add this? broom/tidy doesn't seem to work already with the summary() for the 'mediation' package in R

IndrajeetPatil commented 5 years ago

This is already supported in 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.4.6
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)
#> # A tibble: 4 x 4
#>   term   estimate std.error p.value
#>   <chr>     <dbl>     <dbl>   <dbl>
#> 1 acme_0  -0.0131   0.00943    0.12
#> 2 acme_1  -0.0131   0.00943    0.12
#> 3 ade_0   -0.0444   0.0397     0.36
#> 4 ade_1   -0.0444   0.0397     0.36
tidy(summary(mod))
#> # A tibble: 4 x 4
#>   term   estimate std.error p.value
#>   <chr>     <dbl>     <dbl>   <dbl>
#> 1 acme_0  -0.0131   0.00943    0.12
#> 2 acme_1  -0.0131   0.00943    0.12
#> 3 ade_0   -0.0444   0.0397     0.36
#> 4 ade_1   -0.0444   0.0397     0.36

Created on 2019-03-10 by the reprex package (v0.2.1.9000)

Session info ``` r devtools::session_info() #> - Session info ---------------------------------------------------------- #> setting value #> version R Under development (unstable) (2019-03-02 r76189) #> os Windows 10 x64 #> system x86_64, mingw32 #> ui RTerm #> language (EN) #> collate English_United States.1252 #> ctype English_United States.1252 #> tz America/Chicago #> date 2019-03-10 #> #> - Packages -------------------------------------------------------------- #> package * version date lib #> acepack 1.4.1 2016-10-29 [1] #> assertthat 0.2.0 2017-04-11 [1] #> backports 1.1.3 2018-12-14 [1] #> base64enc 0.1-3 2015-07-28 [1] #> boot 1.3-21 2019-03-01 [2] #> broom * 0.5.1.9000 2019-03-10 [1] #> callr 3.1.1 2018-12-21 [1] #> checkmate 1.9.1 2019-01-15 [1] #> cli 1.0.1.9000 2019-01-20 [1] #> cluster 2.0.7-1 2018-04-13 [2] #> colorspace 1.4-0 2019-01-13 [1] #> crayon 1.3.4 2017-09-16 [1] #> data.table 1.12.0 2019-01-13 [1] #> desc 1.2.0 2019-01-21 [1] #> devtools 2.0.1.9000 2019-02-18 [1] #> digest 0.6.18 2018-10-10 [1] #> dplyr 0.8.0.9006 2019-03-07 [1] #> evaluate 0.13 2019-02-12 [1] #> fansi 0.4.0 2018-11-05 [1] #> foreign 0.8-71 2018-07-20 [2] #> Formula 1.2-3 2018-05-03 [1] #> fs 1.2.6 2018-08-23 [1] #> generics 0.0.2 2019-03-05 [1] #> ggplot2 3.1.0.9000 2019-03-06 [1] #> glue 1.3.0 2018-07-17 [1] #> gridExtra 2.3 2017-09-09 [1] #> gtable 0.2.0 2016-02-26 [1] #> highr 0.7 2018-06-09 [1] #> Hmisc 4.2-0 2019-01-26 [1] #> htmlTable 1.13.1 2019-01-07 [1] #> htmltools 0.3.6 2017-04-28 [1] #> htmlwidgets 1.3 2018-09-30 [1] #> knitr 1.22 2019-03-08 [1] #> lattice 0.20-38 2018-11-04 [2] #> latticeExtra 0.6-28 2016-02-09 [1] #> lazyeval 0.2.1 2017-10-29 [1] #> lme4 1.1-21 2019-03-05 [1] #> lpSolve 5.6.13 2015-09-19 [1] #> magrittr 1.5 2014-11-22 [1] #> MASS * 7.3-51.2 2019-03-01 [2] #> Matrix * 1.2-16 2019-03-08 [1] #> mediation * 4.4.6 2017-07-11 [1] #> memoise 1.1.0 2017-04-21 [1] #> minqa 1.2.4 2014-10-09 [1] #> munsell 0.5.0 2018-06-12 [1] #> mvtnorm * 1.0-10 2019-03-05 [1] #> nlme 3.1-137 2018-04-07 [2] #> nloptr 1.2.1 2018-10-03 [1] #> nnet 7.3-12 2016-02-02 [2] #> pillar 1.3.1 2018-12-15 [1] #> pkgbuild 1.0.2 2018-10-16 [1] #> pkgconfig 2.0.2 2018-08-16 [1] #> pkgload 1.0.2 2018-10-29 [1] #> prettyunits 1.0.2 2015-07-13 [1] #> processx 3.2.1 2018-12-05 [1] #> ps 1.3.0 2018-12-21 [1] #> purrr 0.3.1 2019-03-03 [1] #> R6 2.4.0 2019-02-14 [1] #> RColorBrewer 1.1-2 2014-12-07 [1] #> Rcpp 1.0.0 2018-11-07 [1] #> remotes 2.0.2 2018-10-30 [1] #> rlang 0.3.1 2019-01-08 [1] #> rmarkdown 1.11.6 2019-02-14 [1] #> rpart 4.1-13 2018-02-23 [2] #> rprojroot 1.3-2 2018-01-03 [1] #> rstudioapi 0.9.0 2019-01-09 [1] #> sandwich * 2.5-0 2018-08-17 [1] #> scales 1.0.0 2018-08-09 [1] #> sessioninfo 1.1.1 2018-11-05 [1] #> stringi 1.3.1 2019-02-13 [1] #> stringr 1.4.0 2019-02-10 [1] #> survival 2.43-3 2018-11-26 [2] #> testthat 2.0.1 2018-10-13 [1] #> tibble 2.0.1.9001 2019-03-07 [1] #> tidyr 0.8.3.9000 2019-03-07 [1] #> tidyselect 0.2.5 2018-10-11 [1] #> usethis 1.4.0.9000 2019-02-18 [1] #> utf8 1.1.4 2018-05-24 [1] #> vctrs 0.1.0.9002 2019-03-07 [1] #> withr 2.1.2 2018-03-15 [1] #> xfun 0.5 2019-02-20 [1] #> yaml 2.2.0 2018-07-25 [1] #> zeallot 0.1.0 2018-01-28 [1] #> zoo 1.8-4 2018-09-19 [1] #> source #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.0) #> CRAN (R 3.6.0) #> local #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> Github (r-lib/cli@94e2fc5) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> Github (r-lib/desc@42b9578) #> Github (r-lib/devtools@188a613) #> CRAN (R 3.5.1) #> Github (tidyverse/dplyr@2ef1fd9) #> CRAN (R 3.6.0) #> Github (brodieG/fansi@ab11e9c) #> CRAN (R 3.6.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> Github (r-lib/generics@c15ac43) #> Github (tidyverse/ggplot2@1c88edd) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.0) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.2) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> Github (rstudio/rmarkdown@bbd0786) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> Github (tidyverse/tibble@5fc065b) #> Github (tidyverse/tidyr@7a51bfd) #> CRAN (R 3.5.1) #> Github (r-lib/usethis@ed9ae17) #> CRAN (R 3.5.1) #> Github (r-lib/vctrs@6b8c98a) #> CRAN (R 3.5.1) #> CRAN (R 3.6.0) #> CRAN (R 3.5.1) #> CRAN (R 3.5.1) #> CRAN (R 3.5.2) #> #> [1] C:/Users/inp099/Documents/R/win-library/3.6 #> [2] C:/Program Files/R/R-devel/library ```
alexpghayes commented 5 years ago

We have this! It isn't super clear but that's another issue

github-actions[bot] commented 3 years ago

This issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with a reprex: https://reprex.tidyverse.org) and link to this issue.