Convert Statistical Objects into Tidy Tibbles

Summarizes key information about statistical objects in tidy tibbles. This makes it easy to report results, create plots and consistently work with large numbers of models at once. Broom provides three verbs that each provide different types of information about a model. tidy() summarizes information about model components such as coefficients of a regression. glance() reports information about an entire model, such as goodness of fit measures like AIC and BIC. augment() adds information about individual observations to a dataset, such as fitted values or influence measures.


broom broom website

CRANstatus Downloads R-CMD-check

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 × 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 × 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.
#> # ℹ 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 × 9
#>    Girth Height Volume .fitted .resid   .hat .sigma   .cooksd .std.resid
#>    <dbl>  <dbl>  <dbl>   <dbl>  <dbl>  <dbl>  <dbl>     <dbl>      <dbl>
#>  1   8.3     70   10.3    4.84  5.46  0.116    3.79 0.0978        1.50  
#>  2   8.6     65   10.3    4.55  5.75  0.147    3.77 0.148         1.60  
#>  3   8.8     63   10.2    4.82  5.38  0.177    3.78 0.167         1.53  
#>  4  10.5     72   16.4   15.9   0.526 0.0592   3.95 0.000409      0.140 
#>  5  10.7     81   18.8   19.9  -1.07  0.121    3.95 0.00394      -0.294 
#>  6  10.8     83   19.7   21.0  -1.32  0.156    3.94 0.00840      -0.370 
#>  7  11       66   15.6   16.2  -0.593 0.115    3.95 0.00114      -0.162 
#>  8  11       75   18.2   19.2  -1.05  0.0515   3.95 0.00138      -0.277 
#>  9  11.1     80   22.6   21.4   1.19  0.0920   3.95 0.00348       0.321 
#> 10  11.2     75   19.9   20.2  -0.288 0.0480   3.95 0.0000968    -0.0759
#> # ℹ 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.

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("broom")

1.0.13 by Emil Hvitfeldt, 5 months ago


https://broom.tidymodels.org/, https://github.com/tidymodels/broom


Report a bug at https://github.com/tidymodels/broom/issues


Browse source code at https://github.com/cran/broom


Authors: David Robinson [aut] , Alex Hayes [aut] , Simon Couch [aut] , Emil Hvitfeldt [aut, cre] (ORCID: , Posit Software , PBC [cph, fnd] (ROR: <https://ror.org/03wc8by49>) , Indrajeet Patil [ctb] , Derek Chiu [ctb] , Matthieu Gomez [ctb] , Boris Demeshev [ctb] , Dieter Menne [ctb] , Benjamin Nutter [ctb] , Luke Johnston [ctb] , Ben Bolker [ctb] , Francois Briatte [ctb] , Jeffrey Arnold [ctb] , Jonah Gabry [ctb] , Luciano Selzer [ctb] , Gavin Simpson [ctb] , Jens Preussner [ctb] , Jay Hesselberth [ctb] , Hadley Wickham [ctb] , Matthew Lincoln [ctb] , Alessandro Gasparini [ctb] , Lukasz Komsta [ctb] , Frederick Novometsky [ctb] , Wilson Freitas [ctb] , Michelle Evans [ctb] , Jason Cory Brunson [ctb] , Simon Jackson [ctb] , Ben Whalley [ctb] , Karissa Whiting [ctb] , Yves Rosseel [ctb] , Michael Kuehn [ctb] , Jorge Cimentada [ctb] , Erle Holgersen [ctb] , Karl Dunkle Werner [ctb] (ORCID: , Ethan Christensen [ctb] , Steven Pav [ctb] , Paul PJ [ctb] , Ben Schneider [ctb] , Patrick Kennedy [ctb] , Lily Medina [ctb] , Brian Fannin [ctb] , Jason Muhlenkamp [ctb] , Matt Lehman [ctb] , Bill Denney [ctb] , Nic Crane [ctb] , Andrew Bates [ctb] , Vincent Arel-Bundock [ctb] (ORCID: , Hideaki Hayashi [ctb] , Luis Tobalina [ctb] , Annie Wang [ctb] , Wei Yang Tham [ctb] , Clara Wang [ctb] , Abby Smith [ctb] , Jasper Cooper [ctb] , E Auden Krauska [ctb] , Alex Wang [ctb] , Malcolm Barrett [ctb] , Charles Gray [ctb] , Jared Wilber [ctb] , Vilmantas Gegzna [ctb] , Eduard Szoecs [ctb] , Frederik Aust [ctb] , Angus Moore [ctb] , Nick Williams [ctb] , Marius Barth [ctb] , Bruna Wundervald [ctb] , Joyce Cahoon [ctb] , Grant McDermott [ctb] , Kevin Zarca [ctb] , Shiro Kuriwaki [ctb] , Lukas Wallrich [ctb] , James Martherus [ctb] , Chuliang Xiao [ctb] , Joseph Larmarange [ctb] , Max Kuhn [ctb] , Michal Bojanowski [ctb] , Hakon Malmedal [ctb] , Clara Wang [ctb] , Sergio Oller [ctb] , Luke Sonnet [ctb] , Jim Hester [ctb] , Ben Schneider [ctb] , Bernie Gray [ctb] , Mara Averick [ctb] , Aaron Jacobs [ctb] , Andreas Bender [ctb] , Sven Templer [ctb] , Paul-Christian Buerkner [ctb] , Matthew Kay [ctb] , Erwan Le Pennec [ctb] , Johan Junkka [ctb] , Hao Zhu [ctb] , Benjamin Soltoff [ctb] , Zoe Wilkinson Saldana [ctb] , Tyler Littlefield [ctb] , Charles T. Gray [ctb] , Shabbh E. Banks [ctb] , Serina Robinson [ctb] , Roger Bivand [ctb] , Riinu Ots [ctb] , Nicholas Williams [ctb] , Nina Jakobsen [ctb] , Michael Weylandt [ctb] , Lisa Lendway [ctb] , Karl Hailperin [ctb] , Josue Rodriguez [ctb] , Jenny Bryan [ctb] , Chris Jarvis [ctb] , Greg Macfarlane [ctb] , Brian Mannakee [ctb] , Drew Tyre [ctb] , Shreyas Singh [ctb] , Laurens Geffert [ctb] , Hong Ooi [ctb] , Henrik Bengtsson [ctb] , Eduard Szocs [ctb] , David Hugh-Jones [ctb] , Matthieu Stigler [ctb] , Hugo Tavares [ctb] , R. Willem Vervoort [ctb] , Brenton M. Wiernik [ctb] , Josh Yamamoto [ctb] , Jasme Lee [ctb] , Taren Sanders [ctb] , Ilaria Prosdocimi [ctb] (ORCID: , Daniel D. Sjoberg [ctb] (ORCID: , Alex Reinhart [ctb]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports backports, cli, dplyr, generics, glue, lifecycle, purrr, rlang, stringr, tibble, tidyr

Suggests AER, AUC, bbmle, betareg, biglm, binGroup, boot, btergm, car, carData, caret, cluster, cmprsk, coda, covr, drc, e1071, emmeans, epiR, ergm, fixest, gam, gee, geepack, ggplot2, glmnet, glmnetUtils, gmm, Hmisc, interp, irlba, joineRML, Kendall, knitr, ks, Lahman, lavaan, leaps, lfe, lm.beta, lme4, lmodel2, lmtest, lsmeans, maps, margins, MASS, mclust, mediation, metafor, mfx, mgcv, mlogit, modeldata, modeltests, muhaz, multcomp, network, nnet, ordinal, plm, poLCA, psych, quantreg, rmarkdown, robust, robustbase, rsample, sandwich, spatialreg, spdep, speedglm, spelling, stats4, survey, survival, systemfit, testthat, tseries, vars, zoo


Imported by ACDm, AgroReg, AovBay, AquaticLifeHistory, AssumpSure, BasicStatsPlots, BioTIMEr, CHOIRBM, CR2, CimpleG, CoDaLoMic, CohortSurvival, ComBatFamQC, DAGassist, DeltaTools, DirectEffects, DynNom, ERSA, EasyStat, EpiForsk, EstimateBreed, FinanceGraphs, FluxSeparator, Greg, HDStIM, JSmediation, LDAShiny, LSTbook, LipidomicsR, MAICtools, MF.beta4, MLMusingR, MagmaClustR, MetricGraph, ModLR, NetworkExtinction, OLStrajr, PHEindicatormethods, POV, PhenoSpectra, PhysMove, PopComm, R2MLwiN, RCT, RHRV, RKorAPClient, Rbearcat, RobinCar, RobustMediate, SemNeT, SpatialRDD, SynDI, TSS.RESTREND, ThesiStats, TidyDensity, TrialEmulation, aggTrees, ale, allestimates, apaTables, autoReg, autocogs, autostats, batchtma, beezdemand, beezdiscounting, bonsaiforest, breathtestcore, bregr, broom.helpers, broom.mixed, bumbl, cantrends, cataScience, catfun, cdom, chest, cicalc, clinpubr, codaredistlm, conText, conjoint, convergEU, coresynth, crane, currr, dcurves, deltatest, dentomedical, describedata, did2s, doBy, easynem, echarts4r, edwards97, eoffice, equatiomatic, expertsurv, export, eyetrackingR, fastml, finalfit, fixes, flexCountReg, fluxfinder, fluxible, forestmangr, forestmodel, funneljoin, gRain, gWQS, geepack, germinationmetrics, ggFishPlots, ggadjustedforest, gglm, ggsurvfit, glmmfields, glmtoolbox, gompertztrunc, gtregression, healthyR.ai, highcharter, idionomics, imputeREE, infer, insane, interactions, itraxR, jtools, junco, knfi, konfound, lactater, lcsm, lin.eval, lisat, lnmixsurv, mKBO, mectx, mellio, metamorphr, mice, microbial, mmiCATs, mmibain, modelr, moderndive, mt.surv, mudfold, multibias, multifear, multifunc, mverse, nbTransmission, nestedLogit, netSEM, nrba, oceanic, omicwas, omu, papaja, pbkrtest, pixiedust, plotor, priorityelasticnet, psychReport, pubrplot, pwr2ppl, qPCRtools, qcpm, rSPDE, radiant.data, radiant.model, rdss, regress3d, regressinator, rifttable, risks, rmlnomogram, robomit, rosario, rstatix, scpoisson, sdcLog, shewhartr, simglm, simts, skedastic, smdi, specr, spqdep, sqlm, ssutil, stabiliser, statsr, survParamSim, survminer, survstan, swaprinc, sweep, teal.modules.clinical, teal.modules.general, temperatureresponse, tern, testflow, theftdlc, tidyAML, tidycmprsk, tidymodels, tidyrstats, tidyverse, tikatuwq, ukbflow, valr, volker, weird, whippr, widyr, wrappedtools.

Depended on by NumericEnsembles.

Suggested by Amelia, DeclareDesign, EpiQuestionR, GGally, GREENREG, HawaSpatial, KMunicate, MSEtool, MergeKmeans, ModStatR, NMAR, NetCoupler, OlinkAnalyze, OptSurvCutR, RBesT, RDesk, Rfuzzydid, SAMprior, TOSTER, TextAnalysisR, WeightIt, agriReg, agridat, amt, arsenal, assemblykor, autoimage, capybara, cardx, crmPack, crossmap, csdata, csdm, dcce, depictr, did, directlabels, discord, dotwhisker, dplyr, dpm, ethnobotanyR, etwfe, explainer, falsifyr, faux, fetwfe, fivethirtyeight, flexsurv, flextable, fonctionr, foresty, forrest, ggbiplot, ggdist, ggeffects, ggforestplotR, ggformula, ggplot2, ggpmisc, ggstats, glmmTMB, goldfish, grassr, gravity, groupdata2, gtsummary, guideR, hbal, healthyR, heplots, heteroTests, huxtable, icomb, industRial, insight, iop, ivcheck, jlmerclusterperm, kayadata, lame, lineagefreq, logitr, lspline, lterdatasampler, lucid, macleish, marginaleffects, mariposa, masc, mhurdle, mitey, mixpoissonreg, mmrm, modelbased, modelsummary, mosaic, multiverse, mxfda, netify, nls.multstart, nprobust, offsetreg, openintro, orchaRd, pammtools, panglm, parameters, parglm, pft, photosynthesis, plotly, presto, pubh, public.ctn0094data, qgcomp, rTPC, rar, rcausim, rdhte, rdrobust, rempsyc, resultcheck, rollout, rsample, rtables, sfdep, siera, simTool, simhelpers, sitrep, slxr, sparklyr, spicy, spmixW, statim, statuser, sumExtras, svytest, tabstats, tern.mmrm, texreg, tibbletime, tidybayes, tidycat, tidychangepoint, tidypopgen, tidyquant, tidytext, timetk, tinytable, tipr, traumar, underdisp, utile.visuals, vennDiagramLab, whitewater.


See at CRAN