Open dnzmarcio opened 9 months ago
Hello,
Following the guidelines from the maintainers of R-package broom that strongly encourages to ask the maintainers of the model-parent package to implement new tidy methods for maintainability purposes, I implemented a tidy method for pim objects:
broom
tidy
pim
library(pim) data('FEVData') mod <- pim(FEV~ Smoke*Sex , data=FEVData) tidy(mod) # # A tibble: 3 × 5 # term estimate std.error statistic p.value # <chr> <dbl> <dbl> <dbl> <dbl> # 1 Smoke 1.01 0.137 7.40 1.40e-13 # 2 Sex 0.371 0.0975 3.80 1.44e- 4 # 3 Smoke:Sex 0.442 0.359 1.23 2.17e- 1
One of the main advantages of having a tidy method for pim objects is that multiple imputation can be performed using the R-package mice:
mice
library(mice) library(pim) data('FEVData') FEV_missing <- FEVData FEV_missing$Sex[sample(1:nrow(FEV_missing), 20)] <- NA FEV_missing$Smoke[sample(1:nrow(FEV_missing), 10)] <- NA FEV_imputed <- FEV_missing |> select(FEV, Smoke, Sex, Age, Height) |> droplevels() |> mice(m=5,maxit=50,meth='pmm',seed=500) fit <- with(FEV_imputed, pim(FEV~ Smoke*Sex)) summary(pool(fit)) # term estimate std.error statistic df p.value #1 Smoke 1.0359524 0.1403922 7.3789899 4471.828 1.891286e-13 #2 Sex 0.3587343 0.0985377 3.6405794 8706.559 2.736026e-04 #3 Smoke:Sex 0.3558264 0.3600426 0.9882898 1027.060 3.232435e-01
─ Session info ────────────────────────────────────────────────── setting value version R version 4.3.0 (2023-04-21 ucrt) os Windows 10 x64 (build 19044) system x86_64, mingw32 ui RStudio language (EN) collate English_United States.utf8 ctype English_United States.utf8 tz America/New_York date 2023-11-21 rstudio 2023.06.1+524 Mountain Hydrangea (desktop) pandoc NA ─ Packages ────────────────────────────────────────────────────── ! package * version date (UTC) lib source backports 1.4.1 2021-12-13 [1] CRAN (R 4.3.0) BB 2019.10-1 2019-10-18 [1] CRAN (R 4.3.0) boot 1.3-28.1 2022-11-22 [1] CRAN (R 4.3.0) brio 1.1.3 2021-11-30 [1] CRAN (R 4.3.0) broom 1.0.5.9000 2023-11-04 [1] local cachem 1.0.8 2023-05-01 [1] CRAN (R 4.3.0) callr 3.7.3 2022-11-02 [1] CRAN (R 4.3.0) cli 3.6.1 2023-03-23 [1] CRAN (R 4.3.0) codetools 0.2-19 2023-02-01 [1] CRAN (R 4.3.0) colorspace 2.1-0 2023-01-23 [1] CRAN (R 4.3.0) crayon 1.5.2 2022-09-29 [1] CRAN (R 4.3.0) desc 1.4.2 2022-09-08 [1] CRAN (R 4.3.0) devtools 2.4.5 2022-10-11 [1] CRAN (R 4.3.0) digest 0.6.31 2022-12-11 [1] CRAN (R 4.3.0) dplyr * 1.1.2 2023-04-20 [1] CRAN (R 4.3.0) ellipsis 0.3.2 2021-04-29 [1] CRAN (R 4.3.0) fansi 1.0.4 2023-01-22 [1] CRAN (R 4.3.0) fastmap 1.1.1 2023-02-24 [1] CRAN (R 4.3.0) foreach 1.5.2 2022-02-02 [1] CRAN (R 4.3.0) fs 1.6.2 2023-04-25 [1] CRAN (R 4.3.0) generics 0.1.3 2022-07-05 [1] CRAN (R 4.3.0) ggplot2 * 3.4.2 2023-04-03 [1] CRAN (R 4.3.0) glmnet 4.1-7 2023-03-23 [1] CRAN (R 4.3.1) glue 1.6.2 2022-02-24 [1] CRAN (R 4.3.0) gtable 0.3.3 2023-03-21 [1] CRAN (R 4.3.0) htmltools 0.5.5 2023-03-23 [1] CRAN (R 4.3.0) htmlwidgets 1.6.2 2023-03-17 [1] CRAN (R 4.3.0) httpuv 1.6.11 2023-05-11 [1] CRAN (R 4.3.0) iterators 1.0.14 2022-02-05 [1] CRAN (R 4.3.0) jomo 2.7-6 2023-04-15 [1] CRAN (R 4.3.1) knitr 1.43 2023-05-25 [1] CRAN (R 4.3.1) later 1.3.1 2023-05-02 [1] CRAN (R 4.3.0) lattice 0.21-8 2023-04-05 [1] CRAN (R 4.3.0) lifecycle 1.0.3 2022-10-07 [1] CRAN (R 4.3.0) lme4 1.1-33 2023-04-25 [1] CRAN (R 4.3.0) magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.3.0) MASS 7.3-60 2023-05-04 [1] CRAN (R 4.3.1) Matrix 1.5-4.1 2023-05-18 [1] CRAN (R 4.3.1) memoise 2.0.1 2021-11-26 [1] CRAN (R 4.3.0) mice * 3.16.0 2023-06-05 [1] CRAN (R 4.3.1) mime 0.12 2021-09-28 [1] CRAN (R 4.3.0) miniUI 0.1.1.1 2018-05-18 [1] CRAN (R 4.3.0) minqa 1.2.5 2022-10-19 [1] CRAN (R 4.3.0) mitml 0.4-5 2023-03-08 [1] CRAN (R 4.3.1) munsell 0.5.0 2018-06-12 [1] CRAN (R 4.3.0) nleqslv 3.3.4 2023-01-14 [1] CRAN (R 4.3.0) nlme 3.1-162 2023-01-31 [1] CRAN (R 4.3.0) nloptr 2.0.3 2022-05-26 [1] CRAN (R 4.3.0) nnet 7.3-19 2023-05-03 [1] CRAN (R 4.3.1) pan 1.6 2018-06-29 [1] CRAN (R 4.3.1) pillar 1.9.0 2023-03-22 [1] CRAN (R 4.3.0) P pim * 2.0.2 2020-02-03 [?] CRAN (R 4.3.0) pkgbuild 1.4.1 2023-06-14 [1] CRAN (R 4.3.1) pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.3.0) pkgload 1.3.2 2022-11-16 [1] CRAN (R 4.3.0) prettyunits 1.1.1 2020-01-24 [1] CRAN (R 4.3.0) processx 3.8.1 2023-04-18 [1] CRAN (R 4.3.0) profvis 0.3.8 2023-05-02 [1] CRAN (R 4.3.0) promises 1.2.0.1 2021-02-11 [1] CRAN (R 4.3.0) ps 1.7.5 2023-04-18 [1] CRAN (R 4.3.0) purrr 1.0.1 2023-01-10 [1] CRAN (R 4.3.0) quadprog 1.5-8 2019-11-20 [1] CRAN (R 4.3.0) R6 2.5.1 2021-08-19 [1] CRAN (R 4.3.0) Rcpp 1.0.10 2023-01-22 [1] CRAN (R 4.3.0) remotes 2.4.2.1 2023-07-18 [1] CRAN (R 4.3.0) rlang 1.1.1 2023-04-28 [1] CRAN (R 4.3.0) roxygen2 7.2.3 2022-12-08 [1] CRAN (R 4.3.0) rpart 4.1.19 2022-10-21 [1] CRAN (R 4.3.0) rprojroot 2.0.3 2022-04-02 [1] CRAN (R 4.3.0) rstudioapi 0.14 2022-08-22 [1] CRAN (R 4.3.0) scales 1.2.1 2022-08-20 [1] CRAN (R 4.3.0) sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.3.0) shape 1.4.6 2021-05-19 [1] CRAN (R 4.3.0) shiny 1.7.4 2022-12-15 [1] CRAN (R 4.3.0) stringi 1.7.12 2023-01-11 [1] CRAN (R 4.3.0) stringr 1.5.0 2022-12-02 [1] CRAN (R 4.3.0) survival 3.5-5 2023-03-12 [1] CRAN (R 4.3.0) testthat * 3.1.9 2023-06-15 [1] CRAN (R 4.3.1) tibble 3.2.1 2023-03-20 [1] CRAN (R 4.3.0) tidyr 1.3.0 2023-01-24 [1] CRAN (R 4.3.0) tidyselect 1.2.0 2022-10-10 [1] CRAN (R 4.3.0) urlchecker 1.0.1 2021-11-30 [1] CRAN (R 4.3.0) usethis 2.2.1 2023-06-23 [1] CRAN (R 4.3.0) utf8 1.2.3 2023-01-31 [1] CRAN (R 4.3.0) vctrs 0.6.3 2023-06-14 [1] CRAN (R 4.3.1) withr 2.5.0 2022-03-03 [1] CRAN (R 4.3.0) xfun 0.39 2023-04-20 [1] CRAN (R 4.3.0) xml2 1.3.4 2023-04-27 [1] CRAN (R 4.3.0) xtable 1.8-4 2019-04-21 [1] CRAN (R 4.3.0) [1] C:/Program Files/R/R-4.3.0/library
Hello,
Following the guidelines from the maintainers of R-package
broom
that strongly encourages to ask the maintainers of the model-parent package to implement newtidy
methods for maintainability purposes, I implemented atidy
method forpim
objects:One of the main advantages of having a
tidy
method forpim
objects is that multiple imputation can be performed using the R-packagemice
: