Learn R Programming

⚠️There's a newer version (1.0.4) of this package.Take me there.

broom

Overview

broom summarizes key information about models in tidy tibble()s. broom provides three verbs to make it convenient to interact with model objects:

  • tidy() summarizes information about model components
  • glance() reports information about the entire model
  • augment() adds informations about observations to a dataset

For a detailed introduction, please see vignette("broom").

broom tidies 100+ models from popular modelling packages and almost all of the model objects in the stats package that comes with base R. vignette("available-methods") lists method availabilty.

If you aren’t familiar with tidy data structures and want to know how they can make your life easier, we highly recommend reading Hadley Wickham’s Tidy Data.

Installation

# we recommend installing the entire tidyverse, which includes broom:
install.packages("tidyverse")

# alternatively, to install just broom:
install.packages("broom")

# to get the development version from GitHub:
install.packages("devtools")
devtools::install_github("tidyverse/broom")

If you find a bug, please file a minimal reproducible example in the issues.

Usage

tidy() produces a tibble() where each row contains information about an important component of the model. For regression models, this often corresponds to regression coefficients. This is can be useful if you want to inspect a model or create custom visualizations.

library(broom)

fit <- lm(Sepal.Width ~ Petal.Length + Petal.Width, iris)
tidy(fit)
#> # A tibble: 3 x 5
#>   term         estimate std.error statistic  p.value
#>   <chr>           <dbl>     <dbl>     <dbl>    <dbl>
#> 1 (Intercept)     3.59     0.0937     38.3  2.51e-78
#> 2 Petal.Length   -0.257    0.0669     -3.84 1.80e- 4
#> 3 Petal.Width     0.364    0.155       2.35 2.01e- 2

glance() returns a tibble with exactly one row of goodness of fitness measures and related statistics. This is useful to check for model misspecification and to compare many models.

glance(fit)
#> # A tibble: 1 x 12
#>   r.squared adj.r.squared sigma statistic p.value    df logLik   AIC   BIC
#>       <dbl>         <dbl> <dbl>     <dbl>   <dbl> <dbl>  <dbl> <dbl> <dbl>
#> 1     0.213         0.202 0.389      19.9 2.24e-8     2  -69.8  148.  160.
#> # … with 3 more variables: deviance <dbl>, df.residual <int>, nobs <int>

augment adds columns to a dataset, containing information such as fitted values, residuals or cluster assignments. All columns added to a dataset have . prefix to prevent existing columns from being overwritten.

augment(fit, data = iris)
#> # A tibble: 150 x 11
#>    Sepal.Length Sepal.Width Petal.Length Petal.Width Species .fitted  .resid
#>           <dbl>       <dbl>        <dbl>       <dbl> <fct>     <dbl>   <dbl>
#>  1          5.1         3.5          1.4         0.2 setosa     3.30 -0.200 
#>  2          4.9         3            1.4         0.2 setosa     3.30  0.300 
#>  3          4.7         3.2          1.3         0.2 setosa     3.33  0.126 
#>  4          4.6         3.1          1.5         0.2 setosa     3.27  0.174 
#>  5          5           3.6          1.4         0.2 setosa     3.30 -0.300 
#>  6          5.4         3.9          1.7         0.4 setosa     3.30 -0.604 
#>  7          4.6         3.4          1.4         0.3 setosa     3.34 -0.0637
#>  8          5           3.4          1.5         0.2 setosa     3.27 -0.126 
#>  9          4.4         2.9          1.4         0.2 setosa     3.30  0.400 
#> 10          4.9         3.1          1.5         0.1 setosa     3.24  0.138 
#> # … with 140 more rows, and 4 more variables: .std.resid <dbl>, .hat <dbl>,
#> #   .sigma <dbl>, .cooksd <dbl>

Contributing

We welcome contributions of all types!

If you have never made a pull request to an R package before, broom is an excellent place to start. Find an issue with the Beginner Friendly tag and comment that you’d like to take it on and we’ll help you get started.

We encourage typo corrections, bug reports, bug fixes and feature requests. Feedback on the clarity of the documentation is especially valuable.

If you are interested in adding new tidiers methods to broom, please read vignette("adding-tidiers").

We have a Contributor Code of Conduct. By participating in broom you agree to abide by its terms.

Copy Link

Version

Install

install.packages('broom')

Monthly Downloads

815,730

Version

0.5.6

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

April 20th, 2020

Functions in broom (0.5.6)

augment.glm

Augment a(n) glm object
augment.nls

Augment data with information from a(n) nls object
augment.poLCA

Augment data with information from a(n) poLCA object
augment.prcomp

Augment data with information from a(n) prcomp object
augment.betareg

Augment data with information from a(n) betareg object
augment.plm

Augment data with information from a(n) plm object
augment.coxph

Augment data with information from a(n) coxph object
argument_glossary

Allowed argument names in tidiers
augment.Mclust

Augment data with information from a(n) Mclust object
brms_tidiers

Tidying methods for a brms model
finish_glance

Add logLik, AIC, BIC, and other common measurements to a glance of a prediction
bootstrap

Set up bootstrap replicates of a dplyr operation
broom

Convert Statistical Objects into Tidy Tibbles
glance.biglm

Glance at a(n) biglm object
glance.binDesign

Glance at a(n) binDesign object
column_glossary

Allowed column names in tidied tibbles
glance.lavaan

Glance at a(n) lavaan object
glance.kmeans

Glance at a(n) kmeans object
emmeans_tidiers

Tidy estimated marginal means (least-squares means) objects from the emmeans and lsmeans packages
fix_data_frame

Ensure an object is a data frame, with rownames moved into a column
durbinWatsonTest_tidiers

Tidy/glance a(n) durbinWatsonTest object
glance.nlrq

Glance at a(n) nlrq object
glance.nls

Glance at a(n) nls object
glance.factanal

Glance at a(n) factanal object
glance.poLCA

Augment data with information from a(n) poLCA object
glance.felm

Glance at a(n) felm object
glance.glm

Glance at a(n) glm object
glance.glmnet

Glance at a(n) glmnet object
glance.speedlm

Glance at a(n) speedlm object
augment.rlm

Augment a(n) rlm object
glance.survdiff

Glance at a(n) survdiff object
glance.pyears

Glance at a(n) pyears object
augment.htest

Augment data with information from a(n) htest object
glance.Gam

Glance at a(n) Gam object
augment.speedlm

Augment data with information from a(n) speedlm object
augment.rq

Augment data with information from a(n) rq object
glance.Mclust

Glance at a(n) Mclust object
augment.stl

Augment data with information from a(n) stl object
augment.ivreg

Augment data with information from a(n) ivreg object
glance.cch

Glance at a(n) cch object
augment.decomposed.ts

Augment data with information from a(n) decomposed.ts object
augment.kmeans

Augment data with information from a(n) kmeans object
augment.factanal

Augment data with information from a(n) factanal object
glance.survreg

Glance at a(n) survreg object
augment.loess

Tidy a(n) loess object
glance.coxph

Glance at a(n) coxph object
glance.gmm

Glance at a(n) gmm object
tidy.biglm

Tidy a(n) biglm object
sp_tidiers

Tidy a(n) SpatialPolygonsDataFrame object
nlme_tidiers

Tidying methods for mixed effects models
glance.ivreg

Glance at a(n) ivreg object
tidy.dist

Tidy a(n) dist object
augment.nlrq

Tidy a(n) nlrq object
tidy.gam

Tidy a(n) gam object
tidy.betareg

Tidy a(n) betareg object
rstanarm_tidiers

Tidying methods for an rstanarm model
tidy.ergm

Tidy a(n) ergm object
tidy.factanal

Tidy a(n) factanal object
tidy.felm

Tidy a(n) felm object
tidy.map

Tidy a(n) map object
tidy.manova

Tidy a(n) manova object
augment.survreg

Augment data with information from a(n) survreg object
glance_optim

Tidy a(n) optim object masquerading as list
augment.lm

Augment data with information from a(n) lm object
tidy.plm

Tidy a(n) plm object
tidy.pairwise.htest

Tidy a(n) pairwise.htest object
augment.rqs

Augment data with information from a(n) rqs object
mcmc_tidiers

Tidying methods for MCMC (Stan, JAGS, etc.) fits
glance.Arima

Glance at a(n) Arima object
tidy.geeglm

Tidy a(n) geeglm object
glance.aareg

Glance at a(n) aareg object
augment_columns

add fitted values, residuals, and other common outputs to an augment call
glance.betareg

Glance at a(n) betareg object
tidy.spec

Tidy a(n) spec object
glance.fitdistr

Glance at a(n) fitdistr object
tidy.speedlm

Tidy a(n) speedlm object
list_tidiers

Tidying methods for lists / returned values that are not S3 objects
tidy.aareg

Tidy a(n) aareg object
tidy.TukeyHSD

Tidy a(n) TukeyHSD object
glance.ridgelm

Glance at a(n) ridgelm object
tidy.survreg

Tidy a(n) survreg object
insert_NAs

insert a row of NAs into a data frame wherever another data frame has NAs
lme4_tidiers

Tidying methods for mixed effects models
matrix_tidiers

Tidiers for matrix objects
augment.smooth.spline

Tidy a(n) smooth.spline object
glance.rlm

Glance at a(n) rlm object
glance.gam

Glance at a(n) gam object
glance.ergm

Glance at a(n) ergm object
glance.lmodel2

Glance at a(n) lmodel2 object
data.frame_tidiers

Tidiers for data.frame objects
glance.lm

Glance at a(n) lm object
tidy.table

Tidy a(n) table object
confint_tidy

Calculate confidence interval as a tidy data frame
glance.cv.glmnet

Glance at a(n) cv.glmnet object
glance.garch

Tidy a(n) garch object
glance.orcutt

Glance at a(n) orcutt object
glance.muhaz

Glance at a(n) muhaz object
glance.survexp

Glance at a(n) survexp object
glance.plm

Glance at a(n) plm object
tidy.Kendall

Tidy a(n) Kendall object
tidy.aov

Tidy a(n) aov object
tidy.Mclust

Tidy a(n) Mclust object
tidy.binWidth

Tidy a(n) binWidth object
tidy.binDesign

Tidy a(n) binDesign object
tidy.confusionMatrix

Tidy a(n) confusionMatrix object
tidy.coxph

Tidy a(n) coxph object
glance.survfit

Glance at a(n) survfit object
reexports

Objects exported from other packages
rowwise_df_tidiers

Tidying methods for rowwise_dfs from dplyr, for tidying each row and recombining the results
tidy.gamlss

Tidy a(n) gamlss object
glance.multinom

Glance at a(n) multinom object
glance.rq

Glance at a(n) rq object
tidy.aovlist

Tidy a(n) aovlist object
tidy.coeftest

Tidy a(n) coeftest object
sparse_tidiers

Tidy a sparseMatrix object from the Matrix package
tidy.anova

Tidy a(n) anova object
tidy.acf

Tidy a(n) acf object
summary_tidiers

Tidy/glance a(n) summaryDefault object
tidy.confint.glht

Tidy a(n) confint.glht object
glance.smooth.spline

Tidy a(n) smooth.spine object
tidy.glht

Tidy a(n) glht object
null_tidiers

Tidiers for NULL inputs
tidy.fitdistr

Tidy a(n) fitdistr object
tidy.cv.glmnet

Tidy a(n) cv.glmnet object
tidy.ftable

Tidy a(n) ftable object
tidy.density

Tidy a(n) density object
tidy.lm

Tidy a(n) lm object
tidy.kappa

Tidy a(n) kappa object
tidy.kde

Tidy a(n) kde object
tidy.glm

Tidy a(n) glm object
tidy.multinom

Tidying methods for multinomial logistic regression models
tidy.nlrq

Tidy a(n) nlrq object
tidy.rq

Tidy a(n) rq object
tidy.garch

Tidy a(n) garch object
tidy.rqs

Tidy a(n) rqs object
tidy.polr

Tidying methods for ordinal logistic regression models
tidy.htest

Tidy/glance a(n) htest object
tidy.btergm

Tidy a(n) btergm object
tidy.Gam

Tidy a(n) Gam object
tidy.cch

Tidy a(n) cch object
tidy.Arima

Tidy a(n) Arima object
tidy.summary.glht

Tidy a(n) summary.glht object
tidy.ivreg

Tidy a(n) ivreg object
tidy.boot

Tidy a(n) boot object
tidy.cld

Tidy a(n) cld object
tidy.survdiff

Tidy a(n) survdiff object
tidy.mle2

Tidy a(n) mle2 object
tidy.lmodel2

Tidy a(n) lmodel2 object
tidy.glmnet

Tidy a(n) glmnet object
tidy.poLCA

Tidy a(n) poLCA object
tidy.kmeans

Tidy a(n) kmeans object
tidy.gmm

Tidy a(n) gmm object
tidy.lavaan

Tidy a(n) lavaan object
tidy.power.htest

Tidy a(n) power.htest object
tidy_svd

Tidy a(n) svd object masquerading as list
tidy.nls

Tidy a(n) nls object
tidy.pyears

Tidy a(n) pyears object
tidy.rcorr

Tidy a(n) rcorr object
tidy.prcomp

Tidy a(n) prcomp object
tidy.survexp

Tidy a(n) survexp object
tidy.muhaz

Tidy a(n) muhaz object
tidy.survfit

Tidy a(n) survfit object
tidy.numeric

Tidy atomic vectors
tidy.orcutt

Tidy a(n) orcutt object
tidy_xyz

Tidy a(n) xyz object masquerading as list
tidy.rlm

Tidy a(n) rlm object
tidy_irlba

Tidy a(n) irlba object masquerading as list
tidy.ridgelm

Tidy a(n) ridgelm object
tidy_optim

Tidy a(n) optim object masquerading as list
tidy.roc

Tidy a(n) roc object
tidy.zoo

Tidy a(n) zoo object
tidy.ts

Tidy a(n) ts object
augment.felm

Augment data with information from a(n) felm object