Skip to content

Add tidy function#22

Open
dnzmarcio wants to merge 3 commits intoCenterForStatistics-UGent:masterfrom
dnzmarcio:master
Open

Add tidy function#22
dnzmarcio wants to merge 3 commits intoCenterForStatistics-UGent:masterfrom
dnzmarcio:master

Conversation

@dnzmarcio
Copy link

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:

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:

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

devtools::session_info()

─ Session info ─────────────────────────────────────────────────────────────────────────────
setting  value
version  R version 4.5.1 (2025-06-13 ucrt)
os       Windows 11 x64 (build 22631)
system   x86_64, mingw32
ui       RStudio
language (EN)
collate  English_United States.utf8
ctype    English_United States.utf8
tz       America/New_York
date     2026-02-06
rstudio  2025.05.1+513 Mariposa Orchid (desktop)
pandoc   NA
quarto   ERROR: Unknown command "TMPDIR=C:/Users/dinizm01/AppData/Local/Temp/Rtmp2dkIWR/file9a2828c03116". Did you mean command "install"? @ C:\\Users\\dinizm01\\AppData\\Local\\Programs\\Quarto\\bin\\quarto.exe

─ Packages ─────────────────────────────────────────────────────────────────────────────────
package     * version   date (UTC) lib source
backports     1.5.0     2024-05-23 [1] CRAN (R 4.5.0)
BB            2019.10-1 2019-10-18 [1] CRAN (R 4.5.1)
boot          1.3-32    2025-08-29 [1] CRAN (R 4.5.1)
broom         1.0.9     2025-07-28 [1] CRAN (R 4.5.1)
cachem        1.1.0     2024-05-16 [1] CRAN (R 4.5.1)
cli           3.6.5     2025-04-23 [1] CRAN (R 4.5.1)
codetools     0.2-20    2024-03-31 [1] CRAN (R 4.5.1)
desc          1.4.3     2023-12-10 [1] CRAN (R 4.5.1)
devtools      2.4.5     2022-10-11 [1] CRAN (R 4.5.1)
digest        0.6.37    2024-08-19 [1] CRAN (R 4.5.1)
dplyr       * 1.1.4     2023-11-17 [1] CRAN (R 4.5.1)
ellipsis      0.3.2     2021-04-29 [1] CRAN (R 4.5.1)
evaluate      1.0.5     2025-08-27 [1] CRAN (R 4.5.1)
fastmap       1.2.0     2024-05-15 [1] CRAN (R 4.5.1)
foreach       1.5.2     2022-02-02 [1] CRAN (R 4.5.1)
fs            1.6.6     2025-04-12 [1] CRAN (R 4.5.1)
generics      0.1.4     2025-05-09 [1] CRAN (R 4.5.1)
glmnet        4.1-10    2025-07-17 [1] CRAN (R 4.5.1)
glue          1.8.0     2024-09-30 [1] CRAN (R 4.5.1)
htmltools     0.5.8.1   2024-04-04 [1] CRAN (R 4.5.1)
htmlwidgets   1.6.4     2023-12-06 [1] CRAN (R 4.5.1)
httpuv        1.6.16    2025-04-16 [1] CRAN (R 4.5.1)
iterators     1.0.14    2022-02-05 [1] CRAN (R 4.5.1)
jomo          2.7-6     2023-04-15 [1] CRAN (R 4.5.1)
knitr         1.50      2025-03-16 [1] CRAN (R 4.5.1)
later         1.4.4     2025-08-27 [1] CRAN (R 4.5.1)
lattice       0.22-7    2025-04-02 [1] CRAN (R 4.5.1)
lifecycle     1.0.4     2023-11-07 [1] CRAN (R 4.5.1)
lme4          1.1-37    2025-03-26 [1] CRAN (R 4.5.2)
magrittr      2.0.3     2022-03-30 [1] CRAN (R 4.5.1)
MASS          7.3-65    2025-02-28 [1] CRAN (R 4.5.1)
Matrix        1.7-4     2025-08-28 [1] CRAN (R 4.5.1)
memoise       2.0.1     2021-11-26 [1] CRAN (R 4.5.1)
mice        * 3.18.0    2025-05-27 [1] CRAN (R 4.5.1)
mime          0.13      2025-03-17 [1] CRAN (R 4.5.0)
miniUI        0.1.2     2025-04-17 [1] CRAN (R 4.5.1)
minqa         1.2.8     2024-08-17 [1] CRAN (R 4.5.1)
mitml         0.4-5     2023-03-08 [1] CRAN (R 4.5.1)
nleqslv       3.3.5     2023-11-26 [1] CRAN (R 4.5.0)
nlme          3.1-168   2025-03-31 [1] CRAN (R 4.5.1)
nloptr        2.2.1     2025-03-17 [1] CRAN (R 4.5.1)
nnet          7.3-20    2025-01-01 [1] CRAN (R 4.5.1)
pan           1.9       2023-08-21 [1] CRAN (R 4.5.1)
pillar        1.11.0    2025-07-04 [1] CRAN (R 4.5.1)
pim         * 2.0.3     2026-02-06 [1] local
pkgbuild      1.4.8     2025-05-26 [1] CRAN (R 4.5.1)
pkgconfig     2.0.3     2019-09-22 [1] CRAN (R 4.5.1)
pkgload       1.4.0     2024-06-28 [1] CRAN (R 4.5.1)
profvis       0.4.0     2024-09-20 [1] CRAN (R 4.5.1)
promises      1.3.3     2025-05-29 [1] CRAN (R 4.5.1)
purrr         1.1.0     2025-07-10 [1] CRAN (R 4.5.1)
quadprog      1.5-8     2019-11-20 [1] CRAN (R 4.5.0)
R6            2.6.1     2025-02-15 [1] CRAN (R 4.5.1)
rbibutils     2.3       2024-10-04 [1] CRAN (R 4.5.1)
Rcpp          1.1.0     2025-07-02 [1] CRAN (R 4.5.1)
Rdpack        2.6.4     2025-04-09 [1] CRAN (R 4.5.1)
reformulas    0.4.1     2025-04-30 [1] CRAN (R 4.5.1)
remotes       2.5.0     2024-03-17 [1] CRAN (R 4.5.1)
rlang         1.1.6     2025-04-11 [1] CRAN (R 4.5.1)
roxygen2      7.3.3     2025-09-03 [1] CRAN (R 4.5.1)
rpart         4.1.24    2025-01-07 [1] CRAN (R 4.5.1)
rprojroot     2.1.1     2025-08-26 [1] CRAN (R 4.5.1)
rstudioapi    0.17.1    2024-10-22 [1] CRAN (R 4.5.1)
sessioninfo   1.2.3     2025-02-05 [1] CRAN (R 4.5.1)
shape         1.4.6.1   2024-02-23 [1] CRAN (R 4.5.0)
shiny         1.11.1    2025-07-03 [1] CRAN (R 4.5.1)
stringi       1.8.7     2025-03-27 [1] CRAN (R 4.5.0)
stringr       1.5.2     2025-09-08 [1] CRAN (R 4.5.1)
survival      3.8-3     2024-12-17 [1] CRAN (R 4.5.1)
tibble        3.3.0     2025-06-08 [1] CRAN (R 4.5.1)
tidyr         1.3.1     2024-01-24 [1] CRAN (R 4.5.1)
tidyselect    1.2.1     2024-03-11 [1] CRAN (R 4.5.1)
urlchecker    1.0.1     2021-11-30 [1] CRAN (R 4.5.1)
usethis       3.2.1     2025-09-06 [1] CRAN (R 4.5.1)
utf8          1.2.6     2025-06-08 [1] CRAN (R 4.5.1)
vctrs         0.6.5     2023-12-01 [1] CRAN (R 4.5.1)
withr         3.0.2     2024-10-28 [1] CRAN (R 4.5.1)
xfun          0.53      2025-08-19 [1] CRAN (R 4.5.1)
xml2          1.4.0     2025-08-20 [1] CRAN (R 4.5.1)
xtable        1.8-4     2019-04-21 [1] CRAN (R 4.5.1)

[1] C:/Program Files/R/R-4.5.1/library
* ── Packages attached to the search path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant