broom.helpers/ 0000755 0001762 0000144 00000000000 14464210122 013025 5 ustar ligges users broom.helpers/NAMESPACE 0000644 0001762 0000144 00000015310 14464175037 014263 0 ustar ligges users # Generated by roxygen2: do not edit by hand
S3method(model_compute_terms_contributions,default)
S3method(model_get_assign,default)
S3method(model_get_assign,model_fit)
S3method(model_get_assign,vglm)
S3method(model_get_coefficients_type,LORgee)
S3method(model_get_coefficients_type,biglm)
S3method(model_get_coefficients_type,clm)
S3method(model_get_coefficients_type,clmm)
S3method(model_get_coefficients_type,clogit)
S3method(model_get_coefficients_type,coxph)
S3method(model_get_coefficients_type,crr)
S3method(model_get_coefficients_type,default)
S3method(model_get_coefficients_type,fixest)
S3method(model_get_coefficients_type,geeglm)
S3method(model_get_coefficients_type,glm)
S3method(model_get_coefficients_type,glmerMod)
S3method(model_get_coefficients_type,model_fit)
S3method(model_get_coefficients_type,multinom)
S3method(model_get_coefficients_type,negbin)
S3method(model_get_coefficients_type,polr)
S3method(model_get_coefficients_type,svyolr)
S3method(model_get_coefficients_type,tidycrr)
S3method(model_get_contrasts,betareg)
S3method(model_get_contrasts,default)
S3method(model_get_contrasts,hurdle)
S3method(model_get_contrasts,model_fit)
S3method(model_get_contrasts,zeroinfl)
S3method(model_get_model,default)
S3method(model_get_model,mira)
S3method(model_get_model_frame,biglm)
S3method(model_get_model_frame,coxph)
S3method(model_get_model_frame,default)
S3method(model_get_model_frame,fixest)
S3method(model_get_model_frame,model_fit)
S3method(model_get_model_frame,survreg)
S3method(model_get_model_matrix,LORgee)
S3method(model_get_model_matrix,betareg)
S3method(model_get_model_matrix,biglm)
S3method(model_get_model_matrix,brmsfit)
S3method(model_get_model_matrix,clm)
S3method(model_get_model_matrix,default)
S3method(model_get_model_matrix,fixest)
S3method(model_get_model_matrix,glmmTMB)
S3method(model_get_model_matrix,model_fit)
S3method(model_get_model_matrix,multinom)
S3method(model_get_model_matrix,plm)
S3method(model_get_n,LORgee)
S3method(model_get_n,coxph)
S3method(model_get_n,default)
S3method(model_get_n,glm)
S3method(model_get_n,glmerMod)
S3method(model_get_n,model_fit)
S3method(model_get_n,multinom)
S3method(model_get_n,survreg)
S3method(model_get_n,tidycrr)
S3method(model_get_nlevels,default)
S3method(model_get_offset,default)
S3method(model_get_pairwise_contrasts,betareg)
S3method(model_get_pairwise_contrasts,default)
S3method(model_get_pairwise_contrasts,hurdle)
S3method(model_get_pairwise_contrasts,zeroinfl)
S3method(model_get_response,default)
S3method(model_get_response,glm)
S3method(model_get_response,glmerMod)
S3method(model_get_response,model_fit)
S3method(model_get_response_variable,default)
S3method(model_get_terms,betareg)
S3method(model_get_terms,brmsfit)
S3method(model_get_terms,default)
S3method(model_get_terms,glmmTMB)
S3method(model_get_terms,model_fit)
S3method(model_get_weights,default)
S3method(model_get_weights,model_fit)
S3method(model_get_weights,svyglm)
S3method(model_get_xlevels,brmsfit)
S3method(model_get_xlevels,default)
S3method(model_get_xlevels,felm)
S3method(model_get_xlevels,glmerMod)
S3method(model_get_xlevels,glmmTMB)
S3method(model_get_xlevels,lmerMod)
S3method(model_get_xlevels,model_fit)
S3method(model_get_xlevels,plm)
S3method(model_identify_variables,aov)
S3method(model_identify_variables,clm)
S3method(model_identify_variables,clmm)
S3method(model_identify_variables,default)
S3method(model_identify_variables,gam)
S3method(model_identify_variables,lavaan)
S3method(model_identify_variables,logitr)
S3method(model_identify_variables,model_fit)
S3method(model_list_contrasts,default)
S3method(model_list_higher_order_variables,default)
S3method(model_list_terms_levels,default)
S3method(model_list_variables,default)
S3method(model_list_variables,lavaan)
S3method(model_list_variables,logitr)
export("%>%")
export(.assert_package)
export(.clean_backticks)
export(.escape_regex)
export(.formula_list_to_named_list)
export(.generic_selector)
export(.get_all_packages_dependencies)
export(.get_min_version_required)
export(.get_package_dependencies)
export(.is_selector_scoped)
export(.select_to_varnames)
export(all_categorical)
export(all_continuous)
export(all_contrasts)
export(all_dichotomous)
export(all_interaction)
export(all_intercepts)
export(all_of)
export(all_ran_pars)
export(all_ran_vals)
export(any_of)
export(contains)
export(ends_with)
export(everything)
export(last_col)
export(matches)
export(model_compute_terms_contributions)
export(model_get_assign)
export(model_get_coefficients_type)
export(model_get_contrasts)
export(model_get_model)
export(model_get_model_frame)
export(model_get_model_matrix)
export(model_get_n)
export(model_get_nlevels)
export(model_get_offset)
export(model_get_pairwise_contrasts)
export(model_get_response)
export(model_get_response_variable)
export(model_get_terms)
export(model_get_weights)
export(model_get_xlevels)
export(model_identify_variables)
export(model_list_contrasts)
export(model_list_higher_order_variables)
export(model_list_terms_levels)
export(model_list_variables)
export(num_range)
export(one_of)
export(plot_marginal_predictions)
export(seq_range)
export(starts_with)
export(tidy_add_coefficients_type)
export(tidy_add_contrasts)
export(tidy_add_estimate_to_reference_rows)
export(tidy_add_header_rows)
export(tidy_add_n)
export(tidy_add_pairwise_contrasts)
export(tidy_add_reference_rows)
export(tidy_add_term_labels)
export(tidy_add_variable_labels)
export(tidy_all_effects)
export(tidy_and_attach)
export(tidy_attach_model)
export(tidy_avg_comparisons)
export(tidy_avg_slopes)
export(tidy_broom)
export(tidy_detach_model)
export(tidy_disambiguate_terms)
export(tidy_get_model)
export(tidy_ggpredict)
export(tidy_identify_variables)
export(tidy_marginal_contrasts)
export(tidy_marginal_means)
export(tidy_marginal_predictions)
export(tidy_margins)
export(tidy_multgee)
export(tidy_parameters)
export(tidy_plus_plus)
export(tidy_remove_intercept)
export(tidy_select_variables)
export(tidy_with_broom_or_parameters)
export(tidy_zeroinfl)
export(variables_to_contrast)
export(variables_to_predict)
export(vars)
importFrom(cli,cli_alert_danger)
importFrom(cli,cli_alert_info)
importFrom(cli,cli_code)
importFrom(cli,cli_ul)
importFrom(dplyr,`%>%`)
importFrom(dplyr,add_row)
importFrom(dplyr,all_of)
importFrom(dplyr,any_of)
importFrom(dplyr,contains)
importFrom(dplyr,ends_with)
importFrom(dplyr,everything)
importFrom(dplyr,last_col)
importFrom(dplyr,matches)
importFrom(dplyr,num_range)
importFrom(dplyr,one_of)
importFrom(dplyr,starts_with)
importFrom(dplyr,vars)
importFrom(lifecycle,deprecate_soft)
importFrom(purrr,"%||%")
importFrom(rlang,.data)
importFrom(rlang,.env)
broom.helpers/README.md 0000644 0001762 0000144 00000035746 14360056067 014336 0 ustar ligges users
# broom.helpers
[](https://lifecycle.r-lib.org/articles/stages.html#stable)
[](https://github.com/larmarange/broom.helpers/actions/workflows/R-CMD-check.yaml)
[](https://app.codecov.io/gh/larmarange/broom.helpers?branch=main)
[](https://CRAN.R-project.org/package=broom.helpers)
[](https://zenodo.org/badge/latestdoi/286680847)
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
install.packages("broom.helpers")
```
Documentation of stable version:
To install **development version**:
``` r
remotes::install_github("larmarange/broom.helpers")
```
Documentation of development version:
## Examples
### all-in-one wrapper
``` r
mod1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris)
library(broom.helpers)
ex1 <- mod1 %>% tidy_plus_plus()
ex1
#> # A tibble: 4 × 17
#> term varia…¹ var_l…² var_c…³ var_t…⁴ var_n…⁵ contr…⁶ contr…⁷ refer…⁸ label
#>
#> 1 Sepal.W… Sepal.… Sepal.… numeric contin… NA NA Sepa…
#> 2 Species… Species Species factor catego… 3 contr.… treatm… TRUE seto…
#> 3 Species… Species Species factor catego… 3 contr.… treatm… FALSE vers…
#> 4 Species… Species Species factor catego… 3 contr.… treatm… FALSE virg…
#> # … with 7 more variables: n_obs , estimate , std.error ,
#> # statistic , p.value , conf.low , conf.high , and
#> # abbreviated variable names ¹variable, ²var_label, ³var_class, ⁴var_type,
#> # ⁵var_nlevels, ⁶contrasts, ⁷contrasts_type, ⁸reference_row
dplyr::glimpse(ex1)
#> Rows: 4
#> Columns: 17
#> $ 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_nlevels NA, 3, 3, 3
#> $ 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"
#> $ n_obs 150, 50, 50, 50
#> $ estimate 0.8035609, 0.0000000, 1.4587431, 1.9468166
#> $ std.error 0.1063390, NA, 0.1121079, 0.1000150
#> $ statistic 7.556598, NA, 13.011954, 19.465255
#> $ p.value 4.187340e-12, NA, 3.478232e-26, 2.094475e-42
#> $ conf.low 0.5933983, NA, 1.2371791, 1.7491525
#> $ conf.high 1.013723, NA, 1.680307, 2.144481
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
#> # A tibble: 17 × 19
#> term varia…¹ var_l…² var_c…³ var_t…⁴ var_n…⁵ heade…⁶ contr…⁷ contr…⁸ refer…⁹
#>
#> 1 age Age (i… nmatri… contin… NA TRUE NA
#> 2 poly… age Age (i… nmatri… contin… NA FALSE NA
#> 3 poly… age Age (i… nmatri… contin… NA FALSE NA
#> 4 poly… age Age (i… nmatri… contin… NA FALSE NA
#> 5 stage T Stage factor catego… 4 TRUE contr.… treatm… NA
#> 6 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… FALSE
#> 7 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… FALSE
#> 8 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… TRUE
#> 9 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… FALSE
#> 10 grade Grade factor catego… 3 TRUE contr.… sum NA
#> 11 grad… grade Grade factor catego… 3 FALSE contr.… sum FALSE
#> 12 grad… grade Grade factor catego… 3 FALSE contr.… sum FALSE
#> 13 grad… grade Grade factor catego… 3 FALSE contr.… sum TRUE
#> 14 trtD… trt Chemot… charac… dichot… 2 NA contr.… treatm… FALSE
#> 15 grade:… Grade … intera… NA TRUE NA
#> 16 grad… grade:… Grade … intera… NA FALSE NA
#> 17 grad… grade:… Grade … intera… NA FALSE NA
#> # … with 9 more variables: label , n_obs , n_event ,
#> # estimate , std.error , statistic , p.value ,
#> # conf.low , conf.high , and abbreviated variable names ¹variable,
#> # ²var_label, ³var_class, ⁴var_type, ⁵var_nlevels, ⁶header_row, ⁷contrasts,
#> # ⁸contrasts_type, ⁹reference_row
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",…
#> $ 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…
```
### 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
#> # A tibble: 4 × 16
#> term varia…¹ var_l…² var_c…³ var_t…⁴ var_n…⁵ contr…⁶ contr…⁷ refer…⁸ label
#>
#> 1 Sepal.W… Sepal.… Sepal.… numeric contin… NA NA Sepa…
#> 2 Species… Species Species factor catego… 3 contr.… treatm… TRUE seto…
#> 3 Species… Species Species factor catego… 3 contr.… treatm… FALSE vers…
#> 4 Species… Species Species factor catego… 3 contr.… treatm… FALSE virg…
#> # … with 6 more variables: estimate , std.error , statistic ,
#> # p.value , conf.low , conf.high , and abbreviated variable
#> # names ¹variable, ²var_label, ³var_class, ⁴var_type, ⁵var_nlevels,
#> # ⁶contrasts, ⁷contrasts_type, ⁸reference_row
dplyr::glimpse(ex3)
#> Rows: 4
#> Columns: 16
#> $ 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_nlevels NA, 3, 3, 3
#> $ 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"
#> $ estimate 0.8035609, NA, 1.4587431, 1.9468166
#> $ std.error 0.1063390, NA, 0.1121079, 0.1000150
#> $ statistic 7.556598, NA, 13.011954, 19.465255
#> $ p.value 4.187340e-12, NA, 3.478232e-26, 2.094475e-42
#> $ conf.low 0.5933983, NA, 1.2371791, 1.7491525
#> $ conf.high 1.013723, NA, 1.680307, 2.144481
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
#> # A tibble: 20 × 17
#> term varia…¹ var_l…² var_c…³ var_t…⁴ var_n…⁵ heade…⁶ contr…⁷ contr…⁸ refer…⁹
#>
#> 1 (Int… (Inter… (Inter… interc… NA NA NA
#> 2 age Age in… nmatri… contin… NA TRUE NA
#> 3 poly… age Age in… nmatri… contin… NA FALSE NA
#> 4 poly… age Age in… nmatri… contin… NA FALSE NA
#> 5 poly… age Age in… nmatri… contin… NA FALSE NA
#> 6 stage T Stage factor catego… 4 TRUE contr.… treatm… NA
#> 7 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… FALSE
#> 8 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… FALSE
#> 9 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… TRUE
#> 10 stag… stage T Stage factor catego… 4 FALSE contr.… treatm… FALSE
#> 11 grade Grade factor catego… 3 TRUE contr.… sum NA
#> 12 grad… grade Grade factor catego… 3 FALSE contr.… sum FALSE
#> 13 grad… grade Grade factor catego… 3 FALSE contr.… sum FALSE
#> 14 grad… grade Grade factor catego… 3 FALSE contr.… sum TRUE
#> 15 trt Chemot… charac… dichot… 2 TRUE contr.… treatm… NA
#> 16 trtD… trt Chemot… charac… dichot… 2 FALSE contr.… treatm… TRUE
#> 17 trtD… trt Chemot… charac… dichot… 2 FALSE contr.… treatm… FALSE
#> 18 grade:… Grade … intera… NA TRUE NA
#> 19 grad… grade:… Grade … intera… NA FALSE NA
#> 20 grad… grade:… Grade … intera… NA FALSE NA
#> # … with 7 more variables: label , estimate , std.error ,
#> # statistic , p.value , conf.low , conf.high , and
#> # abbreviated variable names ¹variable, ²var_label, ³var_class, ⁴var_type,
#> # ⁵var_nlevels, ⁶header_row, ⁷contrasts, ⁸contrasts_type, ⁹reference_row
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…
```
broom.helpers/data/ 0000755 0001762 0000144 00000000000 14464175037 013755 5 ustar ligges users broom.helpers/data/supported_models.rda 0000644 0001762 0000144 00000002203 14464175055 020032 0 ustar ligges users BZh91AY&SY' 7Fe\w?@A @ ;lackRS53ROiЧP=MP =F)OPhqddd#FC@D=OH 4h LLC!C@
d1
HL Lښ h 4
4H@pћ2<*"V$'7x,5Mn
AL0ÙԅFFt El$8ᬁcІ@chcBgpIG6mjNB`lfLx7i
61|Zl!۾TG;+H'Gor8CٟN!pQ1ee5VxXoi# &Naus*˽ckcd+[z}ġs. Lq5
0i"[&!(jX]@u=2B,#'/E-5Tjhw=;%3)]
<1bXs(R|*'f3_&T!Ɔǵ)i"t&R
L*sJ̊x[q.Fg2jRDlnf\ZYl1˜'h#})ʫx6ҀF%:x kF`$nkO8E*.5'ac K).RPbvT+KI>)iJs8gϲ͗eX E9p5T(9ΖL2hC!<5 Q]t ZVBk;Zȅ
eJEŰKDNN4,.b6;*jESc}GRsf3( \7e0C/H(Wݧrޑqt2L<ݤ:VXUɯDnlhK`#z)ȅ4\(WeT:@Q!7UUAq2aH
tR broom.helpers/man/ 0000755 0001762 0000144 00000000000 14464175037 013617 5 ustar ligges users broom.helpers/man/tidy_disambiguate_terms.Rd 0000644 0001762 0000144 00000004211 14457461242 021003 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_disambiguate_terms.R
\name{tidy_disambiguate_terms}
\alias{tidy_disambiguate_terms}
\title{Disambiguate terms}
\usage{
tidy_disambiguate_terms(x, sep = ".", model = tidy_get_model(x), quiet = FALSE)
}
\arguments{
\item{x}{a tidy tibble}
\item{sep}{character, separator added between group name and term}
\item{model}{the corresponding model, if not attached to \code{x}}
\item{quiet}{logical argument whether broom.helpers should not return
a message when requested output cannot be generated. Default is \code{FALSE}}
}
\description{
For mixed models, the \code{term} column returned by \code{broom.mixed} may have
duplicated values for random-effect parameters and random-effect values.
In such case, the terms could be disambiguated be prefixing them with the
value of the \code{group} column. \code{tidy_disambiguate_terms()} will not change
any term if there is no \code{group} column in \code{x}. The original term value
is kept in a new column \code{original_term}.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
if (
.assert_package("lme4", boolean = TRUE) &&
.assert_package("broom.mixed", boolean = TRUE) &&
.assert_package("gtsummary", boolean = TRUE)
) {
mod <- lme4::lmer(marker ~ stage + (1 | grade) + (death | response), gtsummary::trial)
mod \%>\%
tidy_and_attach() \%>\%
tidy_disambiguate_terms()
}
\dontshow{\}) # examplesIf}
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_n}()},
\code{\link{tidy_add_pairwise_contrasts}()},
\code{\link{tidy_add_reference_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/tidy_add_reference_rows.Rd 0000644 0001762 0000144 00000007206 14463417025 020757 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_add_reference_rows.R
\name{tidy_add_reference_rows}
\alias{tidy_add_reference_rows}
\title{Add references rows for categorical variables}
\usage{
tidy_add_reference_rows(
x,
no_reference_row = NULL,
model = tidy_get_model(x),
quiet = FALSE
)
}
\arguments{
\item{x}{a tidy tibble}
\item{no_reference_row}{a vector indicating the name of variables
for those no reference row should be added.
Accepts \link[dplyr:select]{tidyselect} syntax. Default is \code{NULL}.
See also \code{\link[=all_categorical]{all_categorical()}} and \code{\link[=all_dichotomous]{all_dichotomous()}}}
\item{model}{the corresponding model, if not attached to \code{x}}
\item{quiet}{logical argument whether broom.helpers should not return
a message when requested output cannot be generated. Default is \code{FALSE}}
}
\description{
For categorical variables with a treatment contrast
(\code{\link[stats:contrast]{stats::contr.treatment()}}), a SAS contrast (\code{\link[stats:contrast]{stats::contr.SAS()}})
a sum contrast (\code{\link[stats:contrast]{stats::contr.sum()}}), or successive differences contrast
(\code{\link[MASS:contr.sdif]{MASS::contr.sdif()}}) add a reference row.
}
\details{
The added \code{reference_row} column will be equal to:
\itemize{
\item \code{TRUE} for a reference row;
\item \code{FALSE} for a normal row of a variable with a reference row;
\item \code{NA} for variables without a reference row.
}
If the \code{contrasts} column is not yet available in \code{x},
\code{\link[=tidy_add_contrasts]{tidy_add_contrasts()}} will be automatically applied.
\code{tidy_add_reference_rows()} will not populate the label
of the reference term. It is therefore better to apply
\code{\link[=tidy_add_term_labels]{tidy_add_term_labels()}} after \code{tidy_add_reference_rows()}
rather than before. Similarly, it is better to apply
\code{tidy_add_reference_rows()} before \code{\link[=tidy_add_n]{tidy_add_n()}}.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
if (.assert_package("gtsummary", boolean = TRUE)) {
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
res <- df \%>\%
glm(
Survived ~ Class + Age + Sex,
data = ., weights = .$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.SAS")
) \%>\%
tidy_and_attach()
res \%>\% tidy_add_reference_rows()
res \%>\% tidy_add_reference_rows(no_reference_row = all_dichotomous())
res \%>\% tidy_add_reference_rows(no_reference_row = "Class")
glm(
response ~ stage + grade * trt,
gtsummary::trial,
family = binomial,
contrasts = list(
stage = contr.treatment(4, base = 3),
grade = contr.treatment(3, base = 2),
trt = contr.treatment(2, base = 2)
)
) \%>\%
tidy_and_attach() \%>\%
tidy_add_reference_rows()
}
\dontshow{\}) # examplesIf}
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_n}()},
\code{\link{tidy_add_pairwise_contrasts}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_disambiguate_terms}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/model_list_terms_levels.Rd 0000644 0001762 0000144 00000007067 14463417025 021032 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_list_terms_levels.R
\name{model_list_terms_levels}
\alias{model_list_terms_levels}
\alias{model_list_terms_levels.default}
\title{List levels of categorical terms}
\usage{
model_list_terms_levels(
model,
label_pattern = "{level}",
variable_labels = NULL,
sdif_term_level = c("diff", "ratio")
)
\method{model_list_terms_levels}{default}(
model,
label_pattern = "{level}",
variable_labels = NULL,
sdif_term_level = c("diff", "ratio")
)
}
\arguments{
\item{model}{a model object}
\item{label_pattern}{a \link[glue:glue]{glue pattern} for term labels (see examples)}
\item{variable_labels}{an optional named list or named vector of
custom variable labels passed to \code{\link[=model_list_variables]{model_list_variables()}}}
\item{sdif_term_level}{for successive differences contrasts, how should term
levels be named? \code{"diff"} for \code{"B - A"} (default), \code{"ratio"} for \code{"B / A"}}
}
\value{
A tibble with ten columns:
\itemize{
\item \code{variable}: variable
\item \code{contrasts_type}: type of contrasts ("sum" or "treatment")
\item \code{term}: term name
\item \code{level}: term level
\item \code{level_rank}: rank of the level
\item \code{reference}: logical indicating which term is the reference level
\item \code{reference_level}: level of the reference term
\item \code{var_label}: variable label obtained with \code{\link[=model_list_variables]{model_list_variables()}}
\item \code{var_nlevels}: number of levels in this variable
\item \code{dichotomous}: logical indicating if the variable is dichotomous
\item \code{label}: term label (by default equal to term level)
The first nine columns can be used in \code{label_pattern}.
}
}
\description{
Only for categorical variables with treatment,
SAS, sum or successive differences contrasts (cf. \code{\link[MASS:contr.sdif]{MASS::contr.sdif()}}), and
categorical variables with no contrast.
}
\examples{
glm(
am ~ mpg + factor(cyl),
data = mtcars,
family = binomial,
contrasts = list(`factor(cyl)` = contr.sum)
) \%>\%
model_list_terms_levels()
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
mod <- df \%>\%
glm(
Survived ~ Class + Age + Sex,
data = ., weights = .$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.helmert")
)
mod \%>\% model_list_terms_levels()
mod \%>\% model_list_terms_levels("{level} vs {reference_level}")
mod \%>\% model_list_terms_levels("{variable} [{level} - {reference_level}]")
mod \%>\% model_list_terms_levels(
"{ifelse(reference, level, paste(level, '-', reference_level))}"
)
}
\seealso{
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/tidy_with_broom_or_parameters.Rd 0000644 0001762 0000144 00000001766 14464175037 022245 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/custom_tidiers.R
\name{tidy_with_broom_or_parameters}
\alias{tidy_with_broom_or_parameters}
\title{Tidy a model with broom or parameters}
\usage{
tidy_with_broom_or_parameters(x, conf.int = TRUE, conf.level = 0.95, ...)
}
\arguments{
\item{x}{a model}
\item{conf.int}{logical indicating whether or not to include a confidence
interval in the tidied output}
\item{conf.level}{the confidence level to use for the confidence interval}
\item{...}{additional parameters passed to \code{broom::tidy()} or
\code{parameters::model_parameters()}}
}
\description{
Try to tidy a model with \code{broom::tidy()}. If it fails, will try to tidy the
model using \code{parameters::model_parameters()} through \code{tidy_parameters()}.
}
\seealso{
Other custom_tieders:
\code{\link{tidy_broom}()},
\code{\link{tidy_multgee}()},
\code{\link{tidy_parameters}()},
\code{\link{tidy_zeroinfl}()}
}
\concept{custom_tieders}
broom.helpers/man/assert_package.Rd 0000644 0001762 0000144 00000004731 14357760764 017077 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/assert_package.R
\name{assert_package}
\alias{assert_package}
\alias{.assert_package}
\alias{.get_package_dependencies}
\alias{.get_all_packages_dependencies}
\alias{.get_min_version_required}
\title{Check a package installation status or minimum required version}
\usage{
.assert_package(pkg, fn = NULL, pkg_search = "broom.helpers", boolean = FALSE)
.get_package_dependencies(pkg_search = "broom.helpers")
.get_all_packages_dependencies(
pkg_search = NULL,
remove_duplicates = FALSE,
lib.loc = NULL
)
.get_min_version_required(pkg, pkg_search = "broom.helpers")
}
\arguments{
\item{pkg}{Package required}
\item{fn}{Calling function from the user perspective. Used to write
informative error messages.}
\item{pkg_search}{the package the function will search for a minimum
required version from.}
\item{boolean}{logical indicating whether to return a \code{TRUE}/\code{FALSE}, rather
than error when package/package version not available. Default is \code{FALSE},
which will return an error if \code{pkg} is not installed.}
\item{remove_duplicates}{if several versions of a package are installed,
should only the first one be returned?}
\item{lib.loc}{location of \code{R} library trees to search through, see
\code{utils::installed.packages()}.}
}
\value{
logical or error for \code{.assert_package()}, \code{NULL} or character with
the minimum version required for \code{.get_min_version_required()}, a tibble for
\code{.get_package_dependencies()}.
}
\description{
The function \code{.assert_package()} checks whether a package is installed and
returns an error or \code{FALSE} if not available. If a package search is provided,
the function will check whether a minimum version of a package is required.
The function \code{.get_package_dependencies()} returns a tibble with all
dependencies of a specific package. Finally, \code{.get_min_version_required()}
will return, if any, the minimum version of \code{pkg} required by \code{pkg_search},
\code{NULL} if no minimum version required.
}
\details{
\code{get_all_packages_dependencies()} could be used to get the list of
dependencies of all installed packages.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
.assert_package("broom", boolean = TRUE)
.get_package_dependencies()
.get_min_version_required("brms")
\dontshow{\}) # examplesIf}
}
broom.helpers/man/tidy_marginal_contrasts.Rd 0000644 0001762 0000144 00000016035 14370455163 021033 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/marginal_tidiers.R
\name{tidy_marginal_contrasts}
\alias{tidy_marginal_contrasts}
\alias{variables_to_contrast}
\title{Marginal Contrasts with \code{marginaleffects::avg_comparisons()}}
\usage{
tidy_marginal_contrasts(
x,
variables_list = "auto",
conf.int = TRUE,
conf.level = 0.95,
...
)
variables_to_contrast(
model,
interactions = TRUE,
cross = FALSE,
var_categorical = "reference",
var_continuous = 1,
by_categorical = unique,
by_continuous = stats::fivenum
)
}
\arguments{
\item{x}{a model}
\item{variables_list}{a list whose elements will be sequentially passed to
\code{variables} in \code{marginaleffects::avg_comparisons()} (see details below);
alternatively, it could also be the string \code{"auto"} (default), \code{"cross"} or
\code{"no_interaction"}}
\item{conf.int}{logical indicating whether or not to include a confidence
interval in the tidied output}
\item{conf.level}{the confidence level to use for the confidence interval}
\item{...}{additional parameters passed to
\code{marginaleffects::avg_comparisons()}}
\item{model}{a model}
\item{interactions}{should combinations of variables corresponding to
interactions be returned?}
\item{cross}{if \code{interaction} is \code{TRUE}, should "cross-contrasts" be
computed? (if \code{FALSE}, only the last term of an interaction is passed to
\code{variable} and the other terms are passed to \code{by})}
\item{var_categorical}{default \code{variable} value for categorical variables}
\item{var_continuous}{default \code{variable} value for continuous variables}
\item{by_categorical}{default \code{by} value for categorical variables}
\item{by_continuous}{default \code{by} value for continuous variables}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Use \code{marginaleffects::avg_comparisons()} to estimate marginal contrasts for
each variable of a model and return a tibble tidied in a way that it could
be used by \code{broom.helpers} functions.
See \code{marginaleffects::avg_comparisons()} for a list of supported models.
}
\details{
Marginal contrasts are obtained by calling, for each variable or combination
of variables, \code{marginaleffects::avg_comparisons()}.
\code{tidy_marginal_contrasts()} will compute marginal contrasts for each
variable or combination of variables, before stacking the results in a unique
tibble. This is why \code{tidy_marginal_contrasts()} has a \code{variables_list}
argument consisting of a list of specifications that will be passed
sequentially to the \code{variables} and the \code{by} argument of
\code{marginaleffects::avg_comparisons()}.
Considering a single categorical variable named \code{cat}, \code{tidy_marginal_contrasts()}
will call \code{avg_comparisons(model, variables = list(cat = "reference"))}
to obtain average marginal contrasts for this variable.
Considering a single continuous variable named \code{cont}, \code{tidy_marginalcontrasts()}
will call \code{avg_comparisons(model, variables = list(cont = 1))}
to obtain average marginal contrasts for an increase of one unit.
For a combination of variables, there are several possibilities. You could
compute "cross-contrasts" by providing simultaneously several variables
to \code{variables} and specifying \code{cross = TRUE} to
\code{marginaleffects::avg_comparisons()}. Alternatively, you could compute the
contrasts of a first variable specified to \code{variables} for the
different values of a second variable specified to \code{by}.
The helper function \code{variables_to_contrast()} could be used to automatically
generate a suitable list to be used with \code{variables_list}. Each combination
of variables should be a list with two named elements: \code{"variables"} a list
of named elements passed to \code{variables} and \code{"by"} a list of named elements
used for creating a relevant \code{datagrid} and whose names are passed to \code{by}.
\code{variables_list}'s default value, \code{"auto"}, calls
\code{variables_to_contrast(interactions = TRUE, cross = FALSE)} while
\code{"no_interaction"} is a shortcut for
\code{variables_to_contrast(interactions = FALSE)}. \code{"cross"} calls
\code{variables_to_contrast(interactions = TRUE, cross = TRUE)}
You can also provide custom specifications (see examples).
By default, \emph{average marginal contrasts} are computed: contrasts are computed
using a counterfactual grid for each value of the variable of interest,
before averaging the results. \emph{Marginal contrasts at the mean} could be
obtained by indicating \code{newdata = "mean"}. Other assumptions are possible,
see the help file of \code{marginaleffects::avg_comparisons()}.
For more information, see \code{vignette("marginal_tidiers", "broom.helpers")}.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
# Average Marginal Contrasts
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
tidyr::uncount(n) \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
mod <- glm(
Survived ~ Class + Age + Sex,
data = df, family = binomial
)
tidy_marginal_contrasts(mod)
tidy_plus_plus(mod, tidy_fun = tidy_marginal_contrasts)
mod2 <- lm(Petal.Length ~ poly(Petal.Width, 2) + Species, data = iris)
tidy_marginal_contrasts(mod2)
tidy_marginal_contrasts(
mod2,
variables_list = variables_to_predict(
mod2,
continuous = 3,
categorical = "pairwise"
)
)
# Model with interactions
mod3 <- glm(
Survived ~ Sex * Age + Class,
data = df, family = binomial
)
tidy_marginal_contrasts(mod3)
tidy_marginal_contrasts(mod3, "no_interaction")
tidy_marginal_contrasts(mod3, "cross")
tidy_marginal_contrasts(
mod3,
variables_list = list(
list(variables = list(Class = "pairwise"), by = list(Sex = unique)),
list(variables = list(Age = "all")),
list(variables = list(Class = "sequential", Sex = "reference"))
)
)
mod4 <- lm(Sepal.Length ~ Petal.Length * Petal.Width + Species, data = iris)
tidy_marginal_contrasts(mod4)
tidy_marginal_contrasts(
mod4,
variables_list = list(
list(
variables = list(Species = "sequential"),
by = list(Petal.Length = c(2, 5))
),
list(
variables = list(Petal.Length = 2),
by = list(Species = unique, Petal.Width = 2:4)
)
)
)
# Marginal Contrasts at the Mean
tidy_marginal_contrasts(mod, newdata = "mean")
tidy_marginal_contrasts(mod3, newdata = "mean")
\dontshow{\}) # examplesIf}
}
\seealso{
\code{marginaleffects::avg_comparisons()}, \code{tidy_avg_comparisons()}
Other marginal_tieders:
\code{\link{tidy_all_effects}()},
\code{\link{tidy_avg_comparisons}()},
\code{\link{tidy_avg_slopes}()},
\code{\link{tidy_ggpredict}()},
\code{\link{tidy_marginal_means}()},
\code{\link{tidy_marginal_predictions}()},
\code{\link{tidy_margins}()}
}
\concept{marginal_tieders}
broom.helpers/man/model_get_terms.Rd 0000644 0001762 0000144 00000004001 14464175037 017252 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_get_terms.R
\name{model_get_terms}
\alias{model_get_terms}
\alias{model_get_terms.default}
\alias{model_get_terms.brmsfit}
\alias{model_get_terms.glmmTMB}
\alias{model_get_terms.model_fit}
\alias{model_get_terms.betareg}
\title{Get the terms of a model}
\usage{
model_get_terms(model)
\method{model_get_terms}{default}(model)
\method{model_get_terms}{brmsfit}(model)
\method{model_get_terms}{glmmTMB}(model)
\method{model_get_terms}{model_fit}(model)
\method{model_get_terms}{betareg}(model)
}
\arguments{
\item{model}{a model object}
}
\description{
Return the result of \code{\link[stats:terms]{stats::terms()}} applied to the model
or \code{NULL} if it is not possible to get terms from \code{model}.
}
\details{
For models fitted with \code{glmmTMB::glmmTMB()}, it will return a terms object
taking into account all components ("cond" and "zi"). For a more
restricted terms object, please refer to \code{glmmTMB::terms.glmmTMB()}.
}
\examples{
lm(hp ~ mpg + factor(cyl), mtcars) \%>\%
model_get_terms()
}
\seealso{
\code{\link[stats:terms]{stats::terms()}}
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/supported_models.Rd 0000644 0001762 0000144 00000007021 14464175037 017476 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/data.R
\docType{data}
\name{supported_models}
\alias{supported_models}
\title{Listing of Supported Models}
\format{
A data frame with one row per supported model
\describe{
\item{model}{Model}
\item{notes}{Notes}
}
}
\usage{
supported_models
}
\description{
Listing of Supported Models
}
\section{Supported models}{
\tabular{ll}{
model \tab notes \cr
\code{betareg::betareg()} \tab Use \code{tidy_parameters()} as \code{tidy_fun} with \code{component} argument to control with coefficients to return. \verb{broom::tidy() does not support the }exponentiate\verb{argument for betareg models, use}tidy_parameters() instead.` \cr
\code{biglm::bigglm()} \tab \cr
\code{biglmm::bigglm()} \tab \cr
\code{brms::brm()} \tab \code{broom.mixed} package required \cr
\code{cmprsk::crr()} \tab Limited support. It is recommended to use \code{tidycmprsk::crr()} instead. \cr
\code{fixest::feglm()} \tab May fail with R <= 4.0. \cr
\code{fixest::femlm()} \tab May fail with R <= 4.0. \cr
\code{fixest::feNmlm()} \tab May fail with R <= 4.0. \cr
\code{fixest::feols()} \tab May fail with R <= 4.0. \cr
\code{gam::gam()} \tab \cr
\code{geepack::geeglm()} \tab \cr
\code{glmmTMB::glmmTMB()} \tab \code{broom.mixed} package required \cr
\code{lavaan::lavaan()} \tab Limited support for categorical variables \cr
\code{lfe::felm()} \tab \cr
\code{lme4::glmer.nb()} \tab \code{broom.mixed} package required \cr
\code{lme4::glmer()} \tab \code{broom.mixed} package required \cr
\code{lme4::lmer()} \tab \code{broom.mixed} package required \cr
\code{logitr::logitr()} \tab Requires logitr >= 0.8.0 \cr
\code{MASS::glm.nb()} \tab \cr
\code{MASS::polr()} \tab \cr
\code{mgcv::gam()} \tab Use default tidier \code{broom::tidy()} for smooth terms only, or \code{gtsummary::tidy_gam()} to include parametric terms \cr
\code{mice::mira} \tab Limited support. If \code{mod} is a \code{mira} object, use \code{tidy_plus_plus(mod, tidy_fun = function(x, ...) mice::pool(x) \%>\% mice::tidy(...))} \cr
\code{multgee::nomLORgee()} \tab Experimental support. Use \code{tidy_multgee()} as \code{tidy_fun}. \cr
\code{multgee::ordLORgee()} \tab Experimental support. Use \code{tidy_multgee()} as \code{tidy_fun}. \cr
\code{nnet::multinom()} \tab \cr
\code{ordinal::clm()} \tab Limited support for models with nominal predictors. \cr
\code{ordinal::clmm()} \tab Limited support for models with nominal predictors. \cr
\code{parsnip::model_fit} \tab Supported as long as the type of model and the engine is supported. \cr
\code{plm::plm()} \tab \cr
\code{pscl::hurdle()} \tab Use \code{tidy_zeroinfl()} as \code{tidy_fun}. \cr
\code{pscl::zeroinfl()} \tab Use \code{tidy_zeroinfl()} as \code{tidy_fun}. \cr
\code{rstanarm::stan_glm()} \tab \code{broom.mixed} package required \cr
\code{stats::aov()} \tab Reference rows are not relevant for such models. \cr
\code{stats::glm()} \tab \cr
\code{stats::lm()} \tab \cr
\code{stats::nls()} \tab Limited support \cr
\code{survey::svycoxph()} \tab \cr
\code{survey::svyglm()} \tab \cr
\code{survey::svyolr()} \tab \cr
\code{survival::clogit()} \tab \cr
\code{survival::coxph()} \tab \cr
\code{survival::survreg()} \tab \cr
\code{tidycmprsk::crr()} \tab \cr
\code{VGAM::vglm()} \tab Limited support. It is recommended to use \code{tidy_parameters()} as \code{tidy_fun}. \cr
}
}
\keyword{datasets}
broom.helpers/man/model_get_nlevels.Rd 0000644 0001762 0000144 00000002734 14360056067 017577 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_get_nlevels.R
\name{model_get_nlevels}
\alias{model_get_nlevels}
\alias{model_get_nlevels.default}
\title{Get the number of levels for each factor used in \code{xlevels}}
\usage{
model_get_nlevels(model)
\method{model_get_nlevels}{default}(model)
}
\arguments{
\item{model}{a model object}
}
\value{
a tibble with two columns: \code{"variable"} and \code{"var_nlevels"}
}
\description{
Get the number of levels for each factor used in \code{xlevels}
}
\examples{
lm(hp ~ mpg + factor(cyl), mtcars) \%>\%
model_get_nlevels()
}
\seealso{
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/model_get_model_frame.Rd 0000644 0001762 0000144 00000004175 14360056067 020402 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_get_model_frame.R
\name{model_get_model_frame}
\alias{model_get_model_frame}
\alias{model_get_model_frame.default}
\alias{model_get_model_frame.coxph}
\alias{model_get_model_frame.survreg}
\alias{model_get_model_frame.biglm}
\alias{model_get_model_frame.model_fit}
\alias{model_get_model_frame.fixest}
\title{Get the model frame of a model}
\usage{
model_get_model_frame(model)
\method{model_get_model_frame}{default}(model)
\method{model_get_model_frame}{coxph}(model)
\method{model_get_model_frame}{survreg}(model)
\method{model_get_model_frame}{biglm}(model)
\method{model_get_model_frame}{model_fit}(model)
\method{model_get_model_frame}{fixest}(model)
}
\arguments{
\item{model}{a model object}
}
\description{
The structure of the object returned by \code{\link[stats:model.frame]{stats::model.frame()}}
could slightly differ for certain types of models.
\code{model_get_model_frame()} will always return an object
with the same data structure or \code{NULL} if it is not possible
to compute model frame from \code{model}.
}
\examples{
lm(hp ~ mpg + factor(cyl), mtcars) \%>\%
model_get_model_frame() \%>\%
head()
}
\seealso{
\code{\link[stats:model.frame]{stats::model.frame()}}
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/tidy_add_pairwise_contrasts.Rd 0000644 0001762 0000144 00000010111 14464175037 021664 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_add_pairwise_contrasts.R
\name{tidy_add_pairwise_contrasts}
\alias{tidy_add_pairwise_contrasts}
\title{Add pairwise contrasts for categorical variables}
\usage{
tidy_add_pairwise_contrasts(
x,
variables = all_categorical(),
keep_model_terms = FALSE,
pairwise_reverse = TRUE,
contrasts_adjust = NULL,
conf.level = attr(x, "conf.level"),
emmeans_args = list(),
model = tidy_get_model(x),
quiet = FALSE
)
}
\arguments{
\item{x}{a tidy tibble}
\item{variables}{a vector indicating the name of variables
for those pairwise contrasts should be added.
Accepts \link[dplyr:select]{tidyselect} syntax. Default is \code{\link[=all_categorical]{all_categorical()}}}
\item{keep_model_terms}{keep terms from the model?}
\item{pairwise_reverse}{determines whether to use \code{"pairwise"} (if \code{TRUE})
or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}}
\item{contrasts_adjust}{optional adjustment method when computing contrasts,
see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \code{emmeans} default)}
\item{conf.level}{confidence level, by default use the value indicated
previously in \code{\link[=tidy_and_attach]{tidy_and_attach()}}}
\item{emmeans_args}{list of additional parameter to pass to
\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts}
\item{model}{the corresponding model, if not attached to \code{x}}
\item{quiet}{logical argument whether broom.helpers should not return
a message when requested output cannot be generated. Default is \code{FALSE}}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Computes pairwise contrasts with \code{\link[emmeans:emmeans]{emmeans::emmeans()}} and add them to the
results tibble. Works only with models supported by \code{emmeans}, see
\code{vignette("models", package = "emmeans")}.
}
\note{
If the \code{contrasts} column is not yet available in \code{x},
\code{\link[=tidy_add_contrasts]{tidy_add_contrasts()}} will be automatically applied.
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
For multi-components models, such as zero-inflated Poisson or beta
regression, support of pairwise contrasts is still experimental.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
if (.assert_package("emmeans", boolean = TRUE)) {
mod1 <- lm(Sepal.Length ~ Species, data = iris)
mod1 \%>\%
tidy_and_attach() \%>\%
tidy_add_pairwise_contrasts()
mod1 \%>\%
tidy_and_attach() \%>\%
tidy_add_pairwise_contrasts(pairwise_reverse = FALSE)
mod1 \%>\%
tidy_and_attach() \%>\%
tidy_add_pairwise_contrasts(keep_model_terms = TRUE)
mod1 \%>\%
tidy_and_attach() \%>\%
tidy_add_pairwise_contrasts(contrasts_adjust = "none")
if (.assert_package("gtsummary", boolean = TRUE)) {
mod2 <- glm(
response ~ age + trt + grade,
data = gtsummary::trial,
family = binomial
)
mod2 \%>\%
tidy_and_attach(exponentiate = TRUE) \%>\%
tidy_add_pairwise_contrasts()
}
}
\dontshow{\}) # examplesIf}
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_n}()},
\code{\link{tidy_add_reference_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_disambiguate_terms}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/dot-clean_backticks.Rd 0000644 0001762 0000144 00000001231 14357760764 017777 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/helpers.R
\name{.clean_backticks}
\alias{.clean_backticks}
\title{Remove backticks around variable names}
\usage{
.clean_backticks(x, variable_names = x)
}
\arguments{
\item{x}{a character vector to be cleaned}
\item{variable_names}{list of variable names,
could be obtained with
\link[=model_list_variables]{model_list_variables(only_variable = TRUE)}
to properly take into account interaction only terms/variables}
}
\description{
Remove backticks around variable names
}
\seealso{
Other other_helpers:
\code{\link{.escape_regex}()}
}
\concept{other_helpers}
broom.helpers/man/model_identify_variables.Rd 0000644 0001762 0000144 00000005767 14360056067 021144 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_identify_variables.R
\name{model_identify_variables}
\alias{model_identify_variables}
\alias{model_identify_variables.default}
\alias{model_identify_variables.lavaan}
\alias{model_identify_variables.aov}
\alias{model_identify_variables.clm}
\alias{model_identify_variables.clmm}
\alias{model_identify_variables.gam}
\alias{model_identify_variables.model_fit}
\alias{model_identify_variables.logitr}
\title{Identify for each coefficient of a model the corresponding variable}
\usage{
model_identify_variables(model)
\method{model_identify_variables}{default}(model)
\method{model_identify_variables}{lavaan}(model)
\method{model_identify_variables}{aov}(model)
\method{model_identify_variables}{clm}(model)
\method{model_identify_variables}{clmm}(model)
\method{model_identify_variables}{gam}(model)
\method{model_identify_variables}{model_fit}(model)
\method{model_identify_variables}{logitr}(model)
}
\arguments{
\item{model}{a model object}
}
\value{
A tibble with four columns:
\itemize{
\item \code{term}: coefficients of the model
\item \code{variable}: the corresponding variable
\item \code{var_class}: class of the variable (cf. \code{\link[stats:checkMFClasses]{stats::.MFclass()}})
\item \code{var_type}: \code{"continuous"}, \code{"dichotomous"} (categorical variable with 2 levels),
\code{"categorical"} (categorical variable with 3 or more levels), \code{"intercept"}
or \code{"interaction"}
\item \code{var_nlevels}: number of original levels for categorical variables
}
}
\description{
It will also identify interaction terms and intercept(s).
}
\examples{
Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) \%>\%
glm(
Survived ~ Class + Age * Sex,
data = ., weights = .$n,
family = binomial
) \%>\%
model_identify_variables()
iris \%>\%
lm(
Sepal.Length ~ poly(Sepal.Width, 2) + Species,
data = .,
contrasts = list(Species = contr.sum)
) \%>\%
model_identify_variables()
}
\seealso{
\code{\link[=tidy_identify_variables]{tidy_identify_variables()}}
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/tidy_parameters.Rd 0000644 0001762 0000144 00000002752 14464175037 017310 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/custom_tidiers.R
\name{tidy_parameters}
\alias{tidy_parameters}
\title{Tidy a model with parameters package}
\usage{
tidy_parameters(x, conf.int = TRUE, conf.level = 0.95, ...)
}
\arguments{
\item{x}{a model}
\item{conf.int}{logical indicating whether or not to include a confidence
interval in the tidied output}
\item{conf.level}{the confidence level to use for the confidence interval}
\item{...}{additional parameters passed to \code{\link[parameters:model_parameters]{parameters::model_parameters()}}}
}
\description{
Use \code{\link[parameters:model_parameters]{parameters::model_parameters()}} to tidy a model and apply
\code{parameters::standardize_names(style = "broom")} to the output
}
\note{
For \code{\link[betareg:betareg]{betareg::betareg()}}, the component column in the results is standardized
with \code{\link[broom:reexports]{broom::tidy()}}, using \code{"mean"} and \code{"precision"} values.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
if (.assert_package("parameters", boolean = TRUE)) {
lm(Sepal.Length ~ Sepal.Width + Species, data = iris) \%>\%
tidy_parameters()
}
\dontshow{\}) # examplesIf}
}
\seealso{
Other custom_tieders:
\code{\link{tidy_broom}()},
\code{\link{tidy_multgee}()},
\code{\link{tidy_with_broom_or_parameters}()},
\code{\link{tidy_zeroinfl}()}
}
\concept{custom_tieders}
broom.helpers/man/tidy_add_n.Rd 0000644 0001762 0000144 00000013564 14457461242 016213 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_add_n.R
\name{tidy_add_n}
\alias{tidy_add_n}
\title{Add the (weighted) number of observations}
\usage{
tidy_add_n(x, model = tidy_get_model(x))
}
\arguments{
\item{x}{a tidy tibble}
\item{model}{the corresponding model, if not attached to \code{x}}
}
\description{
Add the number of observations in a new column \code{n_obs}, taking into account any
weights if they have been defined.
}
\details{
For continuous variables, it corresponds to all valid observations
contributing to the model.
For categorical variables coded with treatment or sum contrasts,
each model term could be associated to only one level of the original
categorical variable. Therefore, \code{n_obs} will correspond to the number of
observations associated with that level. \code{n_obs} will also be computed for
reference rows. For polynomial contrasts (defined with \code{\link[stats:contrast]{stats::contr.poly()}}),
all levels will contribute to the computation of each model term. Therefore,
\code{n_obs} will be equal to the total number of observations. For Helmert and custom
contrasts, only rows contributing positively (i.e. with a positive contrast)
to the computation of a term will be considered for estimating \code{n_obs}. The
result could therefore be difficult to interpret. For a better understanding
of which observations are taken into account to compute \code{n_obs} values, you
could look at \code{\link[=model_compute_terms_contributions]{model_compute_terms_contributions()}}.
For interaction terms, only rows contributing to all the terms of the
interaction will be considered to compute \code{n_obs}.
For binomial logistic models, \code{tidy_add_n()} will also return the
corresponding number of events (\code{n_event}) for each term, taking into account
any defined weights. Observed proportions could be obtained as \code{n_obs / n_event}.
Similarly, a number of events will be computed for multinomial logistic
models (\code{nnet::multinom()}) for each level of the outcome (\code{y.level}),
corresponding to the number of observations equal to that outcome level.
For Poisson models, \code{n_event} will be equal to the number of counts per term.
In addition, a third column \code{exposure} will be computed. If no offset is
defined, exposure is assumed to be equal to 1 (eventually multiplied by
weights) per observation. If an offset is defined, \code{exposure} will be equal
to the (weighted) sum of the exponential of the offset (as a reminder, to
model the effect of \code{x} on the ratio \code{y / z}, a Poisson model will be defined
as \code{glm(y ~ x + offset(log(z)), family = poisson)}). Observed rates could be
obtained with \code{n_event / exposure}.
For Cox models (\code{\link[survival:coxph]{survival::coxph()}}), an individual could be coded
with several observations (several rows). \code{n_obs} will correspond to the weighted
number of observations which could be different from the number of
individuals. \code{tidy_add_n()} will also compute a (weighted) number of events
(\code{n_event}) according to the definition of the \code{\link[survival:Surv]{survival::Surv()}} object.
Exposure time is also returned in \code{exposure} column. It is equal to the
(weighted) sum of the time variable if only one variable time is passed to
\code{\link[survival:Surv]{survival::Surv()}}, and to the (weighted) sum of \code{time2 - time} if two time
variables are defined in \code{\link[survival:Surv]{survival::Surv()}}.
For competing risk regression models (\code{\link[tidycmprsk:crr]{tidycmprsk::crr()}}), \code{n_event} takes
into account only the event of interest defined by \code{failcode.}
The (weighted) total number of observations (\code{N_obs}), of events (\code{N_event}) and
of exposure time (\code{Exposure}) are stored as attributes of the returned
tibble.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
lm(Petal.Length ~ ., data = iris) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
lm(Petal.Length ~ ., data = iris, contrasts = list(Species = contr.sum)) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
lm(Petal.Length ~ ., data = iris, contrasts = list(Species = contr.poly)) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
lm(Petal.Length ~ poly(Sepal.Length, 2), data = iris) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
df \%>\%
glm(
Survived ~ Class + Age + Sex,
data = ., weights = .$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.helmert")
) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
df \%>\%
glm(
Survived ~ Class * (Age:Sex),
data = ., weights = .$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.helmert")
) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
glm(response ~ age + grade * trt, gtsummary::trial, family = poisson) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
glm(
response ~ trt * grade + offset(log(ttdeath)),
gtsummary::trial,
family = poisson
) \%>\%
tidy_and_attach() \%>\%
tidy_add_n()
\dontshow{\}) # examplesIf}
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_pairwise_contrasts}()},
\code{\link{tidy_add_reference_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_disambiguate_terms}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/dot-select_to_varnames.Rd 0000644 0001762 0000144 00000002210 14357760764 020552 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/select_utilities.R
\name{.select_to_varnames}
\alias{.select_to_varnames}
\title{Variable selector}
\usage{
.select_to_varnames(
select,
data = NULL,
var_info = NULL,
arg_name = NULL,
select_single = FALSE
)
}
\arguments{
\item{select}{A single object selecting variables, e.g. \code{c(age, stage)},
\code{starts_with("age")}}
\item{data}{A data frame to select columns from. Default is NULL}
\item{var_info}{A data frame of variable names and attributes. May also pass
a character vector of variable names. Default is NULL}
\item{arg_name}{Optional string indicating the source argument name. This
helps in the error messaging. Default is NULL.}
\item{select_single}{Logical indicating whether the result must be a single
variable. Default is \code{FALSE}}
}
\value{
A character vector of variable names
}
\description{
Function takes \code{select()}-like inputs and converts the selector to
a character vector of variable names. Functions accepts tidyselect syntax,
and additional selector functions defined within the package
}
broom.helpers/man/tidy_marginal_predictions.Rd 0000644 0001762 0000144 00000015605 14370455163 021340 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/marginal_tidiers.R
\name{tidy_marginal_predictions}
\alias{tidy_marginal_predictions}
\alias{variables_to_predict}
\alias{plot_marginal_predictions}
\title{Marginal Predictions with \code{marginaleffects::avg_predictions()}}
\usage{
tidy_marginal_predictions(
x,
variables_list = "auto",
conf.int = TRUE,
conf.level = 0.95,
...
)
variables_to_predict(
model,
interactions = TRUE,
categorical = unique,
continuous = stats::fivenum
)
plot_marginal_predictions(x, variables_list = "auto", conf.level = 0.95, ...)
}
\arguments{
\item{x}{a model}
\item{variables_list}{a list whose elements will be sequentially passed to
\code{variables} in \code{marginaleffects::avg_predictions()} (see details below);
alternatively, it could also be the string \code{"auto"} (default) or
\code{"no_interaction"}}
\item{conf.int}{logical indicating whether or not to include a confidence
interval in the tidied output}
\item{conf.level}{the confidence level to use for the confidence interval}
\item{...}{additional parameters passed to
\code{marginaleffects::avg_predictions()}}
\item{model}{a model}
\item{interactions}{should combinations of variables corresponding to
interactions be returned?}
\item{categorical}{default value for categorical variables}
\item{continuous}{default value for continuous variables}
}
\description{
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}
Use \code{marginaleffects::avg_predictions()} to estimate marginal predictions for
each variable of a model and return a tibble tidied in a way that it could
be used by \code{broom.helpers} functions.
See \code{marginaleffects::avg_predictions()} for a list of supported models.
}
\details{
Marginal predictions are obtained by calling, for each variable,
\code{marginaleffects::avg_predictions()} with the same variable being used for
the \code{variables} and the \code{by} argument.
Considering a categorical variable named \code{cat}, \code{tidy_marginal_predictions()}
will call \code{avg_predictions(model, variables = list(cat = unique), by = "cat")}
to obtain average marginal predictions for this variable.
Considering a continuous variable named \code{cont}, \code{tidy_marginal_predictions()}
will call \code{avg_predictions(model, variables = list(cont = "fivenum"), by = "cont")}
to obtain average marginal predictions for this variable at the minimum, the
first quartile, the median, the third quartile and the maximum of the observed
values of \code{cont}.
By default, \emph{average marginal predictions} are computed: predictions are made
using a counterfactual grid for each value of the variable of interest,
before averaging the results. \emph{Marginal predictions at the mean} could be
obtained by indicating \code{newdata = "mean"}. Other assumptions are possible,
see the help file of \code{marginaleffects::avg_predictions()}.
\code{tidy_marginal_predictions()} will compute marginal predictions for each
variable or combination of variables, before stacking the results in a unique
tibble. This is why \code{tidy_marginal_predictions()} has a \code{variables_list}
argument consisting of a list of specifications that will be passed
sequentially to the \code{variables} argument of \code{marginaleffects::avg_predictions()}.
The helper function \code{variables_to_predict()} could be used to automatically
generate a suitable list to be used with \code{variables_list}. By default, all
unique values are retained for categorical variables and \code{fivenum} (i.e.
Tukey's five numbers, minimum, quartiles and maximum) for continuous variables.
When \code{interactions = FALSE}, \code{variables_to_predict()} will return a list of
all individual variables used in the model. If \code{interactions = FALSE}, it
will search for higher order combinations of variables (see
\code{model_list_higher_order_variables()}).
\code{variables_list}'s default value, \code{"auto"}, calls
\code{variables_to_predict(interactions = TRUE)} while \code{"no_interaction"} is a
shortcut for \code{variables_to_predict(interactions = FALSE)}.
You can also provide custom specifications (see examples).
\code{plot_marginal_predictions()} works in a similar way and returns a list of
plots that could be combined with \code{patchwork::wrap_plots()} (see examples).
For more information, see \code{vignette("marginal_tidiers", "broom.helpers")}.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
# Average Marginal Predictions
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
tidyr::uncount(n) \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
mod <- glm(
Survived ~ Class + Age + Sex,
data = df, family = binomial
)
tidy_marginal_predictions(mod)
tidy_plus_plus(mod, tidy_fun = tidy_marginal_predictions)
if (require("patchwork")) {
plot_marginal_predictions(mod) \%>\% patchwork::wrap_plots()
plot_marginal_predictions(mod) \%>\%
patchwork::wrap_plots() &
ggplot2::scale_y_continuous(limits = c(0, 1), label = scales::percent)
}
mod2 <- lm(Petal.Length ~ poly(Petal.Width, 2) + Species, data = iris)
tidy_marginal_predictions(mod2)
if (require("patchwork")) {
plot_marginal_predictions(mod2) \%>\% patchwork::wrap_plots()
}
tidy_marginal_predictions(
mod2,
variables_list = variables_to_predict(mod2, continuous = "threenum")
)
tidy_marginal_predictions(
mod2,
variables_list = list(
list(Petal.Width = c(0, 1, 2, 3)),
list(Species = unique)
)
)
tidy_marginal_predictions(
mod2,
variables_list = list(list(Species = unique, Petal.Width = 1:3))
)
# Model with interactions
mod3 <- glm(
Survived ~ Sex * Age + Class,
data = df, family = binomial
)
tidy_marginal_predictions(mod3)
tidy_marginal_predictions(mod3, "no_interaction")
if (require("patchwork")) {
plot_marginal_predictions(mod3) \%>\%
patchwork::wrap_plots()
plot_marginal_predictions(mod3, "no_interaction") \%>\%
patchwork::wrap_plots()
}
tidy_marginal_predictions(
mod3,
variables_list = list(
list(Class = unique, Sex = "Female"),
list(Age = unique)
)
)
# Marginal Predictions at the Mean
tidy_marginal_predictions(mod, newdata = "mean")
if (require("patchwork")) {
plot_marginal_predictions(mod, newdata = "mean") \%>\%
patchwork::wrap_plots()
}
\dontshow{\}) # examplesIf}
}
\seealso{
\code{marginaleffects::avg_predictions()}
Other marginal_tieders:
\code{\link{tidy_all_effects}()},
\code{\link{tidy_avg_comparisons}()},
\code{\link{tidy_avg_slopes}()},
\code{\link{tidy_ggpredict}()},
\code{\link{tidy_marginal_contrasts}()},
\code{\link{tidy_marginal_means}()},
\code{\link{tidy_margins}()}
}
\concept{marginal_tieders}
broom.helpers/man/model_get_assign.Rd 0000644 0001762 0000144 00000003207 14360056067 017407 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_get_assign.R
\name{model_get_assign}
\alias{model_get_assign}
\alias{model_get_assign.default}
\alias{model_get_assign.vglm}
\alias{model_get_assign.model_fit}
\title{Get the assign attribute of model matrix of a model}
\usage{
model_get_assign(model)
\method{model_get_assign}{default}(model)
\method{model_get_assign}{vglm}(model)
\method{model_get_assign}{model_fit}(model)
}
\arguments{
\item{model}{a model object}
}
\description{
Return the assign attribute attached to the object returned by
\code{\link[stats:model.matrix]{stats::model.matrix()}}.
}
\examples{
lm(hp ~ mpg + factor(cyl), mtcars) \%>\%
model_get_assign()
}
\seealso{
\code{\link[stats:model.matrix]{stats::model.matrix()}}
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/model_list_contrasts.Rd 0000644 0001762 0000144 00000003751 14463417025 020342 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_list_contrasts.R
\name{model_list_contrasts}
\alias{model_list_contrasts}
\alias{model_list_contrasts.default}
\title{List contrasts used by a model}
\usage{
model_list_contrasts(model)
\method{model_list_contrasts}{default}(model)
}
\arguments{
\item{model}{a model object}
}
\value{
A tibble with three columns:
\itemize{
\item \code{variable}: variable name
\item \code{contrasts}: contrasts used
\item \code{contrasts_type}: type of contrasts
("treatment", "sum", "poly", "helmert", "sdiff, "other" or "no.contrast")
\item \code{reference}: for variables with treatment, SAS
or sum contrasts, position of the reference level
}
}
\description{
List contrasts used by a model
}
\details{
For models with no intercept, no contrasts will be applied to one of the
categorical variable. In such case, one dummy term will be returned for each
level of the categorical variable.
}
\examples{
glm(
am ~ mpg + factor(cyl),
data = mtcars,
family = binomial,
contrasts = list(`factor(cyl)` = contr.sum)
) \%>\%
model_list_contrasts()
}
\seealso{
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/dot-generic_selector.Rd 0000644 0001762 0000144 00000001752 14357760764 020223 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/select_utilities.R
\name{.generic_selector}
\alias{.generic_selector}
\alias{.is_selector_scoped}
\title{Generate a custom selector function}
\usage{
.generic_selector(variable_column, select_column, select_expr, fun_name)
.is_selector_scoped(variable_column, select_column)
}
\arguments{
\item{variable_column}{string indicating column variable names are stored}
\item{select_column}{character vector of columns used in the \verb{select_expr=} argument}
\item{select_expr}{unquoted predicate command to subset a data frame to select variables}
\item{fun_name}{quoted name of function where \code{.generic_selector()} is being used.
This helps with error messaging.}
}
\value{
custom selector functions
}
\description{
Generate a custom selector function
}
\details{
\code{.is_selector_scoped()} checks if a selector has been properly registered
in \code{env_variable_type$df_var_info}.
}
broom.helpers/man/tidy_add_header_rows.Rd 0000644 0001762 0000144 00000007157 14457461241 020260 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_add_header_rows.R
\name{tidy_add_header_rows}
\alias{tidy_add_header_rows}
\title{Add header rows variables with several terms}
\usage{
tidy_add_header_rows(
x,
show_single_row = NULL,
model = tidy_get_model(x),
quiet = FALSE,
strict = FALSE
)
}
\arguments{
\item{x}{a tidy tibble}
\item{show_single_row}{a vector indicating the names of binary
variables that should be displayed on a single row.
Accepts \link[dplyr:select]{tidyselect} syntax. Default is \code{NULL}.
See also \code{\link[=all_dichotomous]{all_dichotomous()}}}
\item{model}{the corresponding model, if not attached to \code{x}}
\item{quiet}{logical argument whether broom.helpers should not return
a message when requested output cannot be generated. Default is \code{FALSE}}
\item{strict}{logical argument whether broom.helpers should return an error
when requested output cannot be generated. Default is \code{FALSE}}
}
\description{
For variables with several terms (usually categorical variables but
could also be the case of continuous variables with polynomial terms
or splines), \code{tidy_add_header_rows()} will add an additional row
per variable, where \code{label} will be equal to \code{var_label}.
These additional rows could be identified with \code{header_row} column.
}
\details{
The \code{show_single_row} argument allows to specify a list
of dichotomous variables that should be displayed on a single row
instead of two rows.
The added \code{header_row} column will be equal to:
\itemize{
\item \code{TRUE} for an header row;
\item \code{FALSE} for a normal row of a variable with an header row;
\item \code{NA} for variables without an header row.
}
If the \code{label} column is not yet available in \code{x},
\code{\link[=tidy_add_term_labels]{tidy_add_term_labels()}} will be automatically applied.
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
if (.assert_package("gtsummary", boolean = TRUE)) {
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes")))
res <- df \%>\%
glm(
Survived ~ Class + Age + Sex,
data = ., weights = .$n, family = binomial,
contrasts = list(Age = contr.sum, Class = "contr.SAS")
) \%>\%
tidy_and_attach() \%>\%
tidy_add_variable_labels(labels = list(Class = "Custom label for Class")) \%>\%
tidy_add_reference_rows()
res \%>\% tidy_add_header_rows()
res \%>\% tidy_add_header_rows(show_single_row = all_dichotomous())
glm(
response ~ stage + grade * trt,
gtsummary::trial,
family = binomial,
contrasts = list(
stage = contr.treatment(4, base = 3),
grade = contr.treatment(3, base = 2),
trt = contr.treatment(2, base = 2)
)
) \%>\%
tidy_and_attach() \%>\%
tidy_add_reference_rows() \%>\%
tidy_add_header_rows()
}
\dontshow{\}) # examplesIf}
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_n}()},
\code{\link{tidy_add_pairwise_contrasts}()},
\code{\link{tidy_add_reference_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_disambiguate_terms}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/model_get_coefficients_type.Rd 0000644 0001762 0000144 00000006464 14360056067 021635 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_get_coefficients_type.R
\name{model_get_coefficients_type}
\alias{model_get_coefficients_type}
\alias{model_get_coefficients_type.default}
\alias{model_get_coefficients_type.glm}
\alias{model_get_coefficients_type.negbin}
\alias{model_get_coefficients_type.geeglm}
\alias{model_get_coefficients_type.fixest}
\alias{model_get_coefficients_type.biglm}
\alias{model_get_coefficients_type.glmerMod}
\alias{model_get_coefficients_type.clogit}
\alias{model_get_coefficients_type.polr}
\alias{model_get_coefficients_type.multinom}
\alias{model_get_coefficients_type.svyolr}
\alias{model_get_coefficients_type.clm}
\alias{model_get_coefficients_type.clmm}
\alias{model_get_coefficients_type.coxph}
\alias{model_get_coefficients_type.crr}
\alias{model_get_coefficients_type.tidycrr}
\alias{model_get_coefficients_type.model_fit}
\alias{model_get_coefficients_type.LORgee}
\title{Get coefficient type}
\usage{
model_get_coefficients_type(model)
\method{model_get_coefficients_type}{default}(model)
\method{model_get_coefficients_type}{glm}(model)
\method{model_get_coefficients_type}{negbin}(model)
\method{model_get_coefficients_type}{geeglm}(model)
\method{model_get_coefficients_type}{fixest}(model)
\method{model_get_coefficients_type}{biglm}(model)
\method{model_get_coefficients_type}{glmerMod}(model)
\method{model_get_coefficients_type}{clogit}(model)
\method{model_get_coefficients_type}{polr}(model)
\method{model_get_coefficients_type}{multinom}(model)
\method{model_get_coefficients_type}{svyolr}(model)
\method{model_get_coefficients_type}{clm}(model)
\method{model_get_coefficients_type}{clmm}(model)
\method{model_get_coefficients_type}{coxph}(model)
\method{model_get_coefficients_type}{crr}(model)
\method{model_get_coefficients_type}{tidycrr}(model)
\method{model_get_coefficients_type}{model_fit}(model)
\method{model_get_coefficients_type}{LORgee}(model)
}
\arguments{
\item{model}{a model object}
}
\description{
Indicate the type of coefficient among "generic", "logistic",
"poisson", "relative_risk" or "prop_hazard".
}
\examples{
lm(hp ~ mpg + factor(cyl), mtcars) \%>\%
model_get_coefficients_type()
Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) \%>\%
glm(Survived ~ Class + Age * Sex, data = ., weights = .$n, family = binomial) \%>\%
model_get_coefficients_type()
}
\seealso{
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/tidy_attach_model.Rd 0000644 0001762 0000144 00000005022 14357760764 017572 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_and_attach.R
\name{tidy_attach_model}
\alias{tidy_attach_model}
\alias{tidy_and_attach}
\alias{tidy_get_model}
\alias{tidy_detach_model}
\title{Attach a full model to the tibble of model terms}
\usage{
tidy_attach_model(x, model, .attributes = NULL)
tidy_and_attach(
model,
tidy_fun = tidy_with_broom_or_parameters,
conf.int = TRUE,
conf.level = 0.95,
exponentiate = FALSE,
...
)
tidy_get_model(x)
tidy_detach_model(x)
}
\arguments{
\item{x}{a tibble of model terms}
\item{model}{a model to be attached/tidied}
\item{.attributes}{named list of additional attributes to be attached to \code{x}}
\item{tidy_fun}{option to specify a custom tidier function}
\item{conf.int}{logical indicating whether or not to include a confidence
interval in the tidied output}
\item{conf.level}{level of confidence for confidence intervals (default: 95\%)}
\item{exponentiate}{logical indicating whether or not to exponentiate the
coefficient estimates. This is typical for logistic, Poisson and Cox models,
but a bad idea if there is no log or logit link; defaults to \code{FALSE}}
\item{...}{other arguments passed to \code{tidy_fun()}}
}
\description{
To facilitate the use of broom helpers with pipe, it is recommended to
attach the original model as an attribute to the tibble of model terms
generated by \code{broom::tidy()}.
}
\details{
\code{tidy_attach_model()} attach the model to a tibble already generated while
\code{tidy_and_attach()} will apply \code{broom::tidy()} and attach the model.
Use \code{tidy_get_model()} to get the model attached to the tibble and
\code{tidy_detach_model()} to remove the attribute containing the model.
}
\examples{
mod <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris)
tt <- mod \%>\%
tidy_and_attach(conf.int = TRUE)
tt
tidy_get_model(tt)
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_n}()},
\code{\link{tidy_add_pairwise_contrasts}()},
\code{\link{tidy_add_reference_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_disambiguate_terms}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/tidy_plus_plus.Rd 0000644 0001762 0000144 00000017314 14457461243 017172 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_plus_plus.R
\name{tidy_plus_plus}
\alias{tidy_plus_plus}
\title{Tidy a model and compute additional informations}
\usage{
tidy_plus_plus(
model,
tidy_fun = tidy_with_broom_or_parameters,
conf.int = TRUE,
conf.level = 0.95,
exponentiate = FALSE,
variable_labels = NULL,
term_labels = NULL,
interaction_sep = " * ",
categorical_terms_pattern = "{level}",
disambiguate_terms = TRUE,
disambiguate_sep = ".",
add_reference_rows = TRUE,
no_reference_row = NULL,
add_pairwise_contrasts = FALSE,
pairwise_variables = all_categorical(),
keep_model_terms = FALSE,
pairwise_reverse = TRUE,
contrasts_adjust = NULL,
emmeans_args = list(),
add_estimate_to_reference_rows = TRUE,
add_header_rows = FALSE,
show_single_row = NULL,
add_n = TRUE,
intercept = FALSE,
include = everything(),
keep_model = FALSE,
quiet = FALSE,
strict = FALSE,
...
)
}
\arguments{
\item{model}{a model to be attached/tidied}
\item{tidy_fun}{option to specify a custom tidier function}
\item{conf.int}{should confidence intervals be computed? (see \code{\link[broom:reexports]{broom::tidy()}})}
\item{conf.level}{level of confidence for confidence intervals (default: 95\%)}
\item{exponentiate}{logical indicating whether or not to exponentiate the
coefficient estimates. This is typical for logistic, Poisson and Cox models,
but a bad idea if there is no log or logit link; defaults to \code{FALSE}.}
\item{variable_labels}{a named list or a named vector of custom variable labels}
\item{term_labels}{a named list or a named vector of custom term labels}
\item{interaction_sep}{separator for interaction terms}
\item{categorical_terms_pattern}{a \link[glue:glue]{glue pattern} for
labels of categorical terms with treatment or sum contrasts
(see \code{\link[=model_list_terms_levels]{model_list_terms_levels()}})}
\item{disambiguate_terms}{should terms be disambiguated with
\code{\link[=tidy_disambiguate_terms]{tidy_disambiguate_terms()}}? (default \code{TRUE})}
\item{disambiguate_sep}{separator for \code{\link[=tidy_disambiguate_terms]{tidy_disambiguate_terms()}}}
\item{add_reference_rows}{should reference rows be added?}
\item{no_reference_row}{variables (accepts \link[dplyr:select]{tidyselect} notation)
for those no reference row should be added, when \code{add_reference_rows = TRUE}}
\item{add_pairwise_contrasts}{apply \code{\link[=tidy_add_pairwise_contrasts]{tidy_add_pairwise_contrasts()}}?
\ifelse{html}{\href{https://lifecycle.r-lib.org/articles/stages.html#experimental}{\figure{lifecycle-experimental.svg}{options: alt='[Experimental]'}}}{\strong{[Experimental]}}}
\item{pairwise_variables}{variables to add pairwise contrasts
(accepts \link[dplyr:select]{tidyselect} notation)}
\item{keep_model_terms}{keep original model terms for variables where
pairwise contrasts are added? (default is \code{FALSE})}
\item{pairwise_reverse}{determines whether to use \code{"pairwise"} (if \code{TRUE})
or \code{"revpairwise"} (if \code{FALSE}), see \code{\link[emmeans:contrast]{emmeans::contrast()}}}
\item{contrasts_adjust}{optional adjustment method when computing contrasts,
see \code{\link[emmeans:contrast]{emmeans::contrast()}} (if \code{NULL}, use \code{emmeans} default)}
\item{emmeans_args}{list of additional parameter to pass to
\code{\link[emmeans:emmeans]{emmeans::emmeans()}} when computing pairwise contrasts}
\item{add_estimate_to_reference_rows}{should an estimate value be added
to reference rows?}
\item{add_header_rows}{should header rows be added?}
\item{show_single_row}{variables that should be displayed
on a single row (accepts \link[dplyr:select]{tidyselect} notation), when
\code{add_header_rows} is \code{TRUE}}
\item{add_n}{should the number of observations be added?}
\item{intercept}{should the intercept(s) be included?}
\item{include}{variables to include. Accepts \link[dplyr:select]{tidyselect}
syntax. Use \code{-} to remove a variable. Default is \code{everything()}.
See also \code{\link[=all_continuous]{all_continuous()}}, \code{\link[=all_categorical]{all_categorical()}}, \code{\link[=all_dichotomous]{all_dichotomous()}}
and \code{\link[=all_interaction]{all_interaction()}}}
\item{keep_model}{should the model be kept as an attribute of the final
result?}
\item{quiet}{logical argument whether broom.helpers should not return
a message when requested output cannot be generated. Default is \code{FALSE}}
\item{strict}{logical argument whether broom.helpers should return an error
when requested output cannot be generated. Default is \code{FALSE}}
\item{...}{other arguments passed to \code{tidy_fun()}}
}
\description{
This function will apply sequentially:
\itemize{
\item \code{\link[=tidy_and_attach]{tidy_and_attach()}}
\item \code{\link[=tidy_disambiguate_terms]{tidy_disambiguate_terms()}}
\item \code{\link[=tidy_identify_variables]{tidy_identify_variables()}}
\item \code{\link[=tidy_add_contrasts]{tidy_add_contrasts()}}
\item \code{\link[=tidy_add_reference_rows]{tidy_add_reference_rows()}}
\item \code{\link[=tidy_add_pairwise_contrasts]{tidy_add_pairwise_contrasts()}}
\item \code{\link[=tidy_add_estimate_to_reference_rows]{tidy_add_estimate_to_reference_rows()}}
\item \code{\link[=tidy_add_variable_labels]{tidy_add_variable_labels()}}
\item \code{\link[=tidy_add_term_labels]{tidy_add_term_labels()}}
\item \code{\link[=tidy_add_header_rows]{tidy_add_header_rows()}}
\item \code{\link[=tidy_add_n]{tidy_add_n()}}
\item \code{\link[=tidy_remove_intercept]{tidy_remove_intercept()}}
\item \code{\link[=tidy_select_variables]{tidy_select_variables()}}
\item \code{\link[=tidy_add_coefficients_type]{tidy_add_coefficients_type()}}
\item \code{\link[=tidy_detach_model]{tidy_detach_model()}}
}
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
ex1 <- lm(Sepal.Length ~ Sepal.Width + Species, data = iris) \%>\%
tidy_plus_plus()
ex1
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(
Survived = factor(Survived, c("No", "Yes"))
) \%>\%
labelled::set_variable_labels(
Class = "Passenger's class",
Sex = "Gender"
)
ex2 <- glm(
Survived ~ Class + Age * Sex,
data = df, weights = df$n,
family = binomial
) \%>\%
tidy_plus_plus(
exponentiate = TRUE,
add_reference_rows = FALSE,
categorical_terms_pattern = "{level} / {reference_level}",
add_n = TRUE
)
ex2
if (.assert_package("gtsummary", boolean = TRUE)) {
ex3 <-
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
)
) \%>\%
tidy_plus_plus(
exponentiate = TRUE,
variable_labels = c(age = "Age (in years)"),
add_header_rows = TRUE,
show_single_row = all_dichotomous(),
term_labels = c("poly(age, 3)3" = "Cubic age"),
keep_model = TRUE
)
ex3
}
\dontshow{\}) # examplesIf}
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_n}()},
\code{\link{tidy_add_pairwise_contrasts}()},
\code{\link{tidy_add_reference_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_add_variable_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_disambiguate_terms}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/tidy_add_variable_labels.Rd 0000644 0001762 0000144 00000005163 14357760764 021073 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/tidy_add_variable_labels.R
\name{tidy_add_variable_labels}
\alias{tidy_add_variable_labels}
\title{Add variable labels}
\usage{
tidy_add_variable_labels(
x,
labels = NULL,
interaction_sep = " * ",
model = tidy_get_model(x),
quiet = FALSE,
strict = FALSE
)
}
\arguments{
\item{x}{a tidy tibble}
\item{labels}{an optional named list or named vector of
custom variable labels}
\item{interaction_sep}{separator for interaction terms}
\item{model}{the corresponding model, if not attached to \code{x}}
\item{quiet}{logical argument whether broom.helpers should not return
a message when requested output cannot be generated. Default is \code{FALSE}}
\item{strict}{logical argument whether broom.helpers should return an error
when requested output cannot be generated. Default is \code{FALSE}}
}
\description{
Will add variable labels in a \code{var_label} column, based on:
\enumerate{
\item labels provided in \code{labels} argument if provided;
\item variable labels defined in the original data frame with
the \code{label} attribute (cf. \code{\link[labelled:var_label]{labelled::var_label()}});
\item variable name otherwise.
}
}
\details{
If the \code{variable} column is not yet available in \code{x},
\code{\link[=tidy_identify_variables]{tidy_identify_variables()}} will be automatically applied.
It is possible to pass a custom label for an interaction
term in \code{labels} (see examples).
}
\examples{
df <- Titanic \%>\%
dplyr::as_tibble() \%>\%
dplyr::mutate(Survived = factor(Survived, c("No", "Yes"))) \%>\%
labelled::set_variable_labels(
Class = "Passenger's class",
Sex = "Sex"
)
df \%>\%
glm(Survived ~ Class * Age * Sex, data = ., weights = .$n, family = binomial) \%>\%
tidy_and_attach() \%>\%
tidy_add_variable_labels(
labels = list(
"(Intercept)" = "Custom intercept",
Sex = "Gender",
"Class:Age" = "Custom label"
)
)
}
\seealso{
Other tidy_helpers:
\code{\link{tidy_add_coefficients_type}()},
\code{\link{tidy_add_contrasts}()},
\code{\link{tidy_add_estimate_to_reference_rows}()},
\code{\link{tidy_add_header_rows}()},
\code{\link{tidy_add_n}()},
\code{\link{tidy_add_pairwise_contrasts}()},
\code{\link{tidy_add_reference_rows}()},
\code{\link{tidy_add_term_labels}()},
\code{\link{tidy_attach_model}()},
\code{\link{tidy_disambiguate_terms}()},
\code{\link{tidy_identify_variables}()},
\code{\link{tidy_plus_plus}()},
\code{\link{tidy_remove_intercept}()},
\code{\link{tidy_select_variables}()}
}
\concept{tidy_helpers}
broom.helpers/man/model_get_model_matrix.Rd 0000644 0001762 0000144 00000006055 14464175037 020617 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_get_model_matrix.R
\name{model_get_model_matrix}
\alias{model_get_model_matrix}
\alias{model_get_model_matrix.default}
\alias{model_get_model_matrix.multinom}
\alias{model_get_model_matrix.clm}
\alias{model_get_model_matrix.brmsfit}
\alias{model_get_model_matrix.glmmTMB}
\alias{model_get_model_matrix.plm}
\alias{model_get_model_matrix.biglm}
\alias{model_get_model_matrix.model_fit}
\alias{model_get_model_matrix.fixest}
\alias{model_get_model_matrix.LORgee}
\alias{model_get_model_matrix.betareg}
\title{Get the model matrix of a model}
\usage{
model_get_model_matrix(model, ...)
\method{model_get_model_matrix}{default}(model, ...)
\method{model_get_model_matrix}{multinom}(model, ...)
\method{model_get_model_matrix}{clm}(model, ...)
\method{model_get_model_matrix}{brmsfit}(model, ...)
\method{model_get_model_matrix}{glmmTMB}(model, ...)
\method{model_get_model_matrix}{plm}(model, ...)
\method{model_get_model_matrix}{biglm}(model, ...)
\method{model_get_model_matrix}{model_fit}(model, ...)
\method{model_get_model_matrix}{fixest}(model, ...)
\method{model_get_model_matrix}{LORgee}(model, ...)
\method{model_get_model_matrix}{betareg}(model, ...)
}
\arguments{
\item{model}{a model object}
\item{...}{additional arguments passed to \code{\link[stats:model.matrix]{stats::model.matrix()}}}
}
\description{
The structure of the object returned by \code{\link[stats:model.matrix]{stats::model.matrix()}}
could slightly differ for certain types of models.
\code{model_get_model_matrix()} will always return an object
with the same structure as \code{\link[stats:model.matrix]{stats::model.matrix.default()}}.
}
\details{
For models fitted with \code{glmmTMB::glmmTMB()}, it will return a model matrix
taking into account all components ("cond", "zi" and "disp"). For a more
restricted model matrix, please refer to \code{glmmTMB::model.matrix.glmmTMB()}.
For \code{\link[plm:plm]{plm::plm()}} models, constant columns are not removed.
}
\examples{
lm(hp ~ mpg + factor(cyl), mtcars) \%>\%
model_get_model_matrix() \%>\%
head()
}
\seealso{
\code{\link[stats:model.matrix]{stats::model.matrix()}}
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/select_helpers.Rd 0000644 0001762 0000144 00000004523 14457461241 017110 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/select_helpers.R
\name{select_helpers}
\alias{select_helpers}
\alias{all_continuous}
\alias{all_dichotomous}
\alias{all_categorical}
\alias{all_interaction}
\alias{all_ran_pars}
\alias{all_ran_vals}
\alias{all_intercepts}
\alias{all_contrasts}
\title{Select helper functions}
\usage{
all_continuous()
all_dichotomous()
all_categorical(dichotomous = TRUE)
all_interaction()
all_ran_pars()
all_ran_vals()
all_intercepts()
all_contrasts(contrasts_type = NULL)
}
\arguments{
\item{dichotomous}{Logical indicating whether to include dichotomous variables.
Default is \code{TRUE}}
\item{contrasts_type}{type of contrast to select. When \code{NULL}, all variables with a
contrast will be selected. Default is \code{NULL}. Select among contrast types
\code{c("treatment", "sum", "poly", "helmert", "other")}}
}
\value{
A character vector of column names selected
}
\description{
Set of functions to supplement the {tidyselect} set of
functions for selecting columns of data frames (and other items as well).
\itemize{
\item \code{all_continuous()} selects continuous variables
\item \code{all_categorical()} selects categorical (including \code{"dichotomous"}) variables
\item \code{all_dichotomous()} selects only type \code{"dichotomous"}
\item \code{all_interaction()} selects interaction terms from a regression model
\item \code{all_intercepts()} selects intercept terms from a regression model
\item \code{all_contrasts()} selects variables in regression model based on their type
of contrast
\item \code{all_ran_pars()} and \code{all_ran_vals()} for random-effect parameters and
values from a mixed model
(see \code{vignette("broom_mixed_intro", package = "broom.mixed")})
}
}
\examples{
\dontshow{if (interactive()) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf}
glm(response ~ age * trt + grade, gtsummary::trial, family = binomial) \%>\%
tidy_plus_plus(exponentiate = TRUE, include = all_categorical())
glm(response ~ age + trt + grade + stage,
gtsummary::trial,
family = binomial,
contrasts = list(trt = contr.SAS, grade = contr.sum, stage = contr.poly)
) \%>\%
tidy_plus_plus(
exponentiate = TRUE,
include = all_contrasts(c("treatment", "sum"))
)
\dontshow{\}) # examplesIf}
}
broom.helpers/man/model_get_model.Rd 0000644 0001762 0000144 00000003062 14360056067 017222 0 ustar ligges users % Generated by roxygen2: do not edit by hand
% Please edit documentation in R/model_get_model.R
\name{model_get_model}
\alias{model_get_model}
\alias{model_get_model.default}
\alias{model_get_model.mira}
\title{Get the model from model objects}
\usage{
model_get_model(model)
\method{model_get_model}{default}(model)
\method{model_get_model}{mira}(model)
}
\arguments{
\item{model}{a model object}
}
\description{
Most model objects are proper R model objects. There are, however, some
model objects that store the proper object internally (e.g. mice models).
This function extracts that model object in those cases.
}
\examples{
lm(hp ~ mpg + factor(cyl), mtcars) \%>\%
model_get_model()
}
\seealso{
Other model_helpers:
\code{\link{model_compute_terms_contributions}()},
\code{\link{model_get_assign}()},
\code{\link{model_get_coefficients_type}()},
\code{\link{model_get_contrasts}()},
\code{\link{model_get_model_frame}()},
\code{\link{model_get_model_matrix}()},
\code{\link{model_get_nlevels}()},
\code{\link{model_get_n}()},
\code{\link{model_get_offset}()},
\code{\link{model_get_pairwise_contrasts}()},
\code{\link{model_get_response_variable}()},
\code{\link{model_get_response}()},
\code{\link{model_get_terms}()},
\code{\link{model_get_weights}()},
\code{\link{model_get_xlevels}()},
\code{\link{model_identify_variables}()},
\code{\link{model_list_contrasts}()},
\code{\link{model_list_higher_order_variables}()},
\code{\link{model_list_terms_levels}()},
\code{\link{model_list_variables}()}
}
\concept{model_helpers}
broom.helpers/man/figures/ 0000755 0001762 0000144 00000000000 14357760764 015273 5 ustar ligges users broom.helpers/man/figures/lifecycle-defunct.svg 0000644 0001762 0000144 00000001704 14357760764 021403 0 ustar ligges users