-
Notifications
You must be signed in to change notification settings - Fork 7
/
README.Rmd
110 lines (88 loc) · 3.39 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# broom.helpers <img src="man/figures/broom.helpers.png" align="right" width="120" />
<!-- badges: start -->
[![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html#stable)
[![R-CMD-check](https://github.com/larmarange/broom.helpers/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/larmarange/broom.helpers/actions/workflows/R-CMD-check.yaml)
[![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)
<!-- badges: end -->
The broom.helpers package provides suite of functions to work with regression model `broom::tidy()` tibbles.
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](https://www.danieldsjoberg.com/gtsummary/articles/tbl_regression.html) and by `ggstats::ggcoef_model()` for [plotting model coefficients](https://larmarange.github.io/ggstats/articles/ggcoef_model.html).
## Installation & Documentation
To install **stable version**:
```{r eval=FALSE}
install.packages("broom.helpers")
```
Documentation of stable version: <https://larmarange.github.io/broom.helpers/>
To install **development version**:
```{r eval=FALSE}
remotes::install_github("larmarange/broom.helpers")
```
Documentation of development version: <https://larmarange.github.io/broom.helpers/dev/>
## Examples
### all-in-one wrapper
```{r}
mod1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris)
library(broom.helpers)
ex1 <- mod1 |> tidy_plus_plus()
ex1
dplyr::glimpse(ex1)
mod2 <- glm(
response ~ poly(age, 3) + stage + grade * trt,
na.omit(gtsummary::trial),
family = binomial,
contrasts = list(
stage = contr.treatment(4, base = 3),
grade = contr.sum
)
)
ex2 <- mod2 |>
tidy_plus_plus(
exponentiate = TRUE,
variable_labels = c(age = "Age (in years)"),
add_header_rows = TRUE,
show_single_row = "trt"
)
ex2
dplyr::glimpse(ex2)
```
### fine control
```{r}
ex3 <- mod1 |>
# perform initial tidying of model
tidy_and_attach() |>
# add reference row
tidy_add_reference_rows() |>
# add term labels
tidy_add_term_labels() |>
# remove intercept
tidy_remove_intercept()
ex3
dplyr::glimpse(ex3)
ex4 <- mod2 |>
# perform initial tidying of model
tidy_and_attach(exponentiate = TRUE) |>
# add variable labels, including a custom value for age
tidy_add_variable_labels(labels = c(age = "Age in years")) |>
# add reference rows for categorical variables
tidy_add_reference_rows() |>
# add a, estimate value of reference terms
tidy_add_estimate_to_reference_rows(exponentiate = TRUE) |>
# add header rows for categorical variables
tidy_add_header_rows()
ex4
dplyr::glimpse(ex4)
```