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

854,765

Version

0.5.4

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Alex Hayes

Last Published

January 27th, 2020

Functions in broom (0.5.4)

augment.glmRob

Augment a(n) glmRob object
augment.htest

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

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

Tidy a(n) loess object
augment.nlrq

Tidy a(n) nlrq object
augment_columns

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

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

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

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

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

Augment a(n) glm object
augment.coxph

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

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

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

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

Augment a(n) rlm object
durbinWatsonTest_tidiers

Tidy/glance a(n) durbinWatsonTest object
emmeans_tidiers

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

Glance at a(n) ivreg object
augment.rq

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

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

Glance at a(n) ergm object
glance.kmeans

Glance at a(n) kmeans object
argument_glossary

Allowed argument names in tidiers
augment.prcomp

Augment data with information from a(n) prcomp object
bootstrap

Set up bootstrap replicates of a dplyr operation
augment.kmeans

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

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

Augment data with information from a(n) speedlm object
tidy.geeglm

Tidy a(n) geeglm object
augment.stl

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

Glance at a(n) Arima object
augment.Mclust

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

Glance at a(n) nlrq object
finish_glance

Add logLik, AIC, BIC, and other common measurements to a glance of a prediction
augment.lm

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

Augment a(n) lmRob object
augment.smooth.spline

Tidy a(n) smooth.spline object
confint_tidy

Calculate confidence interval as a tidy data frame
augment.rqs

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

Glance at a(n) rq object
glance.nls

Glance at a(n) nls object
fix_data_frame

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

Glance at a(n) biglm object
glance.cch

Glance at a(n) cch object
brms_tidiers

Tidying methods for a brms model
data.frame_tidiers

Tidiers for data.frame objects
glance.fitdistr

Glance at a(n) fitdistr object
glance.coxph

Glance at a(n) coxph object
glance.garch

Tidy a(n) garch object
broom

Convert Statistical Objects into Tidy Tibbles
glance.Gam

Glance at a(n) Gam object
glance.aareg

Glance at a(n) aareg object
column_glossary

Allowed column names in tidied tibbles
glance.betareg

Glance at a(n) betareg object
glance.glmnet

Glance at a(n) glmnet object
glance.Mclust

Glance at a(n) Mclust object
glance.ridgelm

Glance at a(n) ridgelm object
glance.plm

Glance at a(n) plm object
glance.orcutt

Glance at a(n) orcutt object
nlme_tidiers

Tidying methods for mixed effects models
glance.smooth.spline

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

Tidy a(n) gam object
null_tidiers

Tidiers for NULL inputs
glance.glm

Glance at a(n) glm object
glance.binDesign

Glance at a(n) binDesign object
glance.survexp

Glance at a(n) survexp object
glance.muhaz

Glance at a(n) muhaz object
glance.gmm

Glance at a(n) gmm object
glance.multinom

Glance at a(n) multinom object
insert_NAs

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

Tidying methods for rowwise_dfs from dplyr, for tidying each row and recombining the results
list_tidiers

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

Glance at a(n) survfit object
reexports

Objects exported from other packages
glance.glmRob

Glance at a(n) glmRob object
glance.lmRob

Glance at a(n) lmRob object
tidy.Kendall

Tidy a(n) Kendall object
tidy.Mclust

Tidy a(n) Mclust object
tidy.polr

Tidying methods for ordinal logistic regression models
glance.poLCA

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

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

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

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

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

Tidy a(n) density object
glance.factanal

Glance at a(n) factanal object
glance.felm

Glance at a(n) felm object
tidy.glmRob

Tidy a(n) glmRob object
glance.lm

Glance at a(n) lm object
glance.speedlm

Glance at a(n) speedlm object
glance.lavaan

Glance at a(n) lavaan object
glance.rlm

Glance at a(n) rlm object
tidy.glmnet

Tidy a(n) glmnet object
tidy.map

Tidy a(n) map object
tidy.manova

Tidy a(n) manova object
tidy.prcomp

Tidy a(n) prcomp object
tidy.anova

Tidy a(n) anova object
tidy.acf

Tidy a(n) acf object
glance.survdiff

Glance at a(n) survdiff object
glance_optim

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

Glance at a(n) survreg object
glance.pyears

Glance at a(n) pyears object
tidy.cch

Tidy a(n) cch object
sparse_tidiers

Tidy a sparseMatrix object from the Matrix package
lme4_tidiers

Tidying methods for mixed effects models
summary_tidiers

Tidy/glance a(n) summaryDefault object
tidy.pyears

Tidy a(n) pyears object
tidy.spec

Tidy a(n) spec object
tidy.aovlist

Tidy a(n) aovlist object
tidy.binDesign

Tidy a(n) binDesign object
tidy.aov

Tidy a(n) aov object
tidy.binWidth

Tidy a(n) binWidth object
matrix_tidiers

Tidiers for matrix objects
tidy.Arima

Tidy a(n) Arima object
tidy.Gam

Tidy a(n) Gam object
tidy.gamlss

Tidy a(n) gamlss object
tidy.ivreg

Tidy a(n) ivreg object
tidy.garch

Tidy a(n) garch object
tidy.betareg

Tidy a(n) betareg object
tidy_irlba

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

Tidy a(n) speedlm object
tidy.biglm

Tidy a(n) biglm object
tidy_optim

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

Tidying methods for multinomial logistic regression models
tidy.kappa

Tidy a(n) kappa object
mcmc_tidiers

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

Glance at a(n) gam object
tidy.cld

Tidy a(n) cld object
tidy.btergm

Tidy a(n) btergm object
tidy.boot

Tidy a(n) boot object
tidy.factanal

Tidy a(n) factanal object
tidy.felm

Tidy a(n) felm object
rstanarm_tidiers

Tidying methods for an rstanarm model
sp_tidiers

Tidy a(n) SpatialPolygonsDataFrame object
tidy.aareg

Tidy a(n) aareg object
tidy.TukeyHSD

Tidy a(n) TukeyHSD object
tidy.confusionMatrix

Tidy a(n) confusionMatrix object
tidy.nlrq

Tidy a(n) nlrq object
tidy.poLCA

Tidy a(n) poLCA object
tidy.htest

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

Tidy a(n) lmodel2 object
tidy.gmm

Tidy a(n) gmm object
tidy.lmRob

Tidy a(n) lmRob object
tidy.dist

Tidy a(n) dist object
tidy.orcutt

Tidy a(n) orcutt object
tidy.nls

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

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

Tidy a(n) survfit object
tidy.survexp

Tidy a(n) survexp object
tidy.numeric

Tidy atomic vectors
tidy.fitdistr

Tidy a(n) fitdistr object
tidy.coxph

Tidy a(n) coxph object
tidy.ftable

Tidy a(n) ftable object
tidy.kde

Tidy a(n) kde object
tidy.kmeans

Tidy a(n) kmeans object
tidy.rcorr

Tidy a(n) rcorr object
tidy.lavaan

Tidy a(n) lavaan object
tidy.ridgelm

Tidy a(n) ridgelm object
tidy.lm

Tidy a(n) lm object
tidy.rlm

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

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

Tidy a(n) survdiff object
tidy.ts

Tidy a(n) ts object
tidy.roc

Tidy a(n) roc object
tidy.zoo

Tidy a(n) zoo object
tidy.ergm

Tidy a(n) ergm object
tidy.survreg

Tidy a(n) survreg object
tidy.table

Tidy a(n) table object
tidy.glm

Tidy a(n) glm object
tidy.mle2

Tidy a(n) mle2 object
tidy.glht

Tidy a(n) glht object
tidy.muhaz

Tidy a(n) muhaz object
tidy.plm

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

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

Tidy a(n) rq object
tidy.rqs

Tidy a(n) rqs object
tidy_svd

Tidy a(n) svd object masquerading as list
tidy_xyz

Tidy a(n) xyz object masquerading as list