diff --git a/README.Rmd b/README.Rmd index 1f16f9b5..b52f14d6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,7 +18,7 @@ knitr::opts_chunk$set( [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable) [![R build status](https://github.com/larmarange/broom.helpers/workflows/R-CMD-check/badge.svg)](https://github.com/larmarange/broom.helpers/actions) -[![Codecov test coverage](https://codecov.io/gh/larmarange/broom.helpers/branch/main/graph/badge.svg)](https://codecov.io/gh/larmarange/broom.helpers?branch=main) +[![Codecov test coverage](https://codecov.io/gh/larmarange/broom.helpers/branch/main/graph/badge.svg)](https://app.codecov.io/gh/larmarange/broom.helpers?branch=main) [![CRAN status](https://www.r-pkg.org/badges/version/broom.helpers)](https://CRAN.R-project.org/package=broom.helpers) [![DOI](https://zenodo.org/badge/286680847.svg)](https://zenodo.org/badge/latestdoi/286680847) @@ -27,7 +27,7 @@ The broom.helpers package provides suite of functions to work with regression mo The suite includes functions to group regression model terms by variable, insert reference and header rows for categorical variables, add variable labels, and more. -`broom.helpers` is used, in particular, by `gtsummary::tbl_regression()` for producing [nice formatted tables of model coefficients](http://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html) and by `GGally::ggcoef_model()` for [plotting model coefficients](http://ggobi.github.io/ggally/articles/ggcoef_model.html). +`broom.helpers` is used, in particular, by `gtsummary::tbl_regression()` for producing [nice formatted tables of model coefficients](https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html) and by `GGally::ggcoef_model()` for [plotting model coefficients](https://ggobi.github.io/ggally/articles/ggcoef_model.html). ## Installation diff --git a/README.md b/README.md index 1235c104..a637c0cd 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,7 @@ stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https:// [![R build status](https://github.com/larmarange/broom.helpers/workflows/R-CMD-check/badge.svg)](https://github.com/larmarange/broom.helpers/actions) [![Codecov test -coverage](https://codecov.io/gh/larmarange/broom.helpers/branch/main/graph/badge.svg)](https://codecov.io/gh/larmarange/broom.helpers?branch=main) +coverage](https://codecov.io/gh/larmarange/broom.helpers/branch/main/graph/badge.svg)](https://app.codecov.io/gh/larmarange/broom.helpers?branch=main) [![CRAN status](https://www.r-pkg.org/badges/version/broom.helpers)](https://CRAN.R-project.org/package=broom.helpers) [![DOI](https://zenodo.org/badge/286680847.svg)](https://zenodo.org/badge/latestdoi/286680847) @@ -25,9 +25,9 @@ add variable labels, and more. `broom.helpers` is used, in particular, by `gtsummary::tbl_regression()` for producing [nice formatted tables of model -coefficients](http://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html) +coefficients](https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html) and by `GGally::ggcoef_model()` for [plotting model -coefficients](http://ggobi.github.io/ggally/articles/ggcoef_model.html). +coefficients](https://ggobi.github.io/ggally/articles/ggcoef_model.html). ## Installation @@ -52,26 +52,26 @@ mod1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris) library(broom.helpers) ex1 <- mod1 %>% tidy_plus_plus() ex1 -#> # A tibble: 4 × 17 +#> # A tibble: 4 x 17 #> term variable var_label var_class var_type var_nlevels contrasts #> -#> 1 Sepal.Width Sepal.Wi… Sepal.Wi… numeric continu… NA -#> 2 Speciessetosa Species Species factor categor… 3 contr.tr… -#> 3 Speciesversicolor Species Species factor categor… 3 contr.tr… -#> 4 Speciesvirginica Species Species factor categor… 3 contr.tr… -#> # … with 10 more variables: contrasts_type , reference_row , +#> 1 Sepal.Width Sepal.Wi~ Sepal.Wi~ numeric continu~ NA +#> 2 Speciessetosa Species Species factor categor~ 3 contr.tr~ +#> 3 Speciesversicolor Species Species factor categor~ 3 contr.tr~ +#> 4 Speciesvirginica Species Species factor categor~ 3 contr.tr~ +#> # ... with 10 more variables: contrasts_type , reference_row , #> # label , n_obs , estimate , std.error , statistic , #> # p.value , conf.low , conf.high dplyr::glimpse(ex1) #> Rows: 4 #> Columns: 17 -#> $ term "Sepal.Width", "Speciessetosa", "Speciesversicolor", "S… +#> $ term "Sepal.Width", "Speciessetosa", "Speciesversicolor", "S~ #> $ variable "Sepal.Width", "Species", "Species", "Species" #> $ var_label "Sepal.Width", "Species", "Species", "Species" #> $ var_class "numeric", "factor", "factor", "factor" -#> $ var_type "continuous", "categorical", "categorical", "categorica… +#> $ var_type "continuous", "categorical", "categorical", "categorica~ #> $ var_nlevels NA, 3, 3, 3 -#> $ contrasts NA, "contr.treatment", "contr.treatment", "contr.treatm… +#> $ contrasts NA, "contr.treatment", "contr.treatment", "contr.treatm~ #> $ contrasts_type NA, "treatment", "treatment", "treatment" #> $ reference_row NA, TRUE, FALSE, FALSE #> $ label "Sepal.Width", "setosa", "versicolor", "virginica" @@ -99,52 +99,53 @@ ex2 <- mod2 %>% add_header_rows = TRUE, show_single_row = "trt" ) +#> Le chargement a nécessité le package : emmeans ex2 -#> # A tibble: 17 × 19 +#> # A tibble: 17 x 19 #> term variable var_label var_class var_type var_nlevels header_row contrasts #> -#> 1 age Age (in … nmatrix.3 continu… NA TRUE -#> 2 poly(… age Age (in … nmatrix.3 continu… NA FALSE -#> 3 poly(… age Age (in … nmatrix.3 continu… NA FALSE -#> 4 poly(… age Age (in … nmatrix.3 continu… NA FALSE -#> 5 stage T Stage factor categor… 4 TRUE contr.tr… -#> 6 stage1 stage T Stage factor categor… 4 FALSE contr.tr… -#> 7 stage2 stage T Stage factor categor… 4 FALSE contr.tr… -#> 8 stage3 stage T Stage factor categor… 4 FALSE contr.tr… -#> 9 stage4 stage T Stage factor categor… 4 FALSE contr.tr… -#> 10 grade Grade factor categor… 3 TRUE contr.sum -#> 11 grade1 grade Grade factor categor… 3 FALSE contr.sum -#> 12 grade2 grade Grade factor categor… 3 FALSE contr.sum -#> 13 grade3 grade Grade factor categor… 3 FALSE contr.sum -#> 14 trtDr… trt Chemothe… character dichoto… 2 NA contr.tr… -#> 15 grade:t… Grade * … interac… NA TRUE -#> 16 grade… grade:t… Grade * … interac… NA FALSE -#> 17 grade… grade:t… Grade * … interac… NA FALSE -#> # … with 11 more variables: contrasts_type , reference_row , +#> 1 age Age (in ~ nmatrix.3 continu~ NA TRUE +#> 2 poly(~ age Age (in ~ nmatrix.3 continu~ NA FALSE +#> 3 poly(~ age Age (in ~ nmatrix.3 continu~ NA FALSE +#> 4 poly(~ age Age (in ~ nmatrix.3 continu~ NA FALSE +#> 5 stage T Stage factor categor~ 4 TRUE contr.tr~ +#> 6 stage1 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 7 stage2 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 8 stage3 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 9 stage4 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 10 grade Grade factor categor~ 3 TRUE contr.sum +#> 11 grade1 grade Grade factor categor~ 3 FALSE contr.sum +#> 12 grade2 grade Grade factor categor~ 3 FALSE contr.sum +#> 13 grade3 grade Grade factor categor~ 3 FALSE contr.sum +#> 14 trtDr~ trt Chemothe~ character dichoto~ 2 NA contr.tr~ +#> 15 grade:t~ Grade * ~ interac~ NA TRUE +#> 16 grade~ grade:t~ Grade * ~ interac~ NA FALSE +#> 17 grade~ grade:t~ Grade * ~ interac~ NA FALSE +#> # ... with 11 more variables: contrasts_type , reference_row , #> # label , n_obs , n_event , estimate , std.error , #> # statistic , p.value , conf.low , conf.high dplyr::glimpse(ex2) #> Rows: 17 #> Columns: 19 -#> $ term NA, "poly(age, 3)1", "poly(age, 3)2", "poly(age, 3)3", … -#> $ variable "age", "age", "age", "age", "stage", "stage", "stage", … -#> $ var_label "Age (in years)", "Age (in years)", "Age (in years)", "… -#> $ var_class "nmatrix.3", "nmatrix.3", "nmatrix.3", "nmatrix.3", "fa… -#> $ var_type "continuous", "continuous", "continuous", "continuous",… +#> $ term NA, "poly(age, 3)1", "poly(age, 3)2", "poly(age, 3)3", ~ +#> $ variable "age", "age", "age", "age", "stage", "stage", "stage", ~ +#> $ var_label "Age (in years)", "Age (in years)", "Age (in years)", "~ +#> $ var_class "nmatrix.3", "nmatrix.3", "nmatrix.3", "nmatrix.3", "fa~ +#> $ var_type "continuous", "continuous", "continuous", "continuous",~ #> $ var_nlevels NA, NA, NA, NA, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, NA, NA, NA -#> $ header_row TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, F… -#> $ contrasts NA, NA, NA, NA, "contr.treatment(base=3)", "contr.treat… -#> $ contrasts_type NA, NA, NA, NA, "treatment", "treatment", "treatment", … -#> $ reference_row NA, NA, NA, NA, NA, FALSE, FALSE, TRUE, FALSE, NA, FALS… -#> $ label "Age (in years)", "Age (in years)", "Age (in years)²", … -#> $ n_obs NA, 92, 56, 80, NA, 46, 50, 35, 42, NA, 63, 53, 57, 90,… -#> $ n_event NA, 31, 17, 22, NA, 17, 12, 13, 12, NA, 20, 16, 18, 30,… -#> $ estimate NA, 20.2416394, 1.2337899, 0.4931553, NA, 1.0047885, 0.… -#> $ std.error NA, 2.3254455, 2.3512842, 2.3936657, NA, 0.4959893, 0.5… -#> $ statistic NA, 1.29340459, 0.08935144, -0.29533409, NA, 0.00963137… -#> $ p.value NA, 0.1958712, 0.9288026, 0.7677387, NA, 0.9923154, 0.1… -#> $ conf.low NA, 0.225454425, 0.007493208, 0.004745694, NA, 0.379776… -#> $ conf.high NA, 2315.587655, 100.318341, 74.226179, NA, 2.683385, 1… +#> $ header_row TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALSE, F~ +#> $ contrasts NA, NA, NA, NA, "contr.treatment(base=3)", "contr.treat~ +#> $ contrasts_type NA, NA, NA, NA, "treatment", "treatment", "treatment", ~ +#> $ reference_row NA, NA, NA, NA, NA, FALSE, FALSE, TRUE, FALSE, NA, FALS~ +#> $ label "Age (in years)", "Age (in years)", "Age (in years)²", ~ +#> $ n_obs NA, 92, 56, 80, NA, 46, 50, 35, 42, NA, 63, 53, 57, 90,~ +#> $ n_event NA, 31, 17, 22, NA, 17, 12, 13, 12, NA, 20, 16, 18, 30,~ +#> $ estimate NA, 20.2416394, 1.2337899, 0.4931553, NA, 1.0047885, 0.~ +#> $ std.error NA, 2.3254455, 2.3512842, 2.3936657, NA, 0.4959893, 0.5~ +#> $ statistic NA, 1.29340459, 0.08935144, -0.29533409, NA, 0.00963137~ +#> $ p.value NA, 0.1958712, 0.9288026, 0.7677387, NA, 0.9923154, 0.1~ +#> $ conf.low NA, 0.225454425, 0.007493208, 0.004745694, NA, 0.379776~ +#> $ conf.high NA, 2315.587655, 100.318341, 74.226179, NA, 2.683385, 1~ ``` ### fine control @@ -160,26 +161,26 @@ ex3 <- mod1 %>% # remove intercept tidy_remove_intercept ex3 -#> # A tibble: 4 × 16 +#> # A tibble: 4 x 16 #> term variable var_label var_class var_type var_nlevels contrasts #> -#> 1 Sepal.Width Sepal.Wi… Sepal.Wi… numeric continu… NA -#> 2 Speciessetosa Species Species factor categor… 3 contr.tr… -#> 3 Speciesversicolor Species Species factor categor… 3 contr.tr… -#> 4 Speciesvirginica Species Species factor categor… 3 contr.tr… -#> # … with 9 more variables: contrasts_type , reference_row , +#> 1 Sepal.Width Sepal.Wi~ Sepal.Wi~ numeric continu~ NA +#> 2 Speciessetosa Species Species factor categor~ 3 contr.tr~ +#> 3 Speciesversicolor Species Species factor categor~ 3 contr.tr~ +#> 4 Speciesvirginica Species Species factor categor~ 3 contr.tr~ +#> # ... with 9 more variables: contrasts_type , reference_row , #> # label , estimate , std.error , statistic , #> # p.value , conf.low , conf.high dplyr::glimpse(ex3) #> Rows: 4 #> Columns: 16 -#> $ term "Sepal.Width", "Speciessetosa", "Speciesversicolor", "S… +#> $ term "Sepal.Width", "Speciessetosa", "Speciesversicolor", "S~ #> $ variable "Sepal.Width", "Species", "Species", "Species" #> $ var_label "Sepal.Width", "Species", "Species", "Species" #> $ var_class "numeric", "factor", "factor", "factor" -#> $ var_type "continuous", "categorical", "categorical", "categorica… +#> $ var_type "continuous", "categorical", "categorical", "categorica~ #> $ var_nlevels NA, 3, 3, 3 -#> $ contrasts NA, "contr.treatment", "contr.treatment", "contr.treatm… +#> $ contrasts NA, "contr.treatment", "contr.treatment", "contr.treatm~ #> $ contrasts_type NA, "treatment", "treatment", "treatment" #> $ reference_row NA, TRUE, FALSE, FALSE #> $ label "Sepal.Width", "setosa", "versicolor", "virginica" @@ -202,50 +203,50 @@ ex4 <- mod2 %>% # add header rows for categorical variables tidy_add_header_rows() ex4 -#> # A tibble: 20 × 17 +#> # A tibble: 20 x 17 #> term variable var_label var_class var_type var_nlevels header_row contrasts #> -#> 1 (Inte… (Interc… (Interce… interce… NA NA -#> 2 age Age in y… nmatrix.3 continu… NA TRUE -#> 3 poly(… age Age in y… nmatrix.3 continu… NA FALSE -#> 4 poly(… age Age in y… nmatrix.3 continu… NA FALSE -#> 5 poly(… age Age in y… nmatrix.3 continu… NA FALSE -#> 6 stage T Stage factor categor… 4 TRUE contr.tr… -#> 7 stage1 stage T Stage factor categor… 4 FALSE contr.tr… -#> 8 stage2 stage T Stage factor categor… 4 FALSE contr.tr… -#> 9 stage3 stage T Stage factor categor… 4 FALSE contr.tr… -#> 10 stage4 stage T Stage factor categor… 4 FALSE contr.tr… -#> 11 grade Grade factor categor… 3 TRUE contr.sum -#> 12 grade1 grade Grade factor categor… 3 FALSE contr.sum -#> 13 grade2 grade Grade factor categor… 3 FALSE contr.sum -#> 14 grade3 grade Grade factor categor… 3 FALSE contr.sum -#> 15 trt Chemothe… character dichoto… 2 TRUE contr.tr… -#> 16 trtDr… trt Chemothe… character dichoto… 2 FALSE contr.tr… -#> 17 trtDr… trt Chemothe… character dichoto… 2 FALSE contr.tr… -#> 18 grade:t… Grade * … interac… NA TRUE -#> 19 grade… grade:t… Grade * … interac… NA FALSE -#> 20 grade… grade:t… Grade * … interac… NA FALSE -#> # … with 9 more variables: contrasts_type , reference_row , +#> 1 (Inte~ (Interc~ (Interce~ interce~ NA NA +#> 2 age Age in y~ nmatrix.3 continu~ NA TRUE +#> 3 poly(~ age Age in y~ nmatrix.3 continu~ NA FALSE +#> 4 poly(~ age Age in y~ nmatrix.3 continu~ NA FALSE +#> 5 poly(~ age Age in y~ nmatrix.3 continu~ NA FALSE +#> 6 stage T Stage factor categor~ 4 TRUE contr.tr~ +#> 7 stage1 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 8 stage2 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 9 stage3 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 10 stage4 stage T Stage factor categor~ 4 FALSE contr.tr~ +#> 11 grade Grade factor categor~ 3 TRUE contr.sum +#> 12 grade1 grade Grade factor categor~ 3 FALSE contr.sum +#> 13 grade2 grade Grade factor categor~ 3 FALSE contr.sum +#> 14 grade3 grade Grade factor categor~ 3 FALSE contr.sum +#> 15 trt Chemothe~ character dichoto~ 2 TRUE contr.tr~ +#> 16 trtDr~ trt Chemothe~ character dichoto~ 2 FALSE contr.tr~ +#> 17 trtDr~ trt Chemothe~ character dichoto~ 2 FALSE contr.tr~ +#> 18 grade:t~ Grade * ~ interac~ NA TRUE +#> 19 grade~ grade:t~ Grade * ~ interac~ NA FALSE +#> 20 grade~ grade:t~ Grade * ~ interac~ NA FALSE +#> # ... with 9 more variables: contrasts_type , reference_row , #> # label , estimate , std.error , statistic , #> # p.value , conf.low , conf.high dplyr::glimpse(ex4) #> Rows: 20 #> Columns: 17 -#> $ term "(Intercept)", NA, "poly(age, 3)1", "poly(age, 3)2", "p… -#> $ variable "(Intercept)", "age", "age", "age", "age", "stage", "st… -#> $ var_label "(Intercept)", "Age in years", "Age in years", "Age in … -#> $ var_class NA, "nmatrix.3", "nmatrix.3", "nmatrix.3", "nmatrix.3",… -#> $ var_type "intercept", "continuous", "continuous", "continuous", … -#> $ var_nlevels NA, NA, NA, NA, NA, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2,… -#> $ header_row NA, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALS… -#> $ contrasts NA, NA, NA, NA, NA, "contr.treatment(base=3)", "contr.t… -#> $ contrasts_type NA, NA, NA, NA, NA, "treatment", "treatment", "treatmen… -#> $ reference_row NA, NA, NA, NA, NA, NA, FALSE, FALSE, TRUE, FALSE, NA, … -#> $ label "(Intercept)", "Age in years", "Age in years", "Age in … -#> $ estimate 0.5266376, NA, 20.2416394, 1.2337899, 0.4931553, NA, 1.… -#> $ std.error 0.4130930, NA, 2.3254455, 2.3512842, 2.3936657, NA, 0.4… -#> $ statistic -1.55229592, NA, 1.29340459, 0.08935144, -0.29533409, N… -#> $ p.value 0.1205914, NA, 0.1958712, 0.9288026, 0.7677387, NA, 0.9… -#> $ conf.low 0.227717775, NA, 0.225454425, 0.007493208, 0.004745694,… -#> $ conf.high 1.164600, NA, 2315.587655, 100.318341, 74.226179, NA, 2… +#> $ term "(Intercept)", NA, "poly(age, 3)1", "poly(age, 3)2", "p~ +#> $ variable "(Intercept)", "age", "age", "age", "age", "stage", "st~ +#> $ var_label "(Intercept)", "Age in years", "Age in years", "Age in ~ +#> $ var_class NA, "nmatrix.3", "nmatrix.3", "nmatrix.3", "nmatrix.3",~ +#> $ var_type "intercept", "continuous", "continuous", "continuous", ~ +#> $ var_nlevels NA, NA, NA, NA, NA, 4, 4, 4, 4, 4, 3, 3, 3, 3, 2, 2, 2,~ +#> $ header_row NA, TRUE, FALSE, FALSE, FALSE, TRUE, FALSE, FALSE, FALS~ +#> $ contrasts NA, NA, NA, NA, NA, "contr.treatment(base=3)", "contr.t~ +#> $ contrasts_type NA, NA, NA, NA, NA, "treatment", "treatment", "treatmen~ +#> $ reference_row NA, NA, NA, NA, NA, NA, FALSE, FALSE, TRUE, FALSE, NA, ~ +#> $ label "(Intercept)", "Age in years", "Age in years", "Age in ~ +#> $ estimate 0.5266376, NA, 20.2416394, 1.2337899, 0.4931553, NA, 1.~ +#> $ std.error 0.4130930, NA, 2.3254455, 2.3512842, 2.3936657, NA, 0.4~ +#> $ statistic -1.55229592, NA, 1.29340459, 0.08935144, -0.29533409, N~ +#> $ p.value 0.1205914, NA, 0.1958712, 0.9288026, 0.7677387, NA, 0.9~ +#> $ conf.low 0.227717775, NA, 0.225454425, 0.007493208, 0.004745694,~ +#> $ conf.high 1.164600, NA, 2315.587655, 100.318341, 74.226179, NA, 2~ ``` diff --git a/vignettes/tidy.Rmd b/vignettes/tidy.Rmd index 3d77b78c..5c9b3c9b 100644 --- a/vignettes/tidy.Rmd +++ b/vignettes/tidy.Rmd @@ -40,7 +40,7 @@ print_table <- function(tab) { ``` Our model predicts tumor response using chemotherapy treatment and tumor grade. -The data set we're utilizing has already labelled the columns using the [labelled package](http://larmarange.github.io/labelled/). +The data set we're utilizing has already labelled the columns using the [labelled package](https://larmarange.github.io/labelled/). The column labels will be carried through to our figure and table. ```{r} @@ -124,7 +124,7 @@ tidy_table %>% print_table() ``` -**Note::** for more advanced and nicely formatted tables of model coefficients, look at `gtsummary::tbl_regression()` and its [dedicated vignette](http://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html). `gtsummary::tbl_regression()` internally uses `broom.helpers`. +**Note::** for more advanced and nicely formatted tables of model coefficients, look at `gtsummary::tbl_regression()` and its [dedicated vignette](https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html). `gtsummary::tbl_regression()` internally uses `broom.helpers`. ## All-in-one function