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

1.0.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

July 1st, 2022

Functions in broom (1.0.0)

augment.factanal

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Tidy a(n) loess object
augment.lm

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

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

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

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

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

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

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

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

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

Tidy a(n) nlrq object
augment.pam

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

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

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

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

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

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

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

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

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

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

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

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

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

Augment data with information from a(n) rqs 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
confint_tidy

(Deprecated) Calculate confidence interval as a tidy data frame
broom

Convert Statistical Objects into Tidy Tibbles
glance.Mclust

Glance at a(n) Mclust object
fix_data_frame

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

Tidy/glance a(n) durbinWatsonTest object
finish_glance

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

Tidiers for data.frame objects
glance.Arima

Glance at a(n) Arima object
glance.aareg

Glance at a(n) aareg object
glance.betareg

Glance at a(n) betareg object
glance.binDesign

Glance at a(n) binDesign object
glance.clm

Glance at a(n) clm object
glance.biglm

Glance at a(n) biglm object
glance.cch

Glance at a(n) cch object
glance.aov

Glance at a(n) lm object
glance.betamfx

Glance at a(n) betamfx object
glance.clmm

Glance at a(n) clmm object
glance.anova

Glance at a(n) anova object
glance.drc

Glance at a(n) drc object
glance.ergm

Glance at a(n) ergm object
glance.felm

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

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

Glance at a(n) factanal object
glance.fixest

Glance at a(n) fixest object
glance.fitdistr

Glance at a(n) fitdistr object
glance.coeftest

Glance at a(n) coeftest object
glance.crr

Glance at a(n) crr object
glance.coxph

Glance at a(n) coxph object
glance.garch

Tidy a(n) garch object
glance.kmeans

Glance at a(n) kmeans object
glance.lavaan

Glance at a(n) lavaan object
glance.glmnet

Glance at a(n) glmnet object
glance.gmm

Glance at a(n) gmm object
glance.glmRob

Glance at a(n) glmRob object
glance.glm

Glance at a(n) glm object
glance.gam

Glance at a(n) gam object
glance.ivreg

Glance at a(n) ivreg object
glance.geeglm

Glance at a(n) geeglm object
glance.margins

Glance at a(n) margins object
glance.lm

Glance at a(n) lm object
glance.lmRob

Glance at a(n) lmRob object
glance.mlogit

Glance at a(n) mlogit object
glance.multinom

Glance at a(n) multinom object
glance.lmodel2

Glance at a(n) lmodel2 object
glance.muhaz

Glance at a(n) muhaz object
glance.negbin

Glance at a(n) negbin object
glance.mjoint

Glance at a(n) mjoint object
glance.mfx

Glance at a(n) mfx object
glance.rlm

Glance at a(n) rlm object
glance.nlrq

Glance at a(n) nlrq object
glance.ridgelm

Glance at a(n) ridgelm object
glance.nls

Glance at a(n) nls object
glance.pyears

Glance at a(n) pyears object
glance.poLCA

Glance at a(n) poLCA object
glance.polr

Glance at a(n) polr object
glance.orcutt

Glance at a(n) orcutt object
glance.pam

Glance at a(n) pam object
glance.plm

Glance at a(n) plm object
glance.lmrob

Glance at a(n) lmrob object
glance.speedglm

Glance at a(n) speedglm object
glance.speedlm

Glance at a(n) speedlm object
glance.survexp

Glance at a(n) survexp object
glance.rq

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

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

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

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

Glance at a(n) survdiff object
glance.sarlm

Glance at a(n) spatialreg object
leveneTest_tidiers

Tidy/glance a(n) leveneTest object
list_tidiers

Tidying methods for lists / returned values that are not S3 objects
glance_optim

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

Glance at a(n) svyolr object
glance.svyglm

Glance at a(n) svyglm object
glance.varest

Glance at a(n) varest object
glance.survfit

Glance at a(n) survfit object
glance.Gam

Glance at a(n) Gam object
tidy.rma

Tidy a(n) rma object
glance.survreg

Glance at a(n) survreg object
tidy.Kendall

Tidy a(n) Kendall object
tidy.aareg

Tidy a(n) aareg object
sparse_tidiers

Tidy a sparseMatrix object from the Matrix package
tidy.Mclust

Tidy a(n) Mclust object
tidy.TukeyHSD

Tidy a(n) TukeyHSD object
tidy.Arima

Tidy a(n) Arima object
summary_tidiers

(Deprecated) Tidy summaryDefault objects
sp_tidiers

Tidy a(n) SpatialPolygonsDataFrame object
null_tidiers

Tidiers for NULL inputs
reexports

Objects exported from other packages
tidy.biglm

Tidy a(n) biglm object
tidy.betareg

Tidy a(n) betareg object
tidy.acf

Tidy a(n) acf object
tidy.aovlist

Tidy a(n) aovlist object
tidy.binDesign

Tidy a(n) binDesign object
tidy.aov

Tidy a(n) aov object
tidy.boot

Tidy a(n) boot object
tidy.anova

Tidy a(n) anova object
tidy.binWidth

Tidy a(n) binWidth object
tidy.betamfx

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

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

Tidy a(n) cch object
tidy.btergm

Tidy a(n) btergm object
tidy.coxph

Tidy a(n) coxph object
tidy.confusionMatrix

Tidy a(n) confusionMatrix object
tidy.cld

Tidy a(n) cld object
tidy.clm

Tidy a(n) clm object
tidy.clmm

Tidy a(n) clmm object
tidy.coeftest

Tidy a(n) coeftest object
tidy.crr

Tidy a(n) cmprsk object
tidy.fitdistr

Tidy a(n) fitdistr object
tidy.drc

Tidy a(n) drc object
tidy.dist

(Deprecated) Tidy dist objects
tidy.felm

Tidy a(n) felm object
tidy.ergm

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

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

Tidy a(n) factanal object
tidy.density

(Deprecated) Tidy density objects
tidy.epi.2by2

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

Tidy a(n) emmGrid object
tidy.glmnet

Tidy a(n) glmnet object
tidy.glm

Tidy a(n) glm object
tidy.geeglm

Tidy a(n) geeglm object
tidy.glht

Tidy a(n) glht object
tidy.glmRob

Tidy a(n) glmRob object
tidy.fixest

Tidy a(n) fixest object
tidy.ftable

(Deprecated) Tidy ftable objects
tidy.gmm

Tidy a(n) gmm object
tidy.gam

Tidy a(n) gam object
tidy.garch

Tidy a(n) garch object
tidy.kappa

Tidy a(n) kappa object
tidy.kde

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

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

Tidy a(n) lavaan object
tidy.kmeans

Tidy a(n) kmeans object
tidy.lmRob

Tidy a(n) lmRob object
tidy.lm

Tidy a(n) lm object
tidy.lmodel2

Tidy a(n) lmodel2 object
tidy.htest

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

Tidy a(n) ivreg object
tidy.mjoint

Tidy a(n) mjoint object
tidy.map

Tidy a(n) map object
tidy.mediate

Tidy a(n) mediate object
tidy.mlm

Tidy a(n) mlm object
tidy.mle2

Tidy a(n) mle2 object
tidy.mlogit

Tidying methods for logit models
tidy.mfx

Tidy a(n) mfx object
tidy.manova

Tidy a(n) manova object
tidy.margins

Tidy a(n) margins object
tidy.lsmobj

Tidy a(n) lsmobj object
tidy.orcutt

Tidy a(n) orcutt object
tidy.negbin

Tidy a(n) negbin object
tidy.pam

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

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

Tidy a(n) nlrq object
tidy.nls

Tidy a(n) nls object
tidy.plm

Tidy a(n) plm object
tidy.poLCA

Tidy a(n) poLCA object
tidy.multinom

Tidying methods for multinomial logistic regression models
tidy.muhaz

Tidy a(n) muhaz object
tidy.polr

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

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

Tidy a(n) regsubsets object
tidy.rcorr

Tidy a(n) rcorr object
tidy.pyears

Tidy a(n) pyears object
tidy.prcomp

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

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

Tidy a(n) ridgelm object
tidy.glmrob

Tidy a(n) glmrob object
tidy.rlm

Tidy a(n) rlm object
tidy.sarlm

Tidying methods for spatially autoregressive models
tidy.speedglm

Tidy a(n) speedglm object
tidy.spec

Tidy a(n) spec object
tidy.rq

Tidy a(n) rq object
tidy.lmrob

Tidy a(n) lmrob object
tidy.rqs

Tidy a(n) rqs object
tidy.speedlm

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

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

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

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

Tidy a(n) systemfit object
tidy.survreg

Tidy a(n) survreg object
tidy.summary_emm

Tidy a(n) summary_emm object
tidy.survfit

Tidy a(n) survfit object
tidy.survdiff

Tidy a(n) survdiff object
tidy.table

Tidy a(n) table object
tidy.svyglm

Tidy a(n) svyglm object
tidy.survexp

Tidy a(n) survexp object
tidy.ts

Tidy a(n) ts object
tidy.svyolr

Tidy a(n) svyolr object
tidy.Gam

Tidy a(n) Gam object
tidy_svd

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

Tidy atomic vectors
tidy_irlba

Tidy a(n) irlba object masquerading as list
tidy_xyz

Tidy a(n) xyz object masquerading as list
tidy_optim

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

Tidy a(n) zoo object
tidy.varest

Tidy a(n) varest object