Learn R Programming

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 availability.

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 
# modeling set, which includes broom:
install.packages("tidymodels")

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

# to get the development version from GitHub:
install.packages("pak")
pak::pak("tidymodels/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(Volume ~ Girth + Height, trees)
tidy(fit)
#> # A tibble: 3 x 5
#>   term        estimate std.error statistic  p.value
#>   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
#> 1 (Intercept)  -58.0       8.64      -6.71 2.75e- 7
#> 2 Girth          4.71      0.264     17.8  8.22e-17
#> 3 Height         0.339     0.130      2.61 1.45e- 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.948         0.944  3.88      255. 1.07e-18     2  -84.5  177.  183.
#> # … 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 = trees)
#> # A tibble: 31 x 9
#>    Girth Height Volume .fitted .resid .std.resid   .hat .sigma   .cooksd
#>    <dbl>  <dbl>  <dbl>   <dbl>  <dbl>      <dbl>  <dbl>  <dbl>     <dbl>
#>  1   8.3     70   10.3    4.84  5.46      1.50   0.116    3.79 0.0978   
#>  2   8.6     65   10.3    4.55  5.75      1.60   0.147    3.77 0.148    
#>  3   8.8     63   10.2    4.82  5.38      1.53   0.177    3.78 0.167    
#>  4  10.5     72   16.4   15.9   0.526     0.140  0.0592   3.95 0.000409 
#>  5  10.7     81   18.8   19.9  -1.07     -0.294  0.121    3.95 0.00394  
#>  6  10.8     83   19.7   21.0  -1.32     -0.370  0.156    3.94 0.00840  
#>  7  11       66   15.6   16.2  -0.593    -0.162  0.115    3.95 0.00114  
#>  8  11       75   18.2   19.2  -1.05     -0.277  0.0515   3.95 0.00138  
#>  9  11.1     80   22.6   21.4   1.19      0.321  0.0920   3.95 0.00348  
#> 10  11.2     75   19.9   20.2  -0.288    -0.0759 0.0480   3.95 0.0000968
#> # … with 21 more rows

Contributing

We welcome contributions of all types!

For questions and discussions about tidymodels packages, modeling, and machine learning, please post on Posit Community. If you think you have encountered a bug, please submit an issue. Either way, learn how to create and share a reprex (a minimal, reproducible example), to clearly communicate about your code. Check out further details on contributing guidelines for tidymodels packages and how to get help.

If you have never directly contributed 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.

Generally, too, 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 tidier methods for new model objects, please read this article on the tidymodels website.

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

816,151

Version

1.0.4

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

March 11th, 2023

Functions in broom (1.0.4)

augment.Mclust

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

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

Augment data with information from a(n) gam object
augment.felm

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

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

Glance at a(n) lm object
augment.kmeans

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

Tidy a(n) smooth.spline object
augment.nlrq

Tidy a(n) nlrq object
augment.fixest

Augment data with information from a(n) fixest object
augment.glmrob

Augment data with information from a(n) glmrob object
augment.glm

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

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

Tidy a(n) lm object
glance.speedglm

Glance at a(n) speedglm object
augment.loess

Tidy a(n) loess object
augment.mfx

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

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

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

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

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

Augment data with information from a(n) speedlm object
glance.kmeans

Glance at a(n) kmeans object
augment.mjoint

Augment data with information from a(n) mjoint object
glance.smooth.spline

Tidy a(n) smooth.spine object
tidy.ref.grid

Tidy a(n) ref.grid object
augment.sarlm

Augment data with information from a(n) spatialreg object
glance.betamfx

Glance at a(n) betamfx object
augment.glmRob

Augment data with information from a(n) glmRob object
augment_columns

Add fitted values, residuals, and other common outputs to an augment call
bootstrap

Set up bootstrap replicates of a dplyr operation
augment.mlogit

Augment data with information from a(n) mlogit object
augment.betamfx

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

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

Augment data with information from a(n) drc object
tidy.fitdistr

Tidy a(n) fitdistr object
glance.rq

Glance at a(n) rq object
augment.lmrob

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

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

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

Glance at a(n) svyglm object
glance.orcutt

Glance at a(n) orcutt object
tidy.pairwise.htest

Tidy a(n) pairwise.htest object
glance.mfx

Glance at a(n) mfx object
fix_data_frame

Ensure an object is a data frame, with rownames moved into a column
glance.felm

Glance at a(n) felm object
augment.poLCA

Augment data with information from a(n) poLCA object
broom

Convert Statistical Objects into Tidy Tibbles
augment.rlm

Augment data with information from a(n) rlm object
null_tidiers

Tidiers for NULL inputs
tidy.btergm

Tidy a(n) btergm object
augment.survreg

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

(Deprecated) Calculate confidence interval as a tidy data frame
glance.betareg

Glance at a(n) betareg object
augment.polr

Augment data with information from a(n) polr object
augment.rma

Augment data with information from a(n) rma object
glance.biglm

Glance at a(n) biglm object
glance.factanal

Glance at a(n) factanal object
augment.lm

Augment data with information from a(n) lm object
list_tidiers

Tidying methods for lists / returned values that are not S3 objects
glance.multinom

Glance at a(n) multinom object
tidy.gmm

Tidy a(n) gmm object
glance.mlogit

Glance at a(n) mlogit object
finish_glance

(Deprecated) Add logLik, AIC, BIC, and other common measurements to a glance of a prediction
augment.rqs

Augment data with information from a(n) rqs object
glance.aareg

Glance at a(n) aareg object
glance.anova

Glance at a(n) anova object
glance.clm

Glance at a(n) clm object
glance.fitdistr

Glance at a(n) fitdistr object
tidy.gam

Tidy a(n) gam object
glance.pam

Glance at a(n) pam object
tidy.power.htest

Tidy a(n) power.htest object
glance.clmm

Glance at a(n) clmm object
augment.stl

Augment data with information from a(n) stl object
glance.binDesign

Glance at a(n) binDesign object
tidy.muhaz

Tidy a(n) muhaz object
glance.muhaz

Glance at a(n) muhaz object
tidy.crr

Tidy a(n) cmprsk object
glance.fixest

Glance at a(n) fixest object
glance.svyolr

Glance at a(n) svyolr object
glance.gmm

Glance at a(n) gmm object
glance.Arima

Glance at a(n) Arima object
glance.glmnet

Glance at a(n) glmnet object
glance.lavaan

Glance at a(n) lavaan object
glance.lmodel2

Glance at a(n) lmodel2 object
glance.crr

Glance at a(n) crr object
glance.Mclust

Glance at a(n) Mclust object
glance.margins

Glance at a(n) margins object
augment.lmRob

Augment data with information from a(n) lmRob object
glance.gam

Glance at a(n) gam object
glance.glmRob

Glance at a(n) glmRob object
augment.betareg

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

Augment data with information from a(n) clm object
glance.cv.glmnet

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

Glance at a(n) ivreg object
tidy.aareg

Tidy a(n) aareg object
glance.plm

Glance at a(n) plm object
tidy.betamfx

Tidy a(n) betamfx object
glance.poLCA

Glance at a(n) poLCA object
glance.speedlm

Glance at a(n) speedlm object
glance.rma

Glance at a(n) rma object
glance.lmrob

Glance at a(n) lmrob object
tidy.dist

(Deprecated) Tidy dist objects
glance.drc

Glance at a(n) drc object
tidy.summary_emm

Tidy a(n) summary_emm object
glance.mjoint

Glance at a(n) mjoint object
tidy.aov

Tidy a(n) aov object
glance.pyears

Glance at a(n) pyears object
tidy.anova

Tidy a(n) anova object
glance.survfit

Glance at a(n) survfit object
tidy.poLCA

Tidy a(n) poLCA object
glance.summary.lm

Glance at a(n) summary.lm object
glance.nlrq

Glance at a(n) nlrq object
tidy.mfx

Tidy a(n) mfx object
glance.polr

Glance at a(n) polr object
tidy.cch

Tidy a(n) cch object
glance.survreg

Glance at a(n) survreg object
tidy.rma

Tidy a(n) rma object
sp_tidiers

Tidy a(n) SpatialPolygonsDataFrame object
summary_tidiers

(Deprecated) Tidy summaryDefault objects
tidy.lavaan

Tidy a(n) lavaan object
tidy.acf

Tidy a(n) acf object
tidy.lmRob

Tidy a(n) lmRob object
tidy.lm.beta

Tidy a(n) lm.beta object
glance.lm

Glance at a(n) lm object
tidy.rcorr

Tidy a(n) rcorr object
glance.garch

Tidy a(n) garch object
leveneTest_tidiers

Tidy/glance a(n) leveneTest object
data.frame_tidiers

Tidiers for data.frame objects
glance_optim

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

Tidy a(n) margins object
tidy.betareg

Tidy a(n) betareg object
tidy.fixest

Tidy a(n) fixest object
reexports

Objects exported from other packages
glance.ergm

Glance at a(n) ergm object
durbinWatsonTest_tidiers

Tidy/glance a(n) durbinWatsonTest object
tidy.glmRob

Tidy a(n) glmRob object
tidy.aovlist

Tidy a(n) aovlist object
tidy.htest

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

Tidy a(n) drc object
glance.negbin

Glance at a(n) negbin object
glance.nls

Glance at a(n) nls object
tidy.cv.glmnet

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

Tidy a(n) table object
tidy.biglm

Tidy a(n) biglm object
glance.sarlm

Glance at a(n) spatialreg object
tidy.spec

Tidy a(n) spec object
glance.coeftest

Glance at a(n) coeftest object
tidy.Mclust

Tidy a(n) Mclust object
tidy.glmnet

Tidy a(n) glmnet object
tidy.regsubsets

Tidy a(n) regsubsets object
glance.cch

Glance at a(n) cch object
tidy.geeglm

Tidy a(n) geeglm object
tidy.Arima

Tidy a(n) Arima object
glance.ridgelm

Glance at a(n) ridgelm object
glance.coxph

Glance at a(n) coxph object
tidy.clm

Tidy a(n) clm object
tidy.Kendall

Tidy a(n) Kendall object
tidy.zoo

Tidy a(n) zoo object
tidy.clmm

Tidy a(n) clmm object
tidy.mlogit

Tidying methods for logit models
tidy.epi.2by2

Tidy a(n) epi.2by2 object
glance.rlm

Glance at a(n) rlm object
tidy.mediate

Tidy a(n) mediate object
tidy.summary.lm

Tidy a(n) summary.lm object
tidy.glmrob

Tidy a(n) glmrob object
tidy.boot

Tidy a(n) boot object
tidy.confusionMatrix

Tidy a(n) confusionMatrix object
tidy.Gam

Tidy a(n) Gam object
tidy.ergm

Tidy a(n) ergm object
tidy.pyears

Tidy a(n) pyears object
tidy.svyolr

Tidy a(n) svyolr object
tidy.polr

Tidy a(n) polr object
tidy.orcutt

Tidy a(n) orcutt object
tidy.survdiff

Tidy a(n) survdiff object
tidy.lmrob

Tidy a(n) lmrob object
glance.lmRob

Glance at a(n) lmRob object
tidy.ivreg

Tidy a(n) ivreg object
tidy.sarlm

Tidying methods for spatially autoregressive models
tidy.survexp

Tidy a(n) survexp object
tidy.garch

Tidy a(n) garch object
tidy.lmodel2

Tidy a(n) lmodel2 object
tidy.cld

Tidy a(n) cld object
tidy.emmGrid

Tidy a(n) emmGrid object
glance.survdiff

Glance at a(n) survdiff object
tidy.lsmobj

Tidy a(n) lsmobj object
glance.glm

Glance at a(n) glm object
glance.varest

Glance at a(n) varest object
tidy.manova

Tidy a(n) manova object
tidy.coxph

Tidy a(n) coxph object
tidy.numeric

Tidy atomic vectors
tidy.prcomp

Tidy a(n) prcomp object
tidy.map

Tidy a(n) map object
tidy.kde

Tidy a(n) kde object
tidy.density

(Deprecated) Tidy density objects
tidy.ftable

(Deprecated) Tidy ftable objects
tidy.pam

Tidy a(n) pam object
tidy.multinom

Tidying methods for multinomial logistic regression models
tidy.kmeans

Tidy a(n) kmeans object
tidy.negbin

Tidy a(n) negbin object
tidy.speedlm

Tidy a(n) speedlm object
tidy.mle2

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

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

Tidy a(n) speedglm object
tidy.plm

Tidy a(n) plm object
tidy.kappa

Tidy a(n) kappa object
tidy.ts

Tidy a(n) ts object
tidy.systemfit

Tidy a(n) systemfit object
tidy_svd

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

Tidy a(n) survreg object
tidy.mlm

Tidy a(n) mlm object
glance.geeglm

Glance at a(n) geeglm object
tidy_xyz

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

Tidy a(n) varest object
tidy.rqs

Tidy a(n) rqs object
tidy.svyglm

Tidy a(n) svyglm object
tidy.coeftest

Tidy a(n) coeftest object
tidy.rlm

Tidy a(n) rlm object
tidy.confint.glht

Tidy a(n) confint.glht object
glance.Gam

Glance at a(n) Gam object
glance.survexp

Glance at a(n) survexp object
tidy.binWidth

Tidy a(n) binWidth object
tidy.binDesign

Tidy a(n) binDesign object
tidy.glht

Tidy a(n) glht object
tidy.TukeyHSD

Tidy a(n) TukeyHSD object
tidy.nlrq

Tidy a(n) nlrq object
tidy.nls

Tidy a(n) nls object
tidy.factanal

Tidy a(n) factanal object
tidy.felm

Tidy a(n) felm object
tidy.rq

Tidy a(n) rq object
tidy.glm

Tidy a(n) glm object
tidy.ridgelm

Tidy a(n) ridgelm object
tidy.mjoint

Tidy a(n) mjoint object
tidy_irlba

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

Tidy a(n) roc object
tidy.survfit

Tidy a(n) survfit object
tidy_optim

Tidy a(n) optim object masquerading as list