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 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("devtools")
devtools::install_github("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 RStudio 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

815,730

Version

0.7.5

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

February 19th, 2021

Functions in broom (0.7.5)

augment.clm

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

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

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

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

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

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

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

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

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

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

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

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

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

Augment data with information from a(n) rlm object
augment.nlrq

Tidy a(n) nlrq object
augment.nls

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

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

Augment data with information from a(n) mjoint object
augment.glmRob

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

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

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

Augment data with information from a(n) rma object
finish_glance

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

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

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

Augment data with information from a(n) spatialreg object
fix_data_frame

Ensure an object is a data frame, with rownames moved into a column
augment.smooth.spline

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

Glance at a(n) factanal object
augment.rqs

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

Glance at a(n) cch object
glance.binDesign

Glance at a(n) binDesign object
glance.felm

Glance at a(n) felm object
glance.aov

Glance at a(n) lm object
augment.lmrob

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

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

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

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

Glance at a(n) coeftest object
glance.muhaz

Glance at a(n) muhaz object
augment.loess

Tidy a(n) loess object
augment.mfx

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

Glance at a(n) betamfx object
glance.crr

Glance at a(n) crr object
glance.mfx

Glance at a(n) mfx object
glance.rma

Glance at a(n) rma object
augment.stl

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

Glance at a(n) Arima object
glance.gmm

Glance at a(n) gmm object
glance.mjoint

Glance at a(n) mjoint object
augment.lmRob

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

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

Augment data with information from a(n) pam object
glance.survexp

Glance at a(n) survexp object
glance.rlm

Glance at a(n) rlm object
glance.survfit

Glance at a(n) survfit object
augment.plm

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

Tidiers for NULL inputs
augment.survreg

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

Glance at a(n) ivreg object
bootstrap

Set up bootstrap replicates of a dplyr operation
glance.survreg

Glance at a(n) survreg object
glance.svyglm

Glance at a(n) svyglm object
glance.rq

Glance at a(n) rq object
glance.pam

Glance at a(n) pam object
glance.garch

Tidy a(n) garch object
sp_tidiers

Tidy a(n) SpatialPolygonsDataFrame object
sparse_tidiers

Tidy a sparseMatrix object from the Matrix package
glance.lmodel2

Glance at a(n) lmodel2 object
glance.Mclust

Glance at a(n) Mclust object
glance.kmeans

Glance at a(n) kmeans object
tidy.drc

Tidy a(n) drc object
glance.betareg

Glance at a(n) betareg object
tidy.confusionMatrix

Tidy a(n) confusionMatrix object
tidy.factanal

Tidy a(n) factanal object
glance.clm

Glance at a(n) clm object
glance.margins

Glance at a(n) margins object
augment.polr

Augment data with information from a(n) polr object
glance.mlogit

Glance at a(n) mlogit object
glance.lmRob

Glance at a(n) lmRob object
tidy.coxph

Tidy a(n) coxph object
tidy.emmGrid

Tidy a(n) emmGrid object
tidy.ftable

(Deprecated) Tidy ftable objects
tidy.gam

Tidy a(n) gam object
tidy.htest

Tidy/glance a(n) htest object
augment.speedlm

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

Glance at a(n) biglm object
tidy.garch

Tidy a(n) garch object
tidy.gamlss

Tidy a(n) gamlss object
glance.pyears

Glance at a(n) pyears object
data.frame_tidiers

Tidiers for data.frame objects
glance.clmm

Glance at a(n) clmm object
glance.drc

Glance at a(n) drc object
glance.smooth.spline

Tidy a(n) smooth.spine object
glance.lavaan

Glance at a(n) lavaan object
tidy.margins

Tidy a(n) margins object
tidy.ivreg

Tidy a(n) ivreg object
glance.ridgelm

Glance at a(n) ridgelm object
glance.lmrob

Glance at a(n) lmrob object
summary_tidiers

(Deprecated) Tidy summaryDefault objects
glance.cv.glmnet

Glance at a(n) cv.glmnet object
reexports

Objects exported from other packages
glance.ergm

Glance at a(n) ergm object
tidy.btergm

Tidy a(n) btergm object
confint_tidy

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

Tidy a(n) ergm object
broom

Convert Statistical Objects into Tidy Tibbles
list_tidiers

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

Tidy a(n) Kendall object
tidy.table

Tidy a(n) table object
glance.nls

Glance at a(n) nls object
tidy.Rchoice

Tidy a(n) Rchoice object
glance.survdiff

Glance at a(n) survdiff object
tidy.Arima

Tidy a(n) Arima object
tidy.boot

Tidy a(n) boot object
tidy.ts

Tidy a(n) ts object
tidy.anova

Tidy a(n) anova object
durbinWatsonTest_tidiers

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

Tidy a(n) rma object
glance.fitdistr

Glance at a(n) fitdistr object
tidy.coeftest

Tidy a(n) coeftest object
glance.orcutt

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

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

Tidy a(n) map object
glance.sarlm

Glance at a(n) spatialreg object
glance.Rchoice

Glance at a(n) Rchoice object
glance.gam

Glance at a(n) gam object
glance.fixest

Glance at a(n) fixest object
tidy.lmRob

Tidy a(n) lmRob object
glance.lm

Glance at a(n) lm object
tidy.betareg

Tidy a(n) betareg object
tidy.dist

(Deprecated) Tidy dist objects
tidy.Mclust

Tidy a(n) Mclust object
glance.plm

Glance at a(n) plm object
tidy.crr

Tidy a(n) cmprsk object
tidy.muhaz

Tidy a(n) muhaz object
tidy.acf

Tidy a(n) acf object
glance.multinom

Glance at a(n) multinom object
tidy.biglm

Tidy a(n) biglm object
glance.glm

Glance at a(n) glm object
tidy.fixest

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

Glance at a(n) summary.lm object
tidy.lm.beta

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

Glance at a(n) geeglm object
tidy.roc

Tidy a(n) roc object
tidy.geeglm

Tidy a(n) geeglm object
tidy.pyears

Tidy a(n) pyears object
tidy.TukeyHSD

Tidy a(n) TukeyHSD object
tidy.nls

Tidy a(n) nls object
tidy.multinom

Tidying methods for multinomial logistic regression models
tidy.cv.glmnet

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

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

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

Tidy a(n) binWidth object
tidy.density

(Deprecated) Tidy density objects
glance.speedglm

Glance at a(n) speedglm object
glance.speedlm

Glance at a(n) speedlm object
tidy.speedglm

Tidy a(n) speedglm object
glance.coxph

Glance at a(n) coxph object
glance.aareg

Glance at a(n) aareg object
tidy.nlrq

Tidy a(n) nlrq object
glance.glmRob

Glance at a(n) glmRob object
tidy.survdiff

Tidy a(n) survdiff object
tidy.felm

Tidy a(n) felm object
glance.nlrq

Glance at a(n) nlrq object
tidy.mediate

Tidy a(n) mediate object
tidy.kde

Tidy a(n) kde object
tidy.kappa

Tidy a(n) kappa object
tidy.poLCA

Tidy a(n) poLCA object
tidy.glht

Tidy a(n) glht object
tidy.ridgelm

Tidy a(n) ridgelm object
tidy.mlogit

Tidying methods for logit models
tidy.lmodel2

Tidy a(n) lmodel2 object
tidy.cch

Tidy a(n) cch object
glance.glmnet

Glance at a(n) glmnet object
tidy.speedlm

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

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

Tidy a(n) rlm object
tidy.systemfit

Tidy a(n) systemfit object
tidy.polr

Tidy a(n) polr object
tidy.rq

Tidy a(n) rq object
tidy.rcorr

Tidy a(n) rcorr object
tidy.mfx

Tidy a(n) mfx object
tidy.survexp

Tidy a(n) survexp object
tidy.glmrob

Tidy a(n) glmrob object
glance.poLCA

Glance at a(n) poLCA object
tidy.varest

Tidy a(n) varest object
tidy.spec

Tidy a(n) spec object
tidy_svd

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

Tidy a(n) svyglm object
tidy.lmrob

Tidy a(n) lmrob object
tidy.svyolr

Tidy a(n) svyolr object
tidy.mlm

Tidy a(n) mlm object
tidy.zoo

Tidy a(n) zoo object
tidy_irlba

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

Tidy a(n) aovlist object
tidy_optim

Tidy a(n) optim object masquerading as list
tidy_xyz

Tidy a(n) xyz object masquerading as list
glance.polr

Glance at a(n) polr object
tidy.glmnet

Tidy a(n) glmnet object
tidy.orcutt

Tidy a(n) orcutt object
leveneTest_tidiers

Tidy/glance a(n) leveneTest object
glance_optim

Tidy a(n) optim object masquerading as list
glance.varest

Glance at a(n) varest object
tidy.numeric

Tidy atomic vectors
glance.svyolr

Glance at a(n) svyolr object
tidy.clm

Tidy a(n) clm object
tidy.lavaan

Tidy a(n) lavaan object
tidy.glmRob

Tidy a(n) glmRob object
tidy.cld

Tidy a(n) cld object
tidy.fitdistr

Tidy a(n) fitdistr object
tidy.aov

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

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

Tidy a(n) rqs object
tidy.lm

Tidy a(n) lm object
tidy.gmm

Tidy a(n) gmm object
tidy.clmm

Tidy a(n) clmm object
tidy.aareg

Tidy a(n) aareg object
tidy.betamfx

Tidy a(n) betamfx object
tidy.lsmobj

Tidy a(n) lsmobj object
tidy.manova

Tidy a(n) manova object
tidy.prcomp

Tidy a(n) prcomp object
tidy.sarlm

Tidying methods for spatially autoregressive models
tidy.glm

Tidy a(n) glm object
tidy.epi.2by2

Tidy a(n) epi.2by2 object
tidy.mjoint

Tidy a(n) mjoint object
tidy.pam

Tidy a(n) pam object
tidy.kmeans

Tidy a(n) kmeans object
tidy.plm

Tidy a(n) plm object
tidy.summary_emm

Tidy a(n) summary_emm object
tidy.ref.grid

Tidy a(n) ref.grid object
tidy.survfit

Tidy a(n) survfit object
tidy.mle2

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

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

Tidy a(n) regsubsets object
tidy.survreg

Tidy a(n) survreg object