├── .Rbuildignore ├── .github ├── .gitignore ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md └── workflows │ ├── R-CMD-check-hard.yaml │ ├── R-CMD-check.yaml │ ├── lock.yaml │ ├── pkgdown.yaml │ ├── pr-commands.yaml │ └── test-coverage.yaml ├── .gitignore ├── .vscode ├── extensions.json └── settings.json ├── DESCRIPTION ├── LICENSE ├── LICENSE.md ├── NAMESPACE ├── NEWS.md ├── R ├── aaa-documentation-helper.R ├── aer.R ├── auc.R ├── base.R ├── bbmle.R ├── betareg.R ├── biglm.R ├── bingroup.R ├── boot.R ├── broom-package.R ├── broom.R ├── btergm.R ├── car.R ├── caret.R ├── cluster.R ├── cmprsk.R ├── data-frame.R ├── deprecated-0-7-0.R ├── drc.R ├── emmeans.R ├── epiR.R ├── ergm.R ├── fixest.R ├── gam.R ├── geepack.R ├── glmnet-cv-glmnet.R ├── glmnet-glmnet.R ├── gmm.R ├── hmisc.R ├── import-standalone-obj-type.R ├── import-standalone-types-check.R ├── joinerml.R ├── kendall.R ├── ks.R ├── lavaan.R ├── leaps.R ├── lfe.R ├── list-irlba.R ├── list-optim.R ├── list-svd.R ├── list-xyz.R ├── list.R ├── lm-beta.R ├── lmodel2.R ├── lmtest.R ├── maps.R ├── margins.R ├── mass-fitdistr.R ├── mass-negbin.R ├── mass-polr.R ├── mass-ridgelm.R ├── mass-rlm.R ├── mclust.R ├── mediation.R ├── metafor.R ├── mfx.R ├── mgcv.R ├── mlogit.R ├── muhaz.R ├── multcomp.R ├── nnet.R ├── nobs.R ├── null-and-default.R ├── ordinal-clm.R ├── ordinal-clmm.R ├── plm.R ├── polca.R ├── psych.R ├── quantreg-nlrq.R ├── quantreg-rq.R ├── quantreg-rqs.R ├── robust-glmrob.R ├── robust-lmrob.R ├── robustbase-glmrob.R ├── robustbase-lmrob.R ├── sp.R ├── spdep.R ├── speedglm-speedglm.R ├── speedglm-speedlm.R ├── stats-anova.R ├── stats-arima.R ├── stats-decompose.R ├── stats-factanal.R ├── stats-glm.R ├── stats-htest.R ├── stats-kmeans.R ├── stats-lm.R ├── stats-loess.R ├── stats-mlm.R ├── stats-nls.R ├── stats-prcomp.R ├── stats-smooth.spline.R ├── stats-summary-lm.R ├── stats-time-series.R ├── survey.R ├── survival-aareg.R ├── survival-cch.R ├── survival-coxph.R ├── survival-pyears.R ├── survival-survdiff.R ├── survival-survexp.R ├── survival-survfit.R ├── survival-survreg.R ├── sysdata.rda ├── systemfit.R ├── tseries.R ├── utilities.R ├── vars.R ├── zoo.R └── zzz.R ├── README.Rmd ├── README.md ├── _pkgdown.yml ├── air.toml ├── broom.Rproj ├── codecov.yml ├── cran-comments.md ├── data-raw └── long_running_models_for_tests.R ├── inst └── WORDLIST ├── man-roxygen ├── augment_NAs.R ├── param_confint.R ├── param_data.R ├── param_exponentiate.R ├── param_interval.R ├── param_newdata.R ├── param_se_fit.R ├── param_type_predict.R ├── param_type_residuals.R ├── param_unused_dots.R ├── return_augment_columns.R ├── return_finish_glance.R ├── return_term_regression.R ├── return_tidy_regression.R ├── title_desc_augment.R ├── title_desc_glance.R ├── title_desc_tidy.R ├── title_desc_tidy_glance.R └── title_desc_tidy_list.R ├── man ├── augment.Mclust.Rd ├── augment.betamfx.Rd ├── augment.betareg.Rd ├── augment.clm.Rd ├── augment.coxph.Rd ├── augment.decomposed.ts.Rd ├── augment.drc.Rd ├── augment.factanal.Rd ├── augment.felm.Rd ├── augment.fixest.Rd ├── augment.gam.Rd ├── augment.glm.Rd ├── augment.glmRob.Rd ├── augment.htest.Rd ├── augment.ivreg.Rd ├── augment.kmeans.Rd ├── augment.lm.Rd ├── augment.lmRob.Rd ├── augment.loess.Rd ├── augment.mfx.Rd ├── augment.mjoint.Rd ├── augment.mlogit.Rd ├── augment.nlrq.Rd ├── augment.nls.Rd ├── augment.pam.Rd ├── augment.plm.Rd ├── augment.poLCA.Rd ├── augment.polr.Rd ├── augment.prcomp.Rd ├── augment.rlm.Rd ├── augment.rma.Rd ├── augment.robustbase.glmrob.Rd ├── augment.robustbase.lmrob.Rd ├── augment.rq.Rd ├── augment.rqs.Rd ├── augment.sarlm.Rd ├── augment.smooth.spline.Rd ├── augment.speedlm.Rd ├── augment.stl.Rd ├── augment.survreg.Rd ├── augment_columns.Rd ├── bootstrap.Rd ├── broom.Rd ├── confint_tidy.Rd ├── data.frame_tidiers.Rd ├── durbinWatsonTest_tidiers.Rd ├── figures │ └── logo.png ├── finish_glance.Rd ├── fix_data_frame.Rd ├── glance.Arima.Rd ├── glance.Mclust.Rd ├── glance.aareg.Rd ├── glance.anova.Rd ├── glance.aov.Rd ├── glance.betamfx.Rd ├── glance.betareg.Rd ├── glance.biglm.Rd ├── glance.binDesign.Rd ├── glance.cch.Rd ├── glance.clm.Rd ├── glance.clmm.Rd ├── glance.coeftest.Rd ├── glance.coxph.Rd ├── glance.crr.Rd ├── glance.cv.glmnet.Rd ├── glance.drc.Rd ├── glance.ergm.Rd ├── glance.factanal.Rd ├── glance.felm.Rd ├── glance.fitdistr.Rd ├── glance.fixest.Rd ├── glance.gam.Rd ├── glance.garch.Rd ├── glance.geeglm.Rd ├── glance.glm.Rd ├── glance.glmRob.Rd ├── glance.glmnet.Rd ├── glance.gmm.Rd ├── glance.ivreg.Rd ├── glance.kmeans.Rd ├── glance.lavaan.Rd ├── glance.lm.Rd ├── glance.lmRob.Rd ├── glance.lmodel2.Rd ├── glance.margins.Rd ├── glance.mfx.Rd ├── glance.mjoint.Rd ├── glance.mlogit.Rd ├── glance.muhaz.Rd ├── glance.multinom.Rd ├── glance.negbin.Rd ├── glance.nlrq.Rd ├── glance.nls.Rd ├── glance.pam.Rd ├── glance.plm.Rd ├── glance.poLCA.Rd ├── glance.polr.Rd ├── glance.pyears.Rd ├── glance.ridgelm.Rd ├── glance.rlm.Rd ├── glance.rma.Rd ├── glance.robustbase.lmrob.Rd ├── glance.rq.Rd ├── glance.sarlm.Rd ├── glance.smooth.spline.Rd ├── glance.speedglm.Rd ├── glance.speedlm.Rd ├── glance.summary.lm.Rd ├── glance.survdiff.Rd ├── glance.survexp.Rd ├── glance.survfit.Rd ├── glance.survreg.Rd ├── glance.svyglm.Rd ├── glance.svyolr.Rd ├── glance.varest.Rd ├── glance_gam_hastie.Rd ├── glance_optim.Rd ├── leveneTest_tidiers.Rd ├── list_tidiers.Rd ├── metafor_tidiers.Rd ├── null_tidiers.Rd ├── reexports.Rd ├── sp_tidiers.Rd ├── summary_tidiers.Rd ├── tidy.Arima.Rd ├── tidy.Kendall.Rd ├── tidy.Mclust.Rd ├── tidy.TukeyHSD.Rd ├── tidy.aareg.Rd ├── tidy.acf.Rd ├── tidy.anova.Rd ├── tidy.aov.Rd ├── tidy.aovlist.Rd ├── tidy.betamfx.Rd ├── tidy.betareg.Rd ├── tidy.biglm.Rd ├── tidy.binDesign.Rd ├── tidy.binWidth.Rd ├── tidy.boot.Rd ├── tidy.btergm.Rd ├── tidy.cch.Rd ├── tidy.cld.Rd ├── tidy.clm.Rd ├── tidy.clmm.Rd ├── tidy.coeftest.Rd ├── tidy.confint.glht.Rd ├── tidy.confusionMatrix.Rd ├── tidy.coxph.Rd ├── tidy.crr.Rd ├── tidy.cv.glmnet.Rd ├── tidy.density.Rd ├── tidy.dist.Rd ├── tidy.drc.Rd ├── tidy.emmGrid.Rd ├── tidy.epi.2by2.Rd ├── tidy.ergm.Rd ├── tidy.factanal.Rd ├── tidy.felm.Rd ├── tidy.fitdistr.Rd ├── tidy.fixest.Rd ├── tidy.ftable.Rd ├── tidy.gam.Rd ├── tidy.garch.Rd ├── tidy.geeglm.Rd ├── tidy.glht.Rd ├── tidy.glm.Rd ├── tidy.glmRob.Rd ├── tidy.glmnet.Rd ├── tidy.gmm.Rd ├── tidy.htest.Rd ├── tidy.ivreg.Rd ├── tidy.kappa.Rd ├── tidy.kde.Rd ├── tidy.kmeans.Rd ├── tidy.lavaan.Rd ├── tidy.lm.Rd ├── tidy.lm.beta.Rd ├── tidy.lmRob.Rd ├── tidy.lmodel2.Rd ├── tidy.lsmobj.Rd ├── tidy.manova.Rd ├── tidy.map.Rd ├── tidy.margins.Rd ├── tidy.mediate.Rd ├── tidy.mfx.Rd ├── tidy.mjoint.Rd ├── tidy.mle2.Rd ├── tidy.mlm.Rd ├── tidy.mlogit.Rd ├── tidy.muhaz.Rd ├── tidy.multinom.Rd ├── tidy.negbin.Rd ├── tidy.nlrq.Rd ├── tidy.nls.Rd ├── tidy.pairwise.htest.Rd ├── tidy.pam.Rd ├── tidy.plm.Rd ├── tidy.poLCA.Rd ├── tidy.polr.Rd ├── tidy.power.htest.Rd ├── tidy.prcomp.Rd ├── tidy.pyears.Rd ├── tidy.rcorr.Rd ├── tidy.ref.grid.Rd ├── tidy.regsubsets.Rd ├── tidy.ridgelm.Rd ├── tidy.rlm.Rd ├── tidy.robustbase.glmrob.Rd ├── tidy.robustbase.lmrob.Rd ├── tidy.roc.Rd ├── tidy.rq.Rd ├── tidy.rqs.Rd ├── tidy.sarlm.Rd ├── tidy.spec.Rd ├── tidy.speedglm.Rd ├── tidy.speedlm.Rd ├── tidy.summary.glht.Rd ├── tidy.summary.lm.Rd ├── tidy.summary_emm.Rd ├── tidy.survdiff.Rd ├── tidy.survexp.Rd ├── tidy.survfit.Rd ├── tidy.survreg.Rd ├── tidy.svyglm.Rd ├── tidy.svyolr.Rd ├── tidy.systemfit.Rd ├── tidy.table.Rd ├── tidy.ts.Rd ├── tidy.varest.Rd ├── tidy.zoo.Rd ├── tidy_gam_hastie.Rd ├── tidy_irlba.Rd ├── tidy_optim.Rd ├── tidy_svd.Rd ├── tidy_xyz.Rd └── vector_tidiers.Rd ├── pkgdown └── favicon │ ├── apple-touch-icon-120x120.png │ ├── apple-touch-icon-152x152.png │ ├── apple-touch-icon-180x180.png │ ├── apple-touch-icon-60x60.png │ ├── apple-touch-icon-76x76.png │ ├── apple-touch-icon.png │ ├── favicon-16x16.png │ ├── favicon-32x32.png │ └── favicon.ico ├── tests ├── spelling.R ├── test-all.R ├── testthat.R └── testthat │ ├── _snaps │ ├── data-frame.md │ ├── drc.md │ ├── ergm.md │ ├── fixest.md │ ├── geepack.md │ ├── joineRML.md │ ├── lfe.md │ ├── list-svd.md │ ├── list-xyz.md │ ├── list.md │ ├── mass-polr.md │ ├── mclust.md │ ├── mediation.md │ ├── mgcv.md │ ├── null-and-default.md │ ├── quantreg-rqs.md │ ├── robust-glmrob.md │ ├── speedglm-speedglm.md │ ├── speedglm-speedlm.md │ ├── stats-anova.md │ ├── stats-factanal.md │ ├── stats-glm.md │ ├── stats-htest.md │ ├── stats-lm.md │ ├── stats-prcomp.md │ ├── survival-survfit.md │ ├── utilities.md │ ├── utilities.new.md │ └── vars.md │ ├── helper.R │ ├── test-aer.R │ ├── test-aov.R │ ├── test-auc.R │ ├── test-bbmle.R │ ├── test-betareg.R │ ├── test-biglm.R │ ├── test-bingroup.R │ ├── test-boot.R │ ├── test-btergm.R │ ├── test-car.R │ ├── test-caret.R │ ├── test-cluster.R │ ├── test-cmprsk.R │ ├── test-data-frame.R │ ├── test-drc.R │ ├── test-emmeans.R │ ├── test-epiR.R │ ├── test-ergm.R │ ├── test-fixest.R │ ├── test-gam.R │ ├── test-geepack.R │ ├── test-glmnet.R │ ├── test-glmnetUtils.R │ ├── test-gmm.R │ ├── test-hmisc.R │ ├── test-joineRML.R │ ├── test-kendall.R │ ├── test-ks.R │ ├── test-lavaan.R │ ├── test-leaps.R │ ├── test-lfe.R │ ├── test-list-irlba.R │ ├── test-list-optim.R │ ├── test-list-svd.R │ ├── test-list-xyz.R │ ├── test-list.R │ ├── test-lmbeta-lm-beta.R │ ├── test-lmodel2.R │ ├── test-lmtest.R │ ├── test-maps.R │ ├── test-margins.R │ ├── test-mass-fitdistr.R │ ├── test-mass-negbin.R │ ├── test-mass-polr.R │ ├── test-mass-ridgelm.R │ ├── test-mass-rlm.R │ ├── test-mclust.R │ ├── test-mediation.R │ ├── test-metafor.R │ ├── test-mfx.R │ ├── test-mgcv.R │ ├── test-mlogit.R │ ├── test-muhaz.R │ ├── test-multcomp.R │ ├── test-nnet.R │ ├── test-null-and-default.R │ ├── test-ordinal.R │ ├── test-plm.R │ ├── test-polca.R │ ├── test-psych.R │ ├── test-quantreg-nlrq.R │ ├── test-quantreg-rq.R │ ├── test-quantreg-rqs.R │ ├── test-robust-glmrob.R │ ├── test-robust.R │ ├── test-robustbase.R │ ├── test-spdep.R │ ├── test-speedglm-speedglm.R │ ├── test-speedglm-speedlm.R │ ├── test-stats-anova.R │ ├── test-stats-arima.R │ ├── test-stats-decompose.R │ ├── test-stats-factanal.R │ ├── test-stats-glm.R │ ├── test-stats-htest.R │ ├── test-stats-kmeans.R │ ├── test-stats-lm.R │ ├── test-stats-loess.R │ ├── test-stats-mlm.R │ ├── test-stats-nls.R │ ├── test-stats-prcomp.R │ ├── test-stats-smooth.spline.R │ ├── test-stats-summary-lm.R │ ├── test-stats-time-series.R │ ├── test-survey.R │ ├── test-survival-aareg.R │ ├── test-survival-cch.R │ ├── test-survival-coxph.R │ ├── test-survival-pyears.R │ ├── test-survival-survdiff.R │ ├── test-survival-survexp.R │ ├── test-survival-survfit.R │ ├── test-survival-survreg.R │ ├── test-systemfit.R │ ├── test-tseries.R │ ├── test-utilities.R │ ├── test-vars.R │ └── test-zoo.R └── vignettes ├── .gitignore ├── adding-tidiers.Rmd ├── articles └── maintenance.Rmd ├── available-methods.Rmd ├── bootstrapping.Rmd ├── broom.Rmd ├── broom_and_dplyr.Rmd └── kmeans.Rmd /.Rbuildignore: -------------------------------------------------------------------------------- 1 | ^CRAN-RELEASE$ 2 | ^.*\.Rproj$ 3 | ^\.Rproj\.user$ 4 | ^man-roxygen$ 5 | ^revdep$ 6 | ^cran-comments\.md$ 7 | ^README.Rmd 8 | ^\.travis\.yml$ 9 | ^appveyor\.yml$ 10 | ^CONDUCT\.md$ 11 | ^codecov\.yml$ 12 | ^_pkgdown\.yml$ 13 | ^README\.Rmd$ 14 | ^\.github$ 15 | ^docs$ 16 | ^data-raw$ 17 | ^\.httr-oauth$ 18 | ^\.lintr$ 19 | ^pkgdown$ 20 | ^CRAN-RELEASE$ 21 | ^LICENSE\.md$ 22 | ^[\.]?air\.toml$ 23 | ^\.vscode$ 24 | -------------------------------------------------------------------------------- /.github/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # CODEOWNERS for broom 2 | # https://www.tidyverse.org/development/understudies 3 | .github/CODEOWNERS @dgrtwo @alexpghayes 4 | -------------------------------------------------------------------------------- /.github/workflows/R-CMD-check-hard.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | # 4 | # NOTE: This workflow only directly installs "hard" dependencies, i.e. Depends, 5 | # Imports, and LinkingTo dependencies. Notably, Suggests dependencies are never 6 | # installed, with the exception of testthat, knitr, and rmarkdown. The cache is 7 | # never used to avoid accidentally restoring a cache containing a suggested 8 | # dependency. 9 | on: 10 | push: 11 | branches: [main] 12 | pull_request: 13 | branches: [main] 14 | 15 | name: R-CMD-check-hard 16 | 17 | jobs: 18 | R-CMD-check: 19 | runs-on: ${{ matrix.config.os }} 20 | 21 | name: ${{ matrix.config.os }} (${{ matrix.config.r }}) 22 | 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | config: 27 | - {os: ubuntu-latest, r: 'release'} 28 | 29 | env: 30 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 31 | R_KEEP_PKG_SOURCE: yes 32 | 33 | steps: 34 | - uses: actions/checkout@v4 35 | 36 | - uses: r-lib/actions/setup-pandoc@v2 37 | 38 | - uses: r-lib/actions/setup-r@v2 39 | with: 40 | r-version: ${{ matrix.config.r }} 41 | http-user-agent: ${{ matrix.config.http-user-agent }} 42 | use-public-rspm: true 43 | 44 | - uses: r-lib/actions/setup-r-dependencies@v2 45 | with: 46 | dependencies: '"hard"' 47 | cache: false 48 | extra-packages: | 49 | any::rcmdcheck 50 | any::testthat 51 | any::knitr 52 | any::rmarkdown 53 | needs: check 54 | 55 | - uses: r-lib/actions/check-r-package@v2 56 | with: 57 | upload-snapshots: true 58 | -------------------------------------------------------------------------------- /.github/workflows/lock.yaml: -------------------------------------------------------------------------------- 1 | name: 'Lock Threads' 2 | 3 | on: 4 | schedule: 5 | - cron: '0 0 * * *' 6 | 7 | jobs: 8 | lock: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: dessant/lock-threads@v2 12 | with: 13 | github-token: ${{ github.token }} 14 | issue-lock-inactive-days: '14' 15 | # issue-exclude-labels: '' 16 | # issue-lock-labels: 'outdated' 17 | issue-lock-comment: > 18 | This issue has been automatically locked. If you believe you have 19 | found a related problem, please file a new issue (with a reprex: 20 | ) and link to this issue. 21 | issue-lock-reason: '' 22 | pr-lock-inactive-days: '14' 23 | # pr-exclude-labels: 'wip' 24 | pr-lock-labels: '' 25 | pr-lock-comment: > 26 | This pull request has been automatically locked. If you believe the 27 | issue addressed here persists, please file a new PR (with a reprex: 28 | ) and link to this one. 29 | pr-lock-reason: '' 30 | # process-only: 'issues' 31 | -------------------------------------------------------------------------------- /.github/workflows/pkgdown.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | release: 8 | types: [published] 9 | workflow_dispatch: 10 | 11 | name: pkgdown.yaml 12 | 13 | permissions: read-all 14 | 15 | jobs: 16 | pkgdown: 17 | runs-on: ubuntu-latest 18 | # Only restrict concurrency for non-PR jobs 19 | concurrency: 20 | group: pkgdown-${{ github.event_name != 'pull_request' || github.run_id }} 21 | env: 22 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 23 | permissions: 24 | contents: write 25 | steps: 26 | - uses: actions/checkout@v4 27 | 28 | - uses: r-lib/actions/setup-pandoc@v2 29 | 30 | - uses: r-lib/actions/setup-r@v2 31 | with: 32 | use-public-rspm: true 33 | 34 | - uses: r-lib/actions/setup-r-dependencies@v2 35 | with: 36 | extra-packages: any::pkgdown, local::. 37 | needs: website 38 | 39 | - name: Build site 40 | run: pkgdown::build_site_github_pages(new_process = FALSE, install = FALSE) 41 | shell: Rscript {0} 42 | 43 | - name: Deploy to GitHub pages 🚀 44 | if: github.event_name != 'pull_request' 45 | uses: JamesIves/github-pages-deploy-action@v4.5.0 46 | with: 47 | clean: false 48 | branch: gh-pages 49 | folder: docs 50 | -------------------------------------------------------------------------------- /.github/workflows/test-coverage.yaml: -------------------------------------------------------------------------------- 1 | # Workflow derived from https://github.com/r-lib/actions/tree/v2/examples 2 | # Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help 3 | on: 4 | push: 5 | branches: [main, master] 6 | pull_request: 7 | 8 | name: test-coverage.yaml 9 | 10 | permissions: read-all 11 | 12 | jobs: 13 | test-coverage: 14 | runs-on: ubuntu-latest 15 | env: 16 | GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} 17 | 18 | steps: 19 | - uses: actions/checkout@v4 20 | 21 | - uses: r-lib/actions/setup-r@v2 22 | with: 23 | use-public-rspm: true 24 | 25 | - uses: r-lib/actions/setup-r-dependencies@v2 26 | with: 27 | extra-packages: any::covr, any::xml2 28 | needs: coverage 29 | 30 | - name: Test coverage 31 | run: | 32 | cov <- covr::package_coverage( 33 | quiet = FALSE, 34 | clean = FALSE, 35 | install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") 36 | ) 37 | print(cov) 38 | covr::to_cobertura(cov) 39 | shell: Rscript {0} 40 | 41 | - uses: codecov/codecov-action@v5 42 | with: 43 | # Fail if error if not on PR, or if on PR and token is given 44 | fail_ci_if_error: ${{ github.event_name != 'pull_request' || secrets.CODECOV_TOKEN }} 45 | files: ./cobertura.xml 46 | plugins: noop 47 | disable_search: true 48 | token: ${{ secrets.CODECOV_TOKEN }} 49 | 50 | - name: Show testthat output 51 | if: always() 52 | run: | 53 | ## -------------------------------------------------------------------- 54 | find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true 55 | shell: bash 56 | 57 | - name: Upload test results 58 | if: failure() 59 | uses: actions/upload-artifact@v4 60 | with: 61 | name: coverage-test-failures 62 | path: ${{ runner.temp }}/package 63 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .Rproj.user 2 | .Rhistory 3 | .RData 4 | vignettes/*cache 5 | inst/doc 6 | /.vs 7 | /broom.rxproj 8 | /broom.sln 9 | .DS_Store 10 | .httr-oauth 11 | docs/ 12 | -------------------------------------------------------------------------------- /.vscode/extensions.json: -------------------------------------------------------------------------------- 1 | { 2 | "recommendations": [ 3 | "Posit.air-vscode" 4 | ] 5 | } 6 | -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "[r]": { 3 | "editor.formatOnSave": true, 4 | "editor.defaultFormatter": "Posit.air-vscode" 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | YEAR: 2025 2 | COPYRIGHT HOLDER: broom authors 3 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # MIT License 2 | 3 | Copyright (c) 2025 broom authors 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /R/auc.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class roc 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x An `roc` object returned from a call to [AUC::roc()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy("cutoff", "tpr", "fpr") 8 | #' 9 | #' @examplesIf rlang::is_installed(c("AUC", "ggplot2")) 10 | #' 11 | #' # load libraries for models and data 12 | #' library(AUC) 13 | #' 14 | #' # load data 15 | #' data(churn) 16 | #' 17 | #' # fit model 18 | #' r <- roc(churn$predictions, churn$labels) 19 | #' 20 | #' # summarize with tidiers + visualization 21 | #' td <- tidy(r) 22 | #' td 23 | #' 24 | #' library(ggplot2) 25 | #' 26 | #' ggplot(td, aes(fpr, tpr)) + 27 | #' geom_line() 28 | #' 29 | #' # compare the ROC curves for two prediction algorithms 30 | #' library(dplyr) 31 | #' library(tidyr) 32 | #' 33 | #' rocs <- churn |> 34 | #' pivot_longer(contains("predictions"), 35 | #' names_to = "algorithm", 36 | #' values_to = "value" 37 | #' ) |> 38 | #' nest(data = -algorithm) |> 39 | #' mutate(tidy_roc = purrr::map(data, \(x) tidy(roc(x$value, x$labels)))) |> 40 | #' unnest(tidy_roc) 41 | #' 42 | #' ggplot(rocs, aes(fpr, tpr, color = algorithm)) + 43 | #' geom_line() 44 | #' 45 | #' @export 46 | #' @aliases auc_tidiers roc_tidiers 47 | #' @seealso [tidy()], [AUC::roc()] 48 | tidy.roc <- function(x, ...) { 49 | rename2(as_tibble(unclass(x)), cutoff = cutoffs) 50 | } 51 | -------------------------------------------------------------------------------- /R/base.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class table 2 | #' @template title_desc_tidy 3 | #' 4 | #' @description Deprecated. Please use [tibble::as_tibble()] instead. 5 | #' 6 | #' @param x A [base::table] object. 7 | #' @template param_unused_dots 8 | #' 9 | #' @return A [tibble::tibble] in long-form containing frequency information 10 | #' for the table in a `Freq` column. The result is much like what you get 11 | #' from [tidyr::pivot_longer()]. 12 | #' 13 | #' @details Directly calls [tibble::as_tibble()] on a [base::table] object. 14 | #' 15 | #' @seealso [tibble::as_tibble.table()] 16 | #' @export 17 | tidy.table <- function(x, ...) { 18 | .Deprecated(new = "tibble::as_tibble()") 19 | as_tibble(x) 20 | } 21 | -------------------------------------------------------------------------------- /R/bbmle.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class mle2 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x An `mle2` object created by a call to [bbmle::mle2()]. 5 | #' @template param_confint 6 | #' @template param_unused_dots 7 | #' 8 | #' @evalRd return_tidy(regression = TRUE) 9 | #' 10 | #' @examplesIf rlang::is_installed("bbmle") 11 | #' 12 | #' # load libraries for models and data 13 | #' library(bbmle) 14 | #' 15 | #' # generate data 16 | #' x <- 0:10 17 | #' y <- c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8) 18 | #' d <- data.frame(x, y) 19 | #' 20 | #' # fit model 21 | #' fit <- mle2(y ~ dpois(lambda = ymean), 22 | #' start = list(ymean = mean(y)), data = d 23 | #' ) 24 | #' 25 | #' # summarize model fit with tidiers 26 | #' tidy(fit) 27 | #' 28 | #' @export 29 | #' @seealso [tidy()], [bbmle::mle2()], [tidy_optim()] 30 | #' @aliases mle2_tidiers bbmle_tidiers 31 | tidy.mle2 <- function(x, conf.int = FALSE, conf.level = .95, ...) { 32 | check_ellipses("exponentiate", "tidy", "mle2", ...) 33 | 34 | co <- bbmle::coef(bbmle::summary(x)) 35 | ret <- ret <- as_tidy_tibble( 36 | co, 37 | new_names = c("estimate", "std.error", "statistic", "p.value") 38 | ) 39 | 40 | if (conf.int) { 41 | # can't use broom_confint / broom_confint_terms due to 42 | # some sort of S4 object dispatch thing 43 | 44 | ci <- bbmle::confint(x, level = conf.level) 45 | 46 | # confint called on models with a single predictor 47 | # often returns a named vector rather than a matrix :( 48 | 49 | if (is.null(dim(ci))) { 50 | ci <- matrix(ci, nrow = 1) 51 | } 52 | 53 | colnames(ci) <- c("conf.low", "conf.high") 54 | ci <- as_tibble(ci) 55 | 56 | ret <- dplyr::bind_cols(ret, ci) 57 | } 58 | 59 | as_tibble(ret) 60 | } 61 | -------------------------------------------------------------------------------- /R/broom-package.R: -------------------------------------------------------------------------------- 1 | # Custom package description for the package help file. 2 | #' @name broom 3 | #' @description 4 | #' Convert statistical analysis objects from R into tidy tibbles, 5 | #' so that they can more easily be combined, reshaped and otherwise processed 6 | #' with tools like dplyr, tidyr and ggplot2. The package provides three S3 7 | #' generics: tidy, which summarizes a model's statistical findings such as 8 | #' coefficients of a regression; augment, which adds columns to the original 9 | #' data such as predictions, residuals and cluster assignments; and glance, 10 | #' which provides a one-row summary of model-level statistics. 11 | #' 12 | #' @keywords internal 13 | "_PACKAGE" 14 | 15 | ## usethis namespace: start 16 | #' @importFrom stats AIC BIC coef confint fitted logLik model.frame 17 | #' @importFrom stats pnorm qnorm qt predict residuals setNames var 18 | #' @importFrom stats quantile model.response terms na.pass na.omit 19 | #' @importFrom stats influence rstandard cooks.distance nobs 20 | #' @importFrom purrr map_df set_names possibly 21 | #' @importFrom tibble tibble as_tibble 22 | #' @importFrom tidyr pivot_longer pivot_wider 23 | #' 24 | #' @import rlang 25 | #' 26 | #' @importFrom utils head 27 | #' @importFrom glue glue 28 | #' 29 | #' @import dplyr 30 | ## usethis namespace: end 31 | NULL 32 | -------------------------------------------------------------------------------- /R/broom.R: -------------------------------------------------------------------------------- 1 | #' @importFrom generics augment 2 | #' @export 3 | #' @seealso [augment.lm()] 4 | generics::augment 5 | 6 | #' @importFrom generics tidy 7 | #' @export 8 | #' @seealso [tidy.lm()] 9 | generics::tidy 10 | 11 | #' @importFrom generics glance 12 | #' @export 13 | #' @seealso [glance.lm()] 14 | generics::glance 15 | -------------------------------------------------------------------------------- /R/btergm.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class btergm 2 | #' @template title_desc_tidy 3 | #' 4 | #' @description This method tidies the coefficients of a bootstrapped 5 | #' temporal exponential random graph model estimated with the \pkg{xergm}. 6 | #' It simply returns the coefficients and their confidence intervals. 7 | #' 8 | #' @param x A [btergm::btergm()] object. 9 | #' @param conf.level Confidence level for confidence intervals. Defaults to 10 | #' 0.95. 11 | #' @template param_exponentiate 12 | #' @template param_unused_dots 13 | #' 14 | #' @evalRd return_tidy("term", "estimate", "conf.low", "conf.high") 15 | #' 16 | #' @export 17 | #' @aliases btergm_tidiers 18 | #' @seealso [tidy()], [btergm::btergm()] 19 | #' @examplesIf rlang::is_installed(c("btergm", "network")) 20 | #' 21 | #' library(btergm) 22 | #' library(network) 23 | #' 24 | #' set.seed(5) 25 | #' 26 | #' # create 10 random networks with 10 actors 27 | #' networks <- list() 28 | #' for (i in 1:10) { 29 | #' mat <- matrix(rbinom(100, 1, .25), nrow = 10, ncol = 10) 30 | #' diag(mat) <- 0 31 | #' nw <- network(mat) 32 | #' networks[[i]] <- nw 33 | #' } 34 | #' 35 | #' # create 10 matrices as covariates 36 | #' covariates <- list() 37 | #' for (i in 1:10) { 38 | #' mat <- matrix(rnorm(100), nrow = 10, ncol = 10) 39 | #' covariates[[i]] <- mat 40 | #' } 41 | #' 42 | #' # fit the model 43 | #' mod <- btergm(networks ~ edges + istar(2) + edgecov(covariates), R = 100) 44 | #' 45 | #' # summarize model fit with tidiers 46 | #' tidy(mod) 47 | #' 48 | tidy.btergm <- function(x, conf.level = .95, exponentiate = FALSE, ...) { 49 | co <- btergm::confint(x, level = conf.level)[, -2] 50 | 51 | ret <- as_tidy_tibble( 52 | co, 53 | new_names = c("estimate", "conf.low", "conf.high")[1:ncol(co)] 54 | ) 55 | 56 | if (exponentiate) { 57 | ret <- exponentiate(ret) 58 | } 59 | 60 | as_tibble(ret) 61 | } 62 | -------------------------------------------------------------------------------- /R/data-frame.R: -------------------------------------------------------------------------------- 1 | #' @export 2 | glance.data.frame <- function(x, ...) { 3 | cli::cli_abort(c( 4 | "There is no {.fn glance} method for data frames.", 5 | "i" = "Did you mean {.fn tibble::glimpse}?" 6 | )) 7 | } 8 | 9 | #' @export 10 | glance.tbl_df <- function(x, ...) { 11 | cli::cli_abort(c( 12 | "There is no glance method for tibbles.", 13 | "i" = "Did you mean {.fn tibble::glimpse}?" 14 | )) 15 | } 16 | -------------------------------------------------------------------------------- /R/gam.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class Gam 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `Gam` object returned from a call to [gam::gam()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy( 8 | #' "term", 9 | #' "df", 10 | #' "sumsq", 11 | #' "meansq", 12 | #' "statistic", 13 | #' "p.value" 14 | #' ) 15 | #' 16 | #' @details Tidy `gam` objects created by calls to [mgcv::gam()] with 17 | #' [tidy.gam()]. 18 | #' 19 | #' @examplesIf rlang::is_installed("gam") 20 | #' 21 | #' # load libraries for models and data 22 | #' library(gam) 23 | #' 24 | #' # fit model 25 | #' g <- gam(mpg ~ s(hp, 4) + am + qsec, data = mtcars) 26 | #' 27 | #' # summarize model fit with tidiers 28 | #' tidy(g) 29 | #' glance(g) 30 | #' 31 | #' @export 32 | #' @family gam tidiers 33 | #' @aliases Gam_tidiers 34 | #' @seealso [tidy()], [gam::gam()], [tidy.anova()], [tidy.gam()] 35 | #' @rdname tidy_gam_hastie 36 | tidy.Gam <- function(x, ...) { 37 | tidy(summary(x)$parametric.anova) 38 | } 39 | 40 | #' @templateVar class Gam 41 | #' @template title_desc_glance 42 | #' 43 | #' @inheritParams tidy.Gam 44 | #' 45 | #' @evalRd return_glance( 46 | #' "df", 47 | #' "logLik", 48 | #' "AIC", 49 | #' "BIC", 50 | #' "deviance", 51 | #' "df.residual", 52 | #' "nobs" 53 | #' ) 54 | #' 55 | #' @details Glance at `gam` objects created by calls to [mgcv::gam()] with 56 | #' [glance.gam()]. 57 | #' 58 | #' @family gam tidiers 59 | #' @export 60 | #' @seealso [glance()], [gam::gam()] 61 | #' @rdname glance_gam_hastie 62 | glance.Gam <- function(x, ...) { 63 | s <- summary(x) 64 | 65 | as_glance_tibble( 66 | df = s$df[1], 67 | logLik = as.numeric(stats::logLik(x)), 68 | AIC = stats::AIC(x), 69 | BIC = stats::BIC(x), 70 | deviance = stats::deviance(x), 71 | df.residual = stats::df.residual(x), 72 | nobs = stats::nobs(x), 73 | na_types = "irrrrii" 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /R/hmisc.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class rcorr 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x An `rcorr` object returned from [Hmisc::rcorr()]. 5 | #' @param diagonal Logical indicating whether or not to include diagonal 6 | #' elements of the correlation matrix, or the correlation of a column with 7 | #' itself. For the elements, `estimate` is always 1 and `p.value` is always 8 | #' `NA`. Defaults to `FALSE`. 9 | #' @template param_unused_dots 10 | #' 11 | #' @evalRd return_tidy( 12 | #' "column1", 13 | #' "column2", 14 | #' "estimate", 15 | #' "p.value", 16 | #' n = "Number of observations used to compute the correlation" 17 | #' ) 18 | #' 19 | #' @details Suppose the original data has columns A and B. In the correlation 20 | #' matrix from `rcorr` there may be entries for both the `cor(A, B)` and 21 | #' `cor(B, A)`. Only one of these pairs will ever be present in the tidy 22 | #' output. 23 | #' 24 | #' @examplesIf rlang::is_installed(c("Hmisc", "ggplot2")) 25 | #' 26 | #' # load libraries for models and data 27 | #' library(Hmisc) 28 | #' 29 | #' mat <- replicate(52, rnorm(100)) 30 | #' 31 | #' # add some NAs 32 | #' mat[sample(length(mat), 2000)] <- NA 33 | #' 34 | #' # also, column names 35 | #' colnames(mat) <- c(LETTERS, letters) 36 | #' 37 | #' # fit model 38 | #' rc <- rcorr(mat) 39 | #' 40 | #' # summarize model fit with tidiers + visualization 41 | #' td <- tidy(rc) 42 | #' td 43 | #' 44 | #' library(ggplot2) 45 | #' ggplot(td, aes(p.value)) + 46 | #' geom_histogram(binwidth = .1) 47 | #' 48 | #' ggplot(td, aes(estimate, p.value)) + 49 | #' geom_point() + 50 | #' scale_y_log10() 51 | #' 52 | #' @export 53 | #' @aliases rcorr_tidiers Hmisc_tidiers 54 | #' @seealso [tidy()], [Hmisc::rcorr()] 55 | tidy.rcorr <- function(x, diagonal = FALSE, ...) { 56 | ret <- x$r |> 57 | as.data.frame() |> 58 | tibble::rownames_to_column("column1") |> 59 | pivot_longer( 60 | c(dplyr::everything(), -column1), 61 | names_to = "column2", 62 | values_to = "estimate" 63 | ) |> 64 | as.data.frame() |> 65 | mutate(n = as.vector(x$n), p.value = as.vector(x$P)) 66 | 67 | # include only half the symmetric matrix. 68 | ret <- ret[upper.tri(x$r, diag = diagonal), ] 69 | as_tibble(ret) 70 | } 71 | -------------------------------------------------------------------------------- /R/kendall.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class Kendall 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `Kendall` object returned from a call to [Kendall::Kendall()], 5 | #' [Kendall::MannKendall()], or [Kendall::SeasonalMannKendall()]. 6 | #' @template param_unused_dots 7 | #' 8 | #' @evalRd return_tidy( 9 | #' "p.value", 10 | #' "kendall_score", 11 | #' "var_kendall_score", 12 | #' statistic = "Kendall's tau statistic", 13 | #' denominator = "The denominator, which is tau=kendall_score/denominator." 14 | #' ) 15 | #' 16 | #' @examplesIf rlang::is_installed("Kendall") 17 | #' 18 | #' # load libraries for models and data 19 | #' library(Kendall) 20 | #' 21 | #' A <- c(2.5, 2.5, 2.5, 2.5, 5, 6.5, 6.5, 10, 10, 10, 10, 10, 14, 14, 14, 16, 17) 22 | #' B <- c(1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2) 23 | #' 24 | #' # fit models and summarize results 25 | #' f_res <- Kendall(A, B) 26 | #' tidy(f_res) 27 | #' 28 | #' s_res <- MannKendall(B) 29 | #' tidy(s_res) 30 | #' 31 | #' t_res <- SeasonalMannKendall(ts(A)) 32 | #' tidy(t_res) 33 | #' 34 | #' @export 35 | #' @seealso [tidy()], [Kendall::Kendall()], [Kendall::MannKendall()], 36 | #' [Kendall::SeasonalMannKendall()] 37 | #' @aliases Kendall_tidiers kendall_tidiers 38 | #' 39 | tidy.Kendall <- function(x, ...) { 40 | col_names <- c( 41 | "statistic", 42 | "p.value", 43 | "kendall_score", 44 | "denominator", 45 | "var_kendall_score" 46 | ) 47 | ret <- as_tibble(unclass(x)) 48 | set_names(ret, col_names) 49 | } 50 | -------------------------------------------------------------------------------- /R/ks.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class kde 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `kde` object returned from [ks::kde()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy("obs", "variable", "value", "estimate") 8 | #' 9 | #' @details Returns a data frame in long format with four columns. Use 10 | #' \code{tidyr::pivot_wider(..., names_from = variable, values_from = value)} 11 | #' on the output to return to a wide format. 12 | #' 13 | #' @examplesIf rlang::is_installed(c("ks", "ggplot2")) 14 | #' 15 | #' # load libraries for models and data 16 | #' library(ks) 17 | #' 18 | #' # generate data 19 | #' dat <- replicate(2, rnorm(100)) 20 | #' k <- kde(dat) 21 | #' 22 | #' # summarize model fit with tidiers + visualization 23 | #' td <- tidy(k) 24 | #' td 25 | #' 26 | #' library(ggplot2) 27 | #' library(dplyr) 28 | #' library(tidyr) 29 | #' 30 | #' td |> 31 | #' pivot_wider(c(obs, estimate), 32 | #' names_from = variable, 33 | #' values_from = value 34 | #' ) |> 35 | #' ggplot(aes(x1, x2, fill = estimate)) + 36 | #' geom_tile() + 37 | #' theme_void() 38 | #' 39 | #' # also works with 3 dimensions 40 | #' dat3 <- replicate(3, rnorm(100)) 41 | #' k3 <- kde(dat3) 42 | #' 43 | #' td3 <- tidy(k3) 44 | #' td3 45 | #' 46 | #' @export 47 | #' @aliases kde_tidiers ks_tidiers 48 | #' @seealso [tidy()], [ks::kde()] 49 | tidy.kde <- function(x, ...) { 50 | estimate <- x$estimate |> 51 | as.data.frame.table(responseName = "value") |> 52 | dplyr::mutate_if(is.factor, as.integer) 53 | 54 | dims <- seq_len(length(x$eval.points)) 55 | 56 | purrr::map2( 57 | x$eval.points, 58 | estimate[dims], 59 | function(e, d) e[d] 60 | ) |> 61 | purrr::set_names(paste0("x", dims)) |> 62 | as_tibble() |> 63 | mutate( 64 | estimate = estimate$value, 65 | obs = row_number() 66 | ) |> 67 | pivot_longer( 68 | cols = c(dplyr::everything(), -estimate, -obs), 69 | names_to = "variable", 70 | values_to = "value" 71 | ) |> 72 | arrange(variable, obs) |> 73 | select(obs, variable, value, estimate) 74 | } 75 | -------------------------------------------------------------------------------- /R/leaps.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class regsubsets 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `regsubsets` object created by [leaps::regsubsets()]. 5 | #' @template param_unused_dots 6 | #' 7 | # # define the documentation manually since r-squared and BIC are unusual 8 | # # elements of a tidy method output 9 | #' @evalRd return_tidy( 10 | #' r.squared = "R squared statistic, or the percent of variation explained by the model.", 11 | #' adj.r.squared = "Adjusted R squared statistic", 12 | #' BIC = "Bayesian information criterion for the component.", 13 | #' mallows_cp = "Mallow's Cp statistic." 14 | #' ) 15 | #' 16 | #' @examplesIf rlang::is_installed("leaps") 17 | #' 18 | #' # load libraries for models and data 19 | #' library(leaps) 20 | #' 21 | #' # fit model 22 | #' all_fits <- regsubsets(hp ~ ., mtcars) 23 | #' 24 | #' # summarize model fit with tidiers 25 | #' tidy(all_fits) 26 | #' 27 | #' @aliases leaps_tidiers 28 | #' @export 29 | #' @seealso [tidy()], [leaps::regsubsets()] 30 | tidy.regsubsets <- function(x, ...) { 31 | s <- summary(x) 32 | inclusions <- as_tibble(s$which) 33 | metrics <- with( 34 | s, 35 | tibble( 36 | r.squared = rsq, 37 | adj.r.squared = adjr2, 38 | BIC = bic, 39 | mallows_cp = cp 40 | ) 41 | ) 42 | bind_cols(inclusions, metrics) 43 | } 44 | -------------------------------------------------------------------------------- /R/list-irlba.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class irlba 2 | #' @template title_desc_tidy_list 3 | #' 4 | #' @param x A list returned from [irlba::irlba()]. 5 | #' 6 | #' @inherit tidy_svd return params examples 7 | #' 8 | #' @details A very thin wrapper around [tidy_svd()]. 9 | #' 10 | #' @aliases tidy.irlba irlba_tidiers 11 | #' @family list tidiers 12 | #' @family svd tidiers 13 | #' @seealso [tidy()], [irlba::irlba()] 14 | #' @export 15 | tidy_irlba <- function(x, ...) { 16 | tidy_svd(x, ...) 17 | } 18 | -------------------------------------------------------------------------------- /R/list-optim.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class optim 2 | #' @template title_desc_tidy_list 3 | #' 4 | #' @param x A list returned from [stats::optim()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy( 8 | #' "parameter", 9 | #' "value", 10 | #' "std.error", 11 | #' .post = "\\code{std.error} is only provided as a column if the Hessian is calculated." 12 | #' ) 13 | #' 14 | #' @examples 15 | #' 16 | #' f <- function(x) (x[1] - 2)^2 + (x[2] - 3)^2 + (x[3] - 8)^2 17 | #' o <- optim(c(1, 1, 1), f) 18 | #' 19 | #' @note 20 | #' This function assumes that the provided objective function is a negative 21 | #' log-likelihood function. Results will be invalid if an incorrect 22 | #' function is supplied. 23 | #' 24 | #' tidy(o) 25 | #' glance(o) 26 | #' @aliases optim_tidiers tidy.optim 27 | #' @family list tidiers 28 | #' @seealso [tidy()], [stats::optim()] 29 | tidy_optim <- function(x, ...) { 30 | if (is.null(names(x$par))) { 31 | names(x$par) <- paste0("parameter", seq_along(x$par)) 32 | } 33 | ret <- tibble(parameter = names(x$par), value = unname(x$par)) 34 | if ("hessian" %in% names(x)) { 35 | ret$std.error <- sqrt(diag(solve(x$hessian))) 36 | } 37 | ret 38 | } 39 | 40 | #' @templateVar class optim 41 | #' @template title_desc_tidy_list 42 | #' 43 | #' @inherit tidy_optim params examples 44 | #' 45 | #' @evalRd return_glance( 46 | #' "value", 47 | #' "function.count", 48 | #' "gradient.count", 49 | #' "convergence" 50 | #' ) 51 | #' 52 | #' @aliases glance.optim 53 | #' @family list tidiers 54 | #' @seealso [glance()], [stats::optim()] 55 | glance_optim <- function(x, ...) { 56 | as_glance_tibble( 57 | value = x$value, 58 | function.count = unname(x$counts["function"]), 59 | gradient.count = unname(x$counts["gradient"]), 60 | convergence = x$convergence, 61 | na_types = "riii" 62 | ) 63 | } 64 | -------------------------------------------------------------------------------- /R/list-xyz.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class xyz 2 | #' @template title_desc_tidy_list 3 | #' 4 | #' @description xyz lists (lists where `x` and `y` are vectors of coordinates 5 | #' and `z` is a matrix of values) are typically used by functions such as 6 | #' [graphics::persp()] or [graphics::image()] and returned 7 | #' by interpolation functions such as [interp::interp()]. 8 | #' 9 | #' @param x A list with component `x`, `y` and `z`, where `x` and `y` are 10 | #' vectors and `z` is a matrix. The length of `x` must equal the number of 11 | #' rows in `z` and the length of `y` must equal the number of columns in `z`. 12 | #' @template param_unused_dots 13 | #' 14 | #' @return A [tibble::tibble] with vector columns `x`, `y` and `z`. 15 | #' 16 | #' @examples 17 | #' 18 | #' A <- list(x = 1:5, y = 1:3, z = matrix(runif(5 * 3), nrow = 5)) 19 | #' image(A) 20 | #' tidy(A) 21 | #' @aliases xyz_tidiers 22 | #' @family list tidiers 23 | #' @seealso [tidy()], [graphics::persp()], [graphics::image()], 24 | #' [interp::interp()] 25 | #' 26 | tidy_xyz <- function(x, ...) { 27 | if (!is.matrix(x$z)) { 28 | cli::cli_abort("{.arg z} must be a matrix.") 29 | } 30 | 31 | if (length(x$x) != nrow(x$z) || length(x$y) != ncol(x$z)) { 32 | cli::cli_abort(c( 33 | "To tidy an xyz list, the length of element {.code x} must equal the 34 | number of rows of element {.code z}, and the length of element 35 | {.code y} must equal the number of columns of element {.code z}." 36 | )) 37 | } 38 | 39 | as_tibble(data.frame( 40 | x = x$x, 41 | y = rep(x$y, each = length(x$x)), 42 | z = as.numeric(x$z) 43 | )) 44 | } 45 | -------------------------------------------------------------------------------- /R/list.R: -------------------------------------------------------------------------------- 1 | #' Tidying methods for lists / returned values that are not S3 objects 2 | #' 3 | #' Broom tidies a number of lists that are effectively S3 objects without 4 | #' a class attribute. For example, [stats::optim()], [base::svd()] and 5 | #' [interp::interp()] produce consistent output, but because they do not 6 | #' have a class attribute, they cannot be handled by S3 dispatch. 7 | #' 8 | #' These functions look at the elements of a list and determine if there is 9 | #' an appropriate tidying method to apply to the list. Those tidiers are 10 | #' themselves are implemented as functions of the form `tidy_` 11 | #' or `glance_` and are not exported (but they are documented!). 12 | #' 13 | #' If no appropriate tidying method is found, throws an error. 14 | #' 15 | #' @param x A list, potentially representing an object that can be tidied. 16 | #' @param ... Additionally, arguments passed to the tidying function. 17 | #' 18 | #' @name list_tidiers 19 | #' @export 20 | #' @family list tidiers 21 | tidy.list <- function(x, ...) { 22 | optim_elems <- c("par", "value", "counts", "convergence", "message") 23 | xyz_elems <- c("x", "y", "z") 24 | svd_elems <- c("d", "u", "v") 25 | irlba_elems <- c(svd_elems, "iter", "mprod") 26 | 27 | if (all(optim_elems %in% names(x))) { 28 | tidy_optim(x, ...) 29 | } else if (all(xyz_elems %in% names(x))) { 30 | tidy_xyz(x, ...) 31 | } else if (all(irlba_elems %in% names(x))) { 32 | tidy_irlba(x, ...) 33 | } else if (all(svd_elems %in% names(x))) { 34 | tidy_svd(x, ...) 35 | } else { 36 | cli::cli_abort("No {.fn tidy} method recognized for this list.") 37 | } 38 | } 39 | 40 | #' @rdname list_tidiers 41 | #' @export 42 | glance.list <- function(x, ...) { 43 | optim_elems <- c("par", "value", "counts", "convergence", "message") 44 | 45 | if (all(optim_elems %in% names(x))) { 46 | glance_optim(x, ...) 47 | } else { 48 | cli::cli_abort("No {.fn glance} method recognized for this list.") 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /R/lm-beta.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class lm.beta 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x An `lm.beta` object created by [lm.beta::lm.beta]. 5 | #' @template param_confint 6 | #' @template param_unused_dots 7 | #' 8 | #' @evalRd return_tidy(regression = TRUE) 9 | #' 10 | #' @details If the linear model is an `mlm` object (multiple linear model), 11 | #' there is an additional column `response`. 12 | #' 13 | #' If you have missing values in your model data, you may need to refit 14 | #' the model with `na.action = na.exclude`. 15 | #' 16 | #' @examplesIf rlang::is_installed("lm.beta") 17 | #' 18 | #' # load libraries for models and data 19 | #' library(lm.beta) 20 | #' 21 | #' # fit models 22 | #' mod <- stats::lm(speed ~ ., data = cars) 23 | #' std <- lm.beta(mod) 24 | #' 25 | #' # summarize model fit with tidiers 26 | #' tidy(std, conf.int = TRUE) 27 | #' 28 | #' # generate data 29 | #' ctl <- c(4.17, 5.58, 5.18, 6.11, 4.50, 4.61, 5.17, 4.53, 5.33, 5.14) 30 | #' trt <- c(4.81, 4.17, 4.41, 3.59, 5.87, 3.83, 6.03, 4.89, 4.32, 4.69) 31 | #' group <- gl(2, 10, 20, labels = c("Ctl", "Trt")) 32 | #' weight <- c(ctl, trt) 33 | #' 34 | #' # fit models 35 | #' mod2 <- lm(weight ~ group) 36 | #' std2 <- lm.beta(mod2) 37 | #' 38 | #' # summarize model fit with tidiers 39 | #' tidy(std2, conf.int = TRUE) 40 | #' 41 | #' @export 42 | #' @family lm tidiers 43 | tidy.lm.beta <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { 44 | check_ellipses("exponentiate", "tidy", "lm.beta", ...) 45 | 46 | ret <- as_tibble(summary(x)$coefficients, rownames = "term") 47 | colnames(ret) <- c( 48 | "term", 49 | "estimate", 50 | "std_estimate", 51 | "std.error", 52 | "statistic", 53 | "p.value" 54 | ) 55 | 56 | if (conf.int) { 57 | ci <- broom_confint_terms(x, level = conf.level) 58 | ret <- dplyr::left_join(ret, ci, by = "term") 59 | } 60 | 61 | ret 62 | } 63 | -------------------------------------------------------------------------------- /R/maps.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class map 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `map` object returned from [maps::map()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy( 8 | #' "term", 9 | #' long = "Longitude.", 10 | #' lat = "Latitude.", 11 | #' .post = "Remaining columns give information on geographic attributes 12 | #' and depend on the inputted map object. See ?maps::map for more information." 13 | #' ) 14 | #' 15 | #' @examplesIf rlang::is_installed(c("maps", "ggplot2")) 16 | #' 17 | #' # load libraries for models and data 18 | #' library(maps) 19 | #' library(ggplot2) 20 | #' 21 | #' ca <- map("county", "ca", plot = FALSE, fill = TRUE) 22 | #' 23 | #' tidy(ca) 24 | #' 25 | #' qplot(long, lat, data = ca, geom = "polygon", group = group) 26 | #' 27 | #' tx <- map("county", "texas", plot = FALSE, fill = TRUE) 28 | #' tidy(tx) 29 | #' qplot(long, lat, 30 | #' data = tx, geom = "polygon", group = group, 31 | #' colour = I("white") 32 | #' ) 33 | #' 34 | #' @export 35 | #' @seealso [tidy()], [maps::map()] 36 | #' @aliases maps_tidiers 37 | tidy.map <- function(x, ...) { 38 | df <- as.data.frame(x[c("x", "y")]) 39 | names(df) <- c("long", "lat") 40 | df$group <- cumsum(is.na(df$long) & is.na(df$lat)) + 1 41 | df$order <- 1:nrow(df) 42 | 43 | names <- do.call("rbind", lapply(strsplit(x$names, "[:,]"), "[", 1:2)) 44 | df$region <- names[df$group, 1] 45 | df$subregion <- names[df$group, 2] 46 | as_tidy_tibble(df[stats::complete.cases(df$lat, df$long), ]) 47 | } 48 | -------------------------------------------------------------------------------- /R/mass-fitdistr.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class fitdistr 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `fitdistr` object returned by [MASS::fitdistr()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy("term", "estimate", "std.error") 8 | #' 9 | #' @examplesIf rlang::is_installed("MASS") 10 | #' 11 | #' # load libraries for models and data 12 | #' library(MASS) 13 | #' 14 | #' # generate data 15 | #' set.seed(2015) 16 | #' x <- rnorm(100, 5, 2) 17 | #' 18 | #' # fit models 19 | #' fit <- fitdistr(x, dnorm, list(mean = 3, sd = 1)) 20 | #' 21 | #' # summarize model fit with tidiers 22 | #' tidy(fit) 23 | #' glance(fit) 24 | #' 25 | #' @export 26 | #' @family fitdistr tidiers 27 | #' @aliases fitdistr_tidiers 28 | #' @seealso [tidy()], [MASS::fitdistr()] 29 | tidy.fitdistr <- function(x, ...) { 30 | tibble( 31 | term = names(x$estimate), 32 | estimate = unname(x$estimate), 33 | std.error = unname(x$sd) 34 | ) 35 | } 36 | 37 | 38 | #' @templateVar class fitdistr 39 | #' @template title_desc_glance 40 | #' 41 | #' @inherit tidy.fitdistr params examples 42 | #' 43 | #' @evalRd return_glance("logLik", "AIC", "BIC", "nobs") 44 | #' 45 | #' @export 46 | #' @family fitdistr tidiers 47 | #' @seealso [tidy()], [MASS::fitdistr()] 48 | glance.fitdistr <- function(x, ...) { 49 | as_glance_tibble( 50 | logLik = stats::logLik(x), 51 | AIC = stats::AIC(x), 52 | BIC = stats::BIC(x), 53 | nobs = stats::nobs(x), 54 | na_types = "rrri" 55 | ) 56 | } 57 | -------------------------------------------------------------------------------- /R/muhaz.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class muhaz 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `muhaz` object returned by [muhaz::muhaz()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy( 8 | #' "time", 9 | #' estimate = "Estimated hazard rate." 10 | #' ) 11 | #' 12 | #' @examplesIf rlang::is_installed(c("muhaz", "survival")) 13 | #' 14 | #' # load libraries for models and data 15 | #' library(muhaz) 16 | #' library(survival) 17 | #' 18 | #' # fit model 19 | #' x <- muhaz(ovarian$futime, ovarian$fustat) 20 | #' 21 | #' # summarize model fit with tidiers 22 | #' tidy(x) 23 | #' glance(x) 24 | #' 25 | #' @aliases muhaz_tidiers 26 | #' @export 27 | #' @seealso [tidy()], [muhaz::muhaz()] 28 | #' @family muhaz tidiers 29 | tidy.muhaz <- function(x, ...) { 30 | bind_cols(x[c("est.grid", "haz.est")]) |> 31 | rename("time" = "est.grid", "estimate" = "haz.est") |> 32 | as_tibble() 33 | } 34 | 35 | #' @templateVar class muhaz 36 | #' @template title_desc_glance 37 | #' 38 | #' @inherit tidy.muhaz params examples 39 | #' 40 | #' @evalRd return_glance( 41 | #' "nobs", 42 | #' "min.time", 43 | #' "max.time", 44 | #' "min.hazard", 45 | #' "max.hazard" 46 | #' ) 47 | #' 48 | #' @export 49 | #' @seealso [glance()], [muhaz::muhaz()] 50 | #' @family muhaz tidiers 51 | glance.muhaz <- function(x, ...) { 52 | bind_cols(x$pin[c("nobs", "min.time", "max.time")]) |> 53 | mutate( 54 | min.hazard = min(x$haz.est), 55 | max.hazard = max(x$haz.est) 56 | ) |> 57 | as_tibble() 58 | } 59 | -------------------------------------------------------------------------------- /R/null-and-default.R: -------------------------------------------------------------------------------- 1 | #' Tidiers for NULL inputs 2 | #' 3 | #' `tidy(NULL)`, `glance(NULL)` and `augment(NULL)` all return an empty 4 | #' [tibble::tibble]. This empty tibble can be treated a tibble with zero 5 | #' rows, making it convenient to combine with other tibbles using 6 | #' functions like [purrr::map_df()] on lists of potentially `NULL` objects. 7 | #' 8 | #' @param x The value `NULL`. 9 | #' @param ... Additional arguments (not used). 10 | #' 11 | #' @return An empty [tibble::tibble]. 12 | #' 13 | #' @name null_tidiers 14 | #' @export 15 | #' @seealso [tibble::tibble] 16 | tidy.NULL <- function(x, ...) { 17 | tibble() 18 | } 19 | 20 | #' @rdname null_tidiers 21 | #' @export 22 | glance.NULL <- function(x, ...) tibble() 23 | 24 | #' @rdname null_tidiers 25 | #' @export 26 | augment.NULL <- function(x, ...) tibble() 27 | 28 | 29 | #' @export 30 | tidy.default <- function(x, ...) { 31 | cli::cli_abort("No {.fn tidy} method for objects of class {.cls {class(x)}}.") 32 | } 33 | 34 | #' @export 35 | glance.default <- function(x, ...) { 36 | cli::cli_abort( 37 | "No {.fn glance} method for objects of class {.cls {class(x)}}." 38 | ) 39 | } 40 | 41 | #' @export 42 | augment.default <- function(x, ...) { 43 | cli::cli_abort( 44 | "No {.fn augment} method for objects of class {.cls {class(x)}}." 45 | ) 46 | } 47 | -------------------------------------------------------------------------------- /R/psych.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class kappa 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `kappa` object returned from [psych::cohen.kappa()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy( 8 | #' type = "Either `weighted` or `unweighted`.", 9 | #' "estimate", 10 | #' "conf.low", 11 | #' "conf.high" 12 | #' ) 13 | #' 14 | #' @details Note that confidence level (alpha) for the confidence interval 15 | #' cannot be set in `tidy`. Instead you must set the `alpha` argument 16 | #' to [psych::cohen.kappa()] when creating the `kappa` object. 17 | #' 18 | #' @examplesIf rlang::is_installed(c("psych", "ggplot2")) 19 | #' 20 | #' # load libraries for models and data 21 | #' library(psych) 22 | #' 23 | #' # generate example data 24 | #' rater1 <- 1:9 25 | #' rater2 <- c(1, 3, 1, 6, 1, 5, 5, 6, 7) 26 | #' 27 | #' # fit model 28 | #' ck <- cohen.kappa(cbind(rater1, rater2)) 29 | #' 30 | #' # summarize model fit with tidiers + visualization 31 | #' tidy(ck) 32 | #' 33 | #' # graph the confidence intervals 34 | #' library(ggplot2) 35 | #' 36 | #' ggplot(tidy(ck), aes(estimate, type)) + 37 | #' geom_point() + 38 | #' geom_errorbarh(aes(xmin = conf.low, xmax = conf.high)) 39 | #' 40 | #' @aliases kappa_tidiers psych_tidiers 41 | #' @export 42 | #' @seealso [tidy()], [psych::cohen.kappa()] 43 | #' 44 | tidy.kappa <- function(x, ...) { 45 | ret <- as_tidy_tibble( 46 | x$confid, 47 | new_names = c("conf.low", "estimate", "conf.high"), 48 | new_column = "type" 49 | ) |> 50 | dplyr::select(type, estimate, conf.low, conf.high) |> 51 | mutate(type = gsub(" kappa", "", type)) 52 | 53 | ret 54 | } 55 | -------------------------------------------------------------------------------- /R/robust-glmrob.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class glmRob 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `glmRob` object returned from [robust::glmRob()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @details For tidiers for robust models from the \pkg{MASS} package see 8 | #' [tidy.rlm()]. 9 | #' 10 | #' @examplesIf rlang::is_installed("robust") 11 | #' 12 | #' # load libraries for models and data 13 | #' library(robust) 14 | #' 15 | #' # fit model 16 | #' gm <- glmRob(am ~ wt, data = mtcars, family = "binomial") 17 | #' 18 | #' # summarize model fit with tidiers 19 | #' tidy(gm) 20 | #' glance(gm) 21 | #' 22 | #' @export 23 | #' @family robust tidiers 24 | #' @seealso [robust::glmRob()] 25 | tidy.glmRob <- function(x, ...) { 26 | co <- stats::coef(summary(x)) 27 | ret <- as_tibble(co, rownames = "term") 28 | names(ret) <- c("term", "estimate", "std.error", "statistic", "p.value") 29 | ret 30 | } 31 | 32 | #' @templateVar class glmRob 33 | #' @template title_desc_augment 34 | #' 35 | #' @param x Unused. 36 | #' @param ... Unused. 37 | #' 38 | #' @export 39 | augment.glmRob <- function(x, ...) { 40 | cli::cli_abort(c( 41 | "{.fn augment.glmRob} has been deprecated as the {.pkg robust} package 42 | doesn't provide the functionality necessary to implement 43 | an augment method.", 44 | "i" = "Please see the augment method for {.cls glmrob} objects from 45 | {.pkg robustbase}." 46 | )) 47 | invisible(TRUE) 48 | } 49 | 50 | #' @templateVar class glmRob 51 | #' @template title_desc_glance 52 | #' 53 | #' @inherit tidy.glmRob params examples 54 | #' @template param_unused_dots 55 | #' 56 | #' @evalRd return_glance( 57 | #' "deviance", 58 | #' "sigma", 59 | #' "null.deviance", 60 | #' "df.residual", 61 | #' "nobs" 62 | #' ) 63 | #' 64 | #' @export 65 | #' @family robust tidiers 66 | #' @seealso [robust::glmRob()] 67 | #' 68 | glance.glmRob <- function(x, ...) { 69 | as_glance_tibble( 70 | deviance = x$deviance, 71 | sigma = stats::sigma(x), 72 | null.deviance = x$null.deviance, 73 | df.residual = stats::df.residual(x), 74 | nobs = stats::nobs(x), 75 | na_types = "rrrii" 76 | ) 77 | } 78 | -------------------------------------------------------------------------------- /R/robustbase-glmrob.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class glmrob 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `glmrob` object returned from [robustbase::glmrob()]. 5 | #' @template param_confint 6 | #' @template param_unused_dots 7 | #' 8 | #' @evalRd return_tidy(regression = TRUE) 9 | #' 10 | #' @details For tidiers for robust models from the \pkg{MASS} package see 11 | #' [tidy.rlm()]. 12 | #' 13 | #' @inherit tidy.lmrob examples 14 | #' 15 | #' @export 16 | #' @family robustbase tidiers 17 | #' @rdname tidy.robustbase.glmrob 18 | #' @seealso [robustbase::glmrob()] 19 | tidy.glmrob <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { 20 | ret <- coef(summary(x)) |> 21 | as_tibble(rownames = "term") 22 | names(ret) <- c("term", "estimate", "std.error", "statistic", "p.value") 23 | 24 | if (conf.int) { 25 | ci <- stats::confint.default(x, level = conf.level) |> 26 | as_tibble() 27 | 28 | names(ci) <- c("conf.low", "conf.high") 29 | ret <- ret |> 30 | cbind(ci) 31 | } 32 | 33 | ret 34 | } 35 | 36 | 37 | #' @templateVar class glmrob 38 | #' @template title_desc_augment 39 | #' 40 | #' @inherit tidy.glmrob params 41 | #' @template param_data 42 | #' @template param_newdata 43 | #' @template param_se_fit 44 | #' @template param_type_predict 45 | #' @template param_type_residuals 46 | #' @template param_unused_dots 47 | #' 48 | #' @evalRd return_augment() 49 | #' @details For tidiers for robust models from the \pkg{MASS} package see 50 | #' [tidy.rlm()]. 51 | #' 52 | #' @inherit tidy.lmrob examples 53 | #' 54 | #' @export 55 | #' @family robustbase tidiers 56 | #' @rdname augment.robustbase.glmrob 57 | #' @seealso [robustbase::glmrob()] 58 | augment.glmrob <- function( 59 | x, 60 | data = model.frame(x), 61 | newdata = NULL, 62 | type.predict = c("link", "response"), 63 | type.residuals = c("deviance", "pearson"), 64 | se_fit = FALSE, 65 | ... 66 | ) { 67 | augment_newdata( 68 | x, 69 | data, 70 | newdata, 71 | type.predict = type.predict, 72 | type.residuals = type.residuals, 73 | .se_fit = se_fit 74 | ) 75 | } 76 | -------------------------------------------------------------------------------- /R/stats-arima.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class Arima 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x An object of class `Arima` created by [stats::arima()]. 5 | #' @template param_confint 6 | #' @template param_unused_dots 7 | #' 8 | #' @evalRd return_tidy( 9 | #' "term", 10 | #' "estimate", 11 | #' "std.error", 12 | #' "conf.low", 13 | #' "conf.high" 14 | #' ) 15 | #' 16 | #' @examples 17 | #' 18 | #' # fit model 19 | #' fit <- arima(lh, order = c(1, 0, 0)) 20 | #' 21 | #' # summarize model fit with tidiers 22 | #' tidy(fit) 23 | #' glance(fit) 24 | #' 25 | #' @aliases Arima_tidiers 26 | #' @seealso [stats::arima()] 27 | #' @export 28 | #' @family Arima tidiers 29 | tidy.Arima <- function(x, conf.int = FALSE, conf.level = 0.95, ...) { 30 | check_ellipses("exponentiate", "tidy", "Arima", ...) 31 | 32 | coefs <- stats::coef(x) 33 | # standard errors are computed as in stats:::print.Arima 34 | ses <- rep.int(0, length(coefs)) 35 | ses[x$mask] <- sqrt(diag(x$var.coef)) 36 | 37 | ret <- unrowname(data.frame( 38 | term = names(coefs), 39 | estimate = coefs, 40 | std.error = ses 41 | )) 42 | 43 | if (conf.int) { 44 | ci <- broom_confint_terms(x, level = conf.level) 45 | ret <- dplyr::left_join(ret, ci, by = "term") 46 | } 47 | 48 | as_tibble(ret) 49 | } 50 | 51 | 52 | #' @templateVar class Arima 53 | #' @template title_desc_glance 54 | #' 55 | #' @inherit tidy.Arima params examples 56 | #' 57 | #' @evalRd return_glance("sigma", "logLik", "AIC", "BIC", "nobs") 58 | #' 59 | #' @seealso [stats::arima()] 60 | #' @export 61 | #' @family Arima tidiers 62 | glance.Arima <- function(x, ...) { 63 | ret <- tibble(sigma = sqrt(x$sigma2)) 64 | ret$logLik <- tryCatch(as.numeric(stats::logLik(x)), error = function(e) NULL) 65 | # special case for class Arima when method = "CSS" 66 | if (!is.na(ret$logLik)) { 67 | ret$AIC <- tryCatch(stats::AIC(x), error = function(e) NULL) 68 | ret$BIC <- tryCatch(stats::BIC(x), error = function(e) NULL) 69 | } 70 | ret$nobs <- stats::nobs(x) 71 | as_tibble(ret) 72 | } 73 | -------------------------------------------------------------------------------- /R/stats-loess.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class loess 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `loess` objects returned by [stats::loess()]. 5 | #' @template param_data 6 | #' @template param_newdata 7 | #' @template param_se_fit 8 | #' @template param_unused_dots 9 | #' 10 | #' @template augment_NAs 11 | #' 12 | #' @evalRd return_augment(".se.fit") 13 | #' 14 | #' @details Note that `loess` objects by default will not predict on data 15 | #' outside of a bounding hypercube defined by the training data unless the 16 | #' original `loess` object was fit with 17 | #' `control = loess.control(surface = \"direct\"))`. See 18 | #' [stats::predict.loess()] for details. 19 | #' 20 | #' @examples 21 | #' 22 | #' lo <- loess( 23 | #' mpg ~ hp + wt, 24 | #' mtcars, 25 | #' control = loess.control(surface = "direct") 26 | #' ) 27 | #' 28 | #' augment(lo) 29 | #' 30 | #' # with all columns of original data 31 | #' augment(lo, mtcars) 32 | #' 33 | #' # with a new dataset 34 | #' augment(lo, newdata = head(mtcars)) 35 | #' 36 | #' @aliases loess_tidiers 37 | #' @export 38 | #' @seealso [augment()], [stats::loess()], [stats::predict.loess()] 39 | augment.loess <- function( 40 | x, 41 | data = model.frame(x), 42 | newdata = NULL, 43 | se_fit = FALSE, 44 | ... 45 | ) { 46 | augment_newdata(x, data, newdata, se_fit, se = se_fit) 47 | } 48 | -------------------------------------------------------------------------------- /R/stats-smooth.spline.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class smooth.spline 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `smooth.spline` object returned from [stats::smooth.spline()]. 5 | #' @template param_data 6 | #' @template param_unused_dots 7 | #' 8 | # sometimes triggers CRAN NOTE `elapsed time > 10s` 9 | #' @examplesIf FALSE 10 | #' 11 | #' # fit model 12 | #' spl <- smooth.spline(mtcars$wt, mtcars$mpg, df = 4) 13 | #' 14 | #' # summarize model fit with tidiers 15 | #' augment(spl, mtcars) 16 | #' 17 | #' # calls original columns x and y 18 | #' augment(spl) 19 | #' 20 | #' library(ggplot2) 21 | #' ggplot(augment(spl, mtcars), aes(wt, mpg)) + 22 | #' geom_point() + 23 | #' geom_line(aes(y = .fitted)) 24 | #' 25 | #' @evalRd return_augment() 26 | #' 27 | #' @aliases smooth.spline_tidiers 28 | #' @export 29 | #' @family smoothing spline tidiers 30 | #' @seealso [augment()], [stats::smooth.spline()], 31 | #' [stats::predict.smooth.spline()] 32 | augment.smooth.spline <- function(x, data = x$data, ...) { 33 | check_ellipses("newdata", "augment", "smooth.spline", ...) 34 | 35 | data <- as_tibble(data) 36 | data$.fitted <- stats::fitted(x) 37 | data$.resid <- stats::resid(x) 38 | data 39 | } 40 | 41 | 42 | #' @templateVar class smooth.spine 43 | #' @template title_desc_tidy 44 | #' 45 | #' @inherit augment.smooth.spline params examples 46 | #' 47 | #' @evalRd return_glance( 48 | #' "spar", 49 | #' "lambda", 50 | #' "df", 51 | #' "crit", 52 | #' "pen.crit", 53 | #' "cv.crit", 54 | #' "nobs" 55 | #' ) 56 | #' 57 | #' @export 58 | #' @family smoothing spline tidiers 59 | #' @seealso [augment()], [stats::smooth.spline()] 60 | #' 61 | glance.smooth.spline <- function(x, ...) { 62 | ret <- x[c("df", "lambda", "cv.crit", "pen.crit", "crit", "spar")] 63 | ret <- as_tibble(ret) 64 | ret$nobs <- stats::nobs(x) 65 | ret 66 | } 67 | -------------------------------------------------------------------------------- /R/survival-aareg.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class aareg 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x An `aareg` object returned from [survival::aareg()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy( 8 | #' "term", 9 | #' "estimate", 10 | #' "statistic", 11 | #' "std.error", 12 | #' "robust.se", 13 | #' "z", 14 | #' "p.value" 15 | #' ) 16 | #' 17 | #' @details `robust.se` is only present when `x` was created with 18 | #' `dfbeta = TRUE`. 19 | #' 20 | #' @examplesIf rlang::is_installed("survival") 21 | #' 22 | #' # load libraries for models and data 23 | #' library(survival) 24 | #' 25 | #' # fit model 26 | #' afit <- aareg( 27 | #' Surv(time, status) ~ age + sex + ph.ecog, 28 | #' data = lung, 29 | #' dfbeta = TRUE 30 | #' ) 31 | #' 32 | #' # summarize model fit with tidiers 33 | #' tidy(afit) 34 | #' 35 | #' @aliases aareg_tidiers 36 | #' @export 37 | #' @seealso [tidy()], [survival::aareg()] 38 | #' @family aareg tidiers 39 | #' @family survival tidiers 40 | #' 41 | tidy.aareg <- function(x, ...) { 42 | if (is.null(x$dfbeta)) { 43 | nn <- c("estimate", "statistic", "std.error", "statistic.z", "p.value") 44 | } else { 45 | nn <- c( 46 | "estimate", 47 | "statistic", 48 | "std.error", 49 | "robust.se", 50 | "statistic.z", 51 | "p.value" 52 | ) 53 | } 54 | 55 | as_tidy_tibble( 56 | summary(x)$table, 57 | new_names = nn 58 | ) 59 | } 60 | 61 | #' @templateVar class aareg 62 | #' @template title_desc_glance 63 | #' 64 | #' @inherit tidy.aareg params examples 65 | #' 66 | #' @evalRd return_glance("statistic", "p.value", "df", "nobs") 67 | #' 68 | #' @export 69 | #' @seealso [glance()], [survival::aareg()] 70 | #' @family aareg tidiers 71 | #' @family survival tidiers 72 | glance.aareg <- function(x, ...) { 73 | s <- summary(x) 74 | chi <- as.numeric(s$chisq) 75 | df <- length(s$test.statistic) - 1 76 | 77 | as_glance_tibble( 78 | statistic = chi, 79 | p.value = as.numeric(1 - stats::pchisq(chi, df)), 80 | df = df, 81 | nobs = stats::nobs(x), 82 | na_types = "rrii" 83 | ) 84 | } 85 | -------------------------------------------------------------------------------- /R/survival-survexp.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class survexp 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x An `survexp` object returned from [survival::survexp()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy("time", "n.risk", 8 | #' estimate = "Estimate survival" 9 | #' ) 10 | #' 11 | #' @examplesIf rlang::is_installed("survival") 12 | #' 13 | #' # load libraries for models and data 14 | #' library(survival) 15 | #' 16 | #' # fit model 17 | #' sexpfit <- survexp( 18 | #' futime ~ 1, 19 | #' rmap = list( 20 | #' sex = "male", 21 | #' year = accept.dt, 22 | #' age = (accept.dt - birth.dt) 23 | #' ), 24 | #' method = "conditional", 25 | #' data = jasa 26 | #' ) 27 | #' 28 | #' # summarize model fit with tidiers 29 | #' tidy(sexpfit) 30 | #' glance(sexpfit) 31 | #' 32 | #' @aliases sexpfit_tidiers survexp_tidiers 33 | #' @export 34 | #' @seealso [tidy()], [survival::survexp()] 35 | #' @family survexp tidiers 36 | #' @family survival tidiers 37 | tidy.survexp <- function(x, ...) { 38 | ret <- as_tibble(summary(x)[c("time", "surv", "n.risk")]) 39 | rename(ret, "estimate" = "surv") 40 | } 41 | 42 | 43 | #' @templateVar class survexp 44 | #' @template title_desc_glance 45 | #' 46 | #' @inherit tidy.survexp params examples 47 | #' 48 | #' @evalRd return_glance("n.max", "n.start", "timepoints") 49 | #' 50 | #' @export 51 | #' @seealso [glance()], [survival::survexp()] 52 | #' @family survexp tidiers 53 | #' @family survival tidiers 54 | glance.survexp <- function(x, ...) { 55 | as_glance_tibble( 56 | n.max = max(x$n.risk), 57 | n.start = x$n.risk[1], 58 | timepoints = length(x$n.risk), 59 | na_types = "iii" 60 | ) 61 | } 62 | -------------------------------------------------------------------------------- /R/sysdata.rda: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/R/sysdata.rda -------------------------------------------------------------------------------- /R/systemfit.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class systemfit 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `systemfit` object produced by a call to [systemfit::systemfit()]. 5 | #' @template param_confint 6 | #' @template param_unused_dots 7 | #' 8 | #' @evalRd return_tidy( 9 | #' "term", 10 | #' "estimate", 11 | #' "std.error", 12 | #' "p.value", 13 | #' "conf.low", 14 | #' "conf.high" 15 | #' ) 16 | #' 17 | #' @details This tidy method works with any model objects of class `systemfit`. 18 | #' Default returns a tibble of six columns. 19 | #' 20 | #' @examplesIf rlang::is_installed("systemfit") 21 | #' 22 | #' set.seed(27) 23 | #' 24 | #' # load libraries for models and data 25 | #' library(systemfit) 26 | #' 27 | #' # generate data 28 | #' df <- data.frame( 29 | #' X = rnorm(100), 30 | #' Y = rnorm(100), 31 | #' Z = rnorm(100), 32 | #' W = rnorm(100) 33 | #' ) 34 | #' 35 | #' # fit model 36 | #' fit <- systemfit(formula = list(Y ~ Z, W ~ X), data = df, method = "SUR") 37 | #' 38 | #' # summarize model fit with tidiers 39 | #' tidy(fit) 40 | #' tidy(fit, conf.int = TRUE) 41 | #' 42 | #' @export 43 | #' @seealso [tidy()], [systemfit::systemfit()] 44 | #' 45 | #' @family systemfit tidiers 46 | #' @aliases systemfit_tidiers 47 | #' 48 | tidy.systemfit <- function(x, conf.int = TRUE, conf.level = 0.95, ...) { 49 | check_ellipses("exponentiate", "tidy", "systemfit", ...) 50 | 51 | ret <- as_tibble(summary(x)$coefficients, rownames = "term") 52 | colnames(ret) <- c("term", "estimate", "std.error", "statistic", "p.value") 53 | 54 | if (conf.int) { 55 | # can't use broom_confint_terms since the resulting confidence 56 | # intervals are of type `confint.systemfit` not `matrix` 57 | 58 | ci <- confint(x, level = conf.level) 59 | colnames(ci) <- c("conf.low", "conf.high") 60 | ci <- as_tibble(unclass(ci), rownames = "term") 61 | ret <- left_join(ret, ci, by = "term") 62 | } 63 | 64 | ret 65 | } 66 | -------------------------------------------------------------------------------- /R/zoo.R: -------------------------------------------------------------------------------- 1 | #' @templateVar class zoo 2 | #' @template title_desc_tidy 3 | #' 4 | #' @param x A `zoo` object such as those created by [zoo::zoo()]. 5 | #' @template param_unused_dots 6 | #' 7 | #' @evalRd return_tidy("index", "series", "value") 8 | #' 9 | #' @examplesIf rlang::is_installed(c("zoo", "ggplot2")) 10 | #' 11 | #' # load libraries for models and data 12 | #' library(zoo) 13 | #' library(ggplot2) 14 | #' 15 | #' set.seed(1071) 16 | #' 17 | #' # generate data 18 | #' Z.index <- as.Date(sample(12450:12500, 10)) 19 | #' Z.data <- matrix(rnorm(30), ncol = 3) 20 | #' colnames(Z.data) <- c("Aa", "Bb", "Cc") 21 | #' Z <- zoo(Z.data, Z.index) 22 | #' 23 | #' # summarize model fit with tidiers + visualization 24 | #' tidy(Z) 25 | #' 26 | #' ggplot(tidy(Z), aes(index, value, color = series)) + 27 | #' geom_line() 28 | #' 29 | #' ggplot(tidy(Z), aes(index, value)) + 30 | #' geom_line() + 31 | #' facet_wrap(~series, ncol = 1) 32 | #' 33 | #' Zrolled <- rollmean(Z, 5) 34 | #' ggplot(tidy(Zrolled), aes(index, value, color = series)) + 35 | #' geom_line() 36 | #' 37 | #' @aliases zoo_tidiers 38 | #' @export 39 | #' @seealso [tidy()], [zoo::zoo()] 40 | #' @family time series tidiers 41 | tidy.zoo <- function(x, ...) { 42 | # check for univariate zoo series 43 | if (length(dim(x)) > 0) { 44 | ret <- data.frame(as.matrix(x), index = zoo::index(x)) 45 | ret <- tibble::as_tibble(ret) 46 | if (!is.null(colnames(x))) { 47 | colnames(ret)[1:ncol(x)] <- colnames(x) 48 | } 49 | 50 | out <- pivot_longer( 51 | ret, 52 | cols = c(dplyr::everything(), -index), 53 | names_to = "series", 54 | values_to = "value" 55 | ) 56 | } else { 57 | out <- tibble::tibble( 58 | index = zoo::index(x), 59 | value = zoo::coredata(x) 60 | ) 61 | } 62 | return(out) 63 | } 64 | -------------------------------------------------------------------------------- /R/zzz.R: -------------------------------------------------------------------------------- 1 | .onLoad <- function(libname, pkgname) { 2 | backports::import(pkgname) 3 | } 4 | -------------------------------------------------------------------------------- /_pkgdown.yml: -------------------------------------------------------------------------------- 1 | url: https://broom.tidymodels.org 2 | 3 | template: 4 | package: tidytemplate 5 | bootstrap: 5 6 | bslib: 7 | danger: "#CA225E" 8 | primary: "#CA225E" 9 | 10 | includes: 11 | in_header: | 12 | 13 | 14 | development: 15 | mode: auto 16 | 17 | default_assets: false 18 | 19 | reference: 20 | 21 | - title: Tidying generics 22 | contents: 23 | - tidy 24 | - glance 25 | - augment 26 | 27 | - title: Tidiers 28 | contents: 29 | - starts_with('tidy') 30 | - starts_with('glance') 31 | - starts_with('augment') 32 | 33 | - title: Miscellaneous 34 | contents: 35 | - broom 36 | - bootstrap 37 | - confint_tidy 38 | - finish_glance 39 | - fix_data_frame 40 | -------------------------------------------------------------------------------- /air.toml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/air.toml -------------------------------------------------------------------------------- /broom.Rproj: -------------------------------------------------------------------------------- 1 | Version: 1.0 2 | 3 | RestoreWorkspace: No 4 | SaveWorkspace: No 5 | AlwaysSaveHistory: No 6 | 7 | EnableCodeIndexing: Yes 8 | UseSpacesForTab: Yes 9 | NumSpacesForTab: 2 10 | Encoding: UTF-8 11 | 12 | RnwWeave: Sweave 13 | LaTeX: pdfLaTeX 14 | 15 | AutoAppendNewline: Yes 16 | 17 | BuildType: Package 18 | PackageUseDevtools: Yes 19 | PackageInstallArgs: --no-multiarch --with-keep.source 20 | PackageRoxygenize: rd,collate,namespace 21 | -------------------------------------------------------------------------------- /codecov.yml: -------------------------------------------------------------------------------- 1 | comment: false 2 | 3 | coverage: 4 | status: 5 | project: 6 | default: 7 | target: auto 8 | threshold: 1% 9 | informational: true 10 | patch: 11 | default: 12 | target: auto 13 | threshold: 1% 14 | informational: true 15 | -------------------------------------------------------------------------------- /cran-comments.md: -------------------------------------------------------------------------------- 1 | # Reverse dependencies 2 | 3 | We checked 279 reverse dependencies, comparing R CMD check results across CRAN and dev versions of this package, and saw no new NOTEs, WARNINGs, or ERRORs. 4 | -------------------------------------------------------------------------------- /data-raw/long_running_models_for_tests.R: -------------------------------------------------------------------------------- 1 | # some models take a long time to fit. instead of waiting for these models to 2 | # fit each time tests are run, we fit them once here and save the results 3 | # to `R/sysdata.rda`. 4 | # 5 | # if you add an object `my_object` to `usethis::use_data` call at the end 6 | # of this file, you can directly reference `my_object` in your code 7 | # 8 | 9 | library(joineRML) 10 | library(survival) 11 | library(dplyr) 12 | 13 | hvd <- heart.valve |> 14 | filter(!is.na(log.grad), !is.na(log.lvmi), num <= 50) 15 | 16 | mjoint_fit <- mjoint( 17 | formLongFixed = list("grad" = log.grad ~ time + sex + hs), 18 | formLongRandom = list("grad" = ~ 1 | num), 19 | formSurv = survival::Surv(fuyrs, status) ~ age, 20 | data = hvd, 21 | inits = list( 22 | "gamma" = c(0.1, 2.7), 23 | "beta" = c(2.5, 0.0, 0.1, 0.2) 24 | ), 25 | timeVar = "time" 26 | ) 27 | 28 | mjoint_fit2 <- mjoint( 29 | formLongFixed = list( 30 | "grad" = log.grad ~ time + sex + hs, 31 | "lvmi" = log.lvmi ~ time + sex 32 | ), 33 | formLongRandom = list( 34 | "grad" = ~ 1 | num, 35 | "lvmi" = ~ time | num 36 | ), 37 | formSurv = Surv(fuyrs, status) ~ age, 38 | data = hvd, 39 | inits = list( 40 | "gamma" = c(0.11, 1.51, 0.80), 41 | "beta" = c(2.52, 0.01, 0.03, 0.08, 4.99, 0.03, -0.20) 42 | ), 43 | timeVar = "time" 44 | ) 45 | 46 | mjoint_fit_bs_se <- bootSE(mjoint_fit, nboot = 5, safe.boot = TRUE) 47 | mjoint_fit2_bs_se <- bootSE(mjoint_fit2, nboot = 5, safe.boot = TRUE) 48 | 49 | usethis::use_data( 50 | mjoint_fit, 51 | mjoint_fit2, 52 | mjoint_fit_bs_se, 53 | mjoint_fit2_bs_se, 54 | internal = TRUE, 55 | overwrite = TRUE 56 | ) 57 | -------------------------------------------------------------------------------- /man-roxygen/augment_NAs.R: -------------------------------------------------------------------------------- 1 | #' @details When the modeling was performed with `na.action = "na.omit"` 2 | #' (as is the typical default), rows with NA in the initial data are omitted 3 | #' entirely from the augmented data frame. When the modeling was performed 4 | #' with `na.action = "na.exclude"`, one should provide the original data 5 | #' as a second argument, at which point the augmented data will contain those 6 | #' rows (typically with NAs in place of the new columns). If the original data 7 | #' is not provided to [augment()] and `na.action = "na.exclude"`, a 8 | #' warning is raised and the incomplete rows are dropped. 9 | #' 10 | #' @seealso [stats::na.action] 11 | #' @md 12 | -------------------------------------------------------------------------------- /man-roxygen/param_confint.R: -------------------------------------------------------------------------------- 1 | #' @param conf.int Logical indicating whether or not to include a confidence 2 | #' interval in the tidied output. Defaults to `FALSE`. 3 | #' @param conf.level The confidence level to use for the confidence interval 4 | #' if `conf.int = TRUE`. Must be strictly greater than 0 and less than 1. 5 | #' Defaults to 0.95, which corresponds to a 95 percent confidence interval. 6 | #' @md 7 | -------------------------------------------------------------------------------- /man-roxygen/param_data.R: -------------------------------------------------------------------------------- 1 | #' @param data A [base::data.frame] or [tibble::tibble()] containing the original 2 | #' data that was used to produce the object `x`. Defaults to 3 | #' `stats::model.frame(x)` so that `augment(my_fit)` returns the augmented 4 | #' original data. **Do not** pass new data to the `data` argument. 5 | #' Augment will report information such as influence and cooks distance for 6 | #' data passed to the `data` argument. These measures are only defined for 7 | #' the original training data. 8 | #' @md 9 | -------------------------------------------------------------------------------- /man-roxygen/param_exponentiate.R: -------------------------------------------------------------------------------- 1 | #' @param exponentiate Logical indicating whether or not to exponentiate the 2 | #' the coefficient estimates. This is typical for logistic and multinomial 3 | #' regressions, but a bad idea if there is no log or logit link. Defaults 4 | #' to `FALSE`. 5 | #' @md 6 | -------------------------------------------------------------------------------- /man-roxygen/param_interval.R: -------------------------------------------------------------------------------- 1 | #' @param interval Character indicating the type of confidence interval columns 2 | #' to be added to the augmented output. Passed on to `predict()` and defaults 3 | #' to "none". 4 | #' @md 5 | -------------------------------------------------------------------------------- /man-roxygen/param_newdata.R: -------------------------------------------------------------------------------- 1 | #' @param newdata A [base::data.frame()] or [tibble::tibble()] containing all 2 | #' the original predictors used to create `x`. Defaults to `NULL`, indicating 3 | #' that nothing has been passed to `newdata`. If `newdata` is specified, 4 | #' the `data` argument will be ignored. 5 | #' @md 6 | -------------------------------------------------------------------------------- /man-roxygen/param_se_fit.R: -------------------------------------------------------------------------------- 1 | #' @param se_fit Logical indicating whether or not a `.se.fit` column should be 2 | #' added to the augmented output. For some models, this calculation can be 3 | #' somewhat time-consuming. Defaults to `FALSE`. 4 | #' @md 5 | -------------------------------------------------------------------------------- /man-roxygen/param_type_predict.R: -------------------------------------------------------------------------------- 1 | #' @param type.predict Character indicating type of prediction to use. Passed 2 | #' to the `type` argument of the [stats::predict()] generic. Allowed arguments 3 | #' vary with model class, so be sure to read the `predict.my_class` 4 | #' documentation. 5 | #' @md 6 | -------------------------------------------------------------------------------- /man-roxygen/param_type_residuals.R: -------------------------------------------------------------------------------- 1 | #' @param type.residuals Character indicating type of residuals to use. Passed 2 | #' to the `type` argument of [stats::residuals()] generic. Allowed arguments 3 | #' vary with model class, so be sure to read the `residuals.my_class` 4 | #' documentation. 5 | #' @md 6 | -------------------------------------------------------------------------------- /man-roxygen/param_unused_dots.R: -------------------------------------------------------------------------------- 1 | #' @param ... Additional arguments. Not used. Needed to match generic 2 | #' signature only. **Cautionary note:** Misspelled arguments will be 3 | #' absorbed in `...`, where they will be ignored. If the misspelled 4 | #' argument has a default value, the default value will be used. 5 | #' For example, if you pass `conf.lvel = 0.9`, all computation will 6 | #' proceed using `conf.level = 0.95`. Two exceptions here are: 7 | #' 8 | #' * `tidy()` methods will warn when supplied an `exponentiate` argument if 9 | #' it will be ignored. 10 | #' * `augment()` methods will warn when supplied a `newdata` argument if it 11 | #' will be ignored. 12 | #' 13 | #' @md 14 | -------------------------------------------------------------------------------- /man-roxygen/return_augment_columns.R: -------------------------------------------------------------------------------- 1 | #' @return A [tibble::tibble()] containing the data passed to `augment`, 2 | #' and **additional** columns: 3 | #' 4 | #' \item{.fitted}{The predicted response for that observation.} 5 | #' \item{.resid}{The residual for a particular point. Present only when 6 | #' data has been passed to `augment` via the `data` argument.} 7 | #' 8 | #' @md 9 | -------------------------------------------------------------------------------- /man-roxygen/return_finish_glance.R: -------------------------------------------------------------------------------- 1 | #' @return A one-row [tibble::tibble] with columns: 2 | #' 3 | #' \item{logLik}{Log-likelihood of the model.} 4 | #' \item{AIC}{Akaike's Information Criterion for the model.} 5 | #' \item{BIC}{Bayesian Information Criterion for the model.} 6 | #' \item{deviance}{Deviance of the model.} 7 | #' \item{df.residual}{Residual degrees of freedom for the model.} 8 | #' 9 | #' @md 10 | -------------------------------------------------------------------------------- /man-roxygen/return_term_regression.R: -------------------------------------------------------------------------------- 1 | #' @return \item{term}{The name of the regression term.} 2 | -------------------------------------------------------------------------------- /man-roxygen/return_tidy_regression.R: -------------------------------------------------------------------------------- 1 | #' @return A [tibble::tibble()] with one row for each term in the 2 | #' regression. The tibble has columns: 3 | #' 4 | #' \item{term}{The name of the regression term.} 5 | #' \item{estimate}{The estimated value of the regression term.} 6 | #' \item{std.error}{The standard error of the regression term.} 7 | #' \item{statistic}{The value of a statistic, almost always a T-statistic, 8 | #' to use in a hypothesis that the regression term is non-zero.} 9 | #' \item{p.value}{The two-sided p-value associated with the observed 10 | #' statistic.} 11 | #' \item{conf.low}{The low end of a confidence interval for the regression 12 | #' term. Included only if `conf.int = TRUE`.} 13 | #' \item{conf.high}{The high end of a confidence interval for the regression 14 | #' term. Included only if `conf.int = TRUE`.} 15 | #' 16 | #' @md 17 | -------------------------------------------------------------------------------- /man-roxygen/title_desc_glance.R: -------------------------------------------------------------------------------- 1 | #' @title Glance at a(n) <%= class %> object 2 | #' 3 | #' @description Glance accepts a model object and returns a [tibble::tibble()] 4 | #' with exactly one row of model summaries. The summaries are typically 5 | #' goodness of fit measures, p-values for hypothesis tests on residuals, 6 | #' or model convergence information. 7 | #' 8 | #' Glance never returns information from the original call to the modeling 9 | #' function. This includes the name of the modeling function or any 10 | #' arguments passed to the modeling function. 11 | #' 12 | #' Glance does not calculate summary measures. Rather, it farms out these 13 | #' computations to appropriate methods and gathers the results together. 14 | #' Sometimes a goodness of fit measure will be undefined. In these cases 15 | #' the measure will be reported as `NA`. 16 | #' 17 | #' Glance returns the same number of columns regardless of whether the 18 | #' model matrix is rank-deficient or not. If so, entries in columns 19 | #' that no longer have a well-defined value are filled in with an `NA` 20 | #' of the appropriate type. 21 | #' 22 | #' @md 23 | -------------------------------------------------------------------------------- /man-roxygen/title_desc_tidy.R: -------------------------------------------------------------------------------- 1 | #' @title Tidy a(n) <%= class %> object 2 | #' 3 | #' @description Tidy summarizes information about the components of a model. 4 | #' A model component might be a single term in a regression, a single 5 | #' hypothesis, a cluster, or a class. Exactly what tidy considers to be a 6 | #' model component varies across models but is usually self-evident. 7 | #' If a model has several distinct types of components, you will need to 8 | #' specify which components to return. 9 | #' 10 | #' @md 11 | 12 | -------------------------------------------------------------------------------- /man-roxygen/title_desc_tidy_glance.R: -------------------------------------------------------------------------------- 1 | #' @title Tidy/glance a(n) <%= class %> object 2 | #' 3 | #' @description For models that have only a single component, the [tidy()] and 4 | #' [glance()] methods are identical. Please see the documentation for both 5 | #' of those methods. 6 | #' 7 | #' @md 8 | -------------------------------------------------------------------------------- /man-roxygen/title_desc_tidy_list.R: -------------------------------------------------------------------------------- 1 | #' @title Tidy a(n) <%= class %> object masquerading as list 2 | #' 3 | #' @description Broom tidies a number of lists that are effectively S3 4 | #' objects without a class attribute. For example, [stats::optim()], 5 | #' [svd()][base::svd()] and [interp::interp()] produce consistent output, but 6 | #' because they do not have a class attribute, they cannot be handled by S3 7 | #' dispatch. 8 | #' 9 | #' These functions look at the elements of a list and determine if there is 10 | #' an appropriate tidying method to apply to the list. Those tidiers are 11 | #' implemented as functions of the form `tidy_` or 12 | #' `glance_` and are not exported (but they are documented!). 13 | #' 14 | #' If no appropriate tidying method is found, they throw an error. 15 | #' 16 | #' @md 17 | -------------------------------------------------------------------------------- /man/augment_columns.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/utilities.R 3 | \name{augment_columns} 4 | \alias{augment_columns} 5 | \title{Add fitted values, residuals, and other common outputs to 6 | an augment call} 7 | \usage{ 8 | augment_columns( 9 | x, 10 | data, 11 | newdata = NULL, 12 | type, 13 | type.predict = type, 14 | type.residuals = type, 15 | se.fit = TRUE, 16 | ... 17 | ) 18 | } 19 | \arguments{ 20 | \item{x}{a model} 21 | 22 | \item{data}{original data onto which columns should be added} 23 | 24 | \item{newdata}{new data to predict on, optional} 25 | 26 | \item{type}{Type of prediction and residuals to compute} 27 | 28 | \item{type.predict}{Type of prediction to compute; by default 29 | same as \code{type}} 30 | 31 | \item{type.residuals}{Type of residuals to compute; by default 32 | same as \code{type}} 33 | 34 | \item{se.fit}{Value to pass to predict's \code{se.fit}, or NULL for 35 | no value. Ignored for model types that do not accept an \code{se.fit} 36 | argument} 37 | 38 | \item{...}{extra arguments (not used)} 39 | } 40 | \description{ 41 | \code{augment_columns} is intended for use in the internals of \code{augment} methods 42 | only and is exported for developers extending the broom package. Please 43 | instead use \code{\link[=augment]{augment()}} to appropriately make use of the functionality 44 | in \code{augment_columns()}. 45 | } 46 | \details{ 47 | Note that, in the case that a \code{residuals()} or \code{influence()} generic is 48 | not implemented for the supplied model \code{x}, the function will fail quietly. 49 | } 50 | -------------------------------------------------------------------------------- /man/bootstrap.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated-0-7-0.R 3 | \name{bootstrap} 4 | \alias{bootstrap} 5 | \title{Set up bootstrap replicates of a dplyr operation} 6 | \usage{ 7 | bootstrap(df, m, by_group = FALSE) 8 | } 9 | \arguments{ 10 | \item{df}{a data frame} 11 | 12 | \item{m}{number of bootstrap replicates to perform} 13 | 14 | \item{by_group}{If \code{TRUE}, then bootstrap within each group if \code{df} is 15 | a grouped tibble.} 16 | } 17 | \description{ 18 | The \code{bootstrap()} function is deprecated and will be removed from 19 | an upcoming release of broom. For tidy resampling, please use the rsample 20 | package instead. Functionality is no longer supported for this method. 21 | } 22 | \details{ 23 | This code originates from Hadley Wickham (with a few small 24 | corrections) here: 25 | \url{https://github.com/tidyverse/dplyr/issues/269} 26 | } 27 | \seealso{ 28 | Other deprecated: 29 | \code{\link{confint_tidy}()}, 30 | \code{\link{data.frame_tidiers}}, 31 | \code{\link{finish_glance}()}, 32 | \code{\link{fix_data_frame}()}, 33 | \code{\link{summary_tidiers}}, 34 | \code{\link{tidy.density}()}, 35 | \code{\link{tidy.dist}()}, 36 | \code{\link{tidy.ftable}()}, 37 | \code{\link{tidy.numeric}()} 38 | } 39 | \concept{deprecated} 40 | -------------------------------------------------------------------------------- /man/confint_tidy.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated-0-7-0.R 3 | \name{confint_tidy} 4 | \alias{confint_tidy} 5 | \title{(Deprecated) Calculate confidence interval as a tidy data frame} 6 | \usage{ 7 | confint_tidy(x, conf.level = 0.95, func = stats::confint, ...) 8 | } 9 | \arguments{ 10 | \item{x}{a model object for which \code{\link[=confint]{confint()}} can be calculated} 11 | 12 | \item{conf.level}{confidence level} 13 | 14 | \item{func}{A function to compute a confidence interval for \code{x}. Calling 15 | \code{func(x, level = conf.level, ...)} must return an object coercible to a 16 | tibble. This dataframe like object should have to columns corresponding 17 | the lower and upper bounds on the confidence interval.} 18 | 19 | \item{...}{extra arguments passed on to \code{confint}} 20 | } 21 | \value{ 22 | A tibble with two columns: \code{conf.low} and \code{conf.high}. 23 | } 24 | \description{ 25 | This function is now deprecated and will be removed from a future 26 | release of broom. 27 | } 28 | \details{ 29 | Return a confidence interval as a tidy data frame. This directly wraps the 30 | \code{\link[=confint]{confint()}} function, but ensures it follows broom conventions: 31 | column names of \code{conf.low} and \code{conf.high}, and no row names. 32 | 33 | \code{confint_tidy} 34 | } 35 | \seealso{ 36 | Other deprecated: 37 | \code{\link{bootstrap}()}, 38 | \code{\link{data.frame_tidiers}}, 39 | \code{\link{finish_glance}()}, 40 | \code{\link{fix_data_frame}()}, 41 | \code{\link{summary_tidiers}}, 42 | \code{\link{tidy.density}()}, 43 | \code{\link{tidy.dist}()}, 44 | \code{\link{tidy.ftable}()}, 45 | \code{\link{tidy.numeric}()} 46 | } 47 | \concept{deprecated} 48 | -------------------------------------------------------------------------------- /man/figures/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/man/figures/logo.png -------------------------------------------------------------------------------- /man/finish_glance.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated-0-7-0.R 3 | \name{finish_glance} 4 | \alias{finish_glance} 5 | \title{(Deprecated) Add logLik, AIC, BIC, and other common measurements to a 6 | glance of a prediction} 7 | \usage{ 8 | finish_glance(ret, x) 9 | } 10 | \arguments{ 11 | \item{ret}{a one-row data frame (a partially complete glance)} 12 | 13 | \item{x}{the prediction model} 14 | } 15 | \value{ 16 | a one-row data frame with additional columns added, such as 17 | \item{logLik}{log likelihoods} 18 | \item{AIC}{Akaike Information Criterion} 19 | \item{BIC}{Bayesian Information Criterion} 20 | \item{deviance}{deviance} 21 | \item{df.residual}{residual degrees of freedom} 22 | } 23 | \description{ 24 | This function is now deprecated in favor of using custom logic and 25 | the appropriate \code{nobs()} method. 26 | } 27 | \seealso{ 28 | Other deprecated: 29 | \code{\link{bootstrap}()}, 30 | \code{\link{confint_tidy}()}, 31 | \code{\link{data.frame_tidiers}}, 32 | \code{\link{fix_data_frame}()}, 33 | \code{\link{summary_tidiers}}, 34 | \code{\link{tidy.density}()}, 35 | \code{\link{tidy.dist}()}, 36 | \code{\link{tidy.ftable}()}, 37 | \code{\link{tidy.numeric}()} 38 | } 39 | \concept{deprecated} 40 | -------------------------------------------------------------------------------- /man/fix_data_frame.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated-0-7-0.R 3 | \name{fix_data_frame} 4 | \alias{fix_data_frame} 5 | \title{Ensure an object is a data frame, with rownames moved into a column} 6 | \usage{ 7 | fix_data_frame(x, newnames = NULL, newcol = "term") 8 | } 9 | \arguments{ 10 | \item{x}{a data.frame or matrix} 11 | 12 | \item{newnames}{new column names, not including the rownames} 13 | 14 | \item{newcol}{the name of the new rownames column} 15 | } 16 | \value{ 17 | a data.frame, with rownames moved into a column and new column 18 | names assigned 19 | } 20 | \description{ 21 | This function is deprecated as of broom 0.7.0 and will be removed from 22 | a future release. Please see \code{tibble::as_tibble}. 23 | } 24 | \seealso{ 25 | Other deprecated: 26 | \code{\link{bootstrap}()}, 27 | \code{\link{confint_tidy}()}, 28 | \code{\link{data.frame_tidiers}}, 29 | \code{\link{finish_glance}()}, 30 | \code{\link{summary_tidiers}}, 31 | \code{\link{tidy.density}()}, 32 | \code{\link{tidy.dist}()}, 33 | \code{\link{tidy.ftable}()}, 34 | \code{\link{tidy.numeric}()} 35 | } 36 | \concept{deprecated} 37 | -------------------------------------------------------------------------------- /man/list_tidiers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/list.R 3 | \name{list_tidiers} 4 | \alias{list_tidiers} 5 | \alias{tidy.list} 6 | \alias{glance.list} 7 | \title{Tidying methods for lists / returned values that are not S3 objects} 8 | \usage{ 9 | \method{tidy}{list}(x, ...) 10 | 11 | \method{glance}{list}(x, ...) 12 | } 13 | \arguments{ 14 | \item{x}{A list, potentially representing an object that can be tidied.} 15 | 16 | \item{...}{Additionally, arguments passed to the tidying function.} 17 | } 18 | \description{ 19 | Broom tidies a number of lists that are effectively S3 objects without 20 | a class attribute. For example, \code{\link[stats:optim]{stats::optim()}}, \code{\link[base:svd]{base::svd()}} and 21 | \code{\link[interp:interp]{interp::interp()}} produce consistent output, but because they do not 22 | have a class attribute, they cannot be handled by S3 dispatch. 23 | } 24 | \details{ 25 | These functions look at the elements of a list and determine if there is 26 | an appropriate tidying method to apply to the list. Those tidiers are 27 | themselves are implemented as functions of the form \verb{tidy_} 28 | or \verb{glance_} and are not exported (but they are documented!). 29 | 30 | If no appropriate tidying method is found, throws an error. 31 | } 32 | \seealso{ 33 | Other list tidiers: 34 | \code{\link{glance_optim}()}, 35 | \code{\link{tidy_irlba}()}, 36 | \code{\link{tidy_optim}()}, 37 | \code{\link{tidy_svd}()}, 38 | \code{\link{tidy_xyz}()} 39 | } 40 | \concept{list tidiers} 41 | -------------------------------------------------------------------------------- /man/null_tidiers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/null-and-default.R 3 | \name{null_tidiers} 4 | \alias{null_tidiers} 5 | \alias{tidy.NULL} 6 | \alias{glance.NULL} 7 | \alias{augment.NULL} 8 | \title{Tidiers for NULL inputs} 9 | \usage{ 10 | \method{tidy}{`NULL`}(x, ...) 11 | 12 | \method{glance}{`NULL`}(x, ...) 13 | 14 | \method{augment}{`NULL`}(x, ...) 15 | } 16 | \arguments{ 17 | \item{x}{The value \code{NULL}.} 18 | 19 | \item{...}{Additional arguments (not used).} 20 | } 21 | \value{ 22 | An empty \link[tibble:tibble]{tibble::tibble}. 23 | } 24 | \description{ 25 | \code{tidy(NULL)}, \code{glance(NULL)} and \code{augment(NULL)} all return an empty 26 | \link[tibble:tibble]{tibble::tibble}. This empty tibble can be treated a tibble with zero 27 | rows, making it convenient to combine with other tibbles using 28 | functions like \code{\link[purrr:map_dfr]{purrr::map_df()}} on lists of potentially \code{NULL} objects. 29 | } 30 | \seealso{ 31 | \link[tibble:tibble]{tibble::tibble} 32 | } 33 | -------------------------------------------------------------------------------- /man/reexports.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/broom.R 3 | \docType{import} 4 | \name{reexports} 5 | \alias{reexports} 6 | \alias{augment} 7 | \alias{tidy} 8 | \alias{glance} 9 | \title{Objects exported from other packages} 10 | \seealso{ 11 | \code{\link[=augment.lm]{augment.lm()}} 12 | 13 | \code{\link[=tidy.lm]{tidy.lm()}} 14 | 15 | \code{\link[=glance.lm]{glance.lm()}} 16 | } 17 | \keyword{internal} 18 | \description{ 19 | These objects are imported from other packages. Follow the links 20 | below to see their documentation. 21 | 22 | \describe{ 23 | \item{generics}{\code{\link[generics]{augment}}, \code{\link[generics]{glance}}, \code{\link[generics]{tidy}}} 24 | }} 25 | 26 | -------------------------------------------------------------------------------- /man/sp_tidiers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/sp.R 3 | \name{sp_tidiers} 4 | \alias{sp_tidiers} 5 | \alias{tidy.SpatialPolygonsDataFrame} 6 | \alias{tidy.SpatialPolygons} 7 | \alias{tidy.Polygons} 8 | \alias{tidy.Polygon} 9 | \alias{tidy.SpatialLinesDataFrame} 10 | \alias{tidy.Lines} 11 | \alias{tidy.Line} 12 | \title{Tidy a(n) SpatialPolygonsDataFrame object} 13 | \usage{ 14 | \method{tidy}{SpatialPolygonsDataFrame}(x, region = NULL, ...) 15 | 16 | \method{tidy}{SpatialPolygons}(x, ...) 17 | 18 | \method{tidy}{Polygons}(x, ...) 19 | 20 | \method{tidy}{Polygon}(x, ...) 21 | 22 | \method{tidy}{SpatialLinesDataFrame}(x, ...) 23 | 24 | \method{tidy}{Lines}(x, ...) 25 | 26 | \method{tidy}{Line}(x, ...) 27 | } 28 | \arguments{ 29 | \item{x}{A \code{SpatialPolygonsDataFrame}, \code{SpatialPolygons}, \code{Polygons}, 30 | \code{Polygon}, \code{SpatialLinesDataFrame}, \code{Lines} or \code{Line} object.} 31 | 32 | \item{region}{name of variable used to split up regions} 33 | 34 | \item{...}{not used by this method} 35 | } 36 | \description{ 37 | Tidy summarizes information about the components of a model. 38 | A model component might be a single term in a regression, a single 39 | hypothesis, a cluster, or a class. Exactly what tidy considers to be a 40 | model component varies across models but is usually self-evident. 41 | If a model has several distinct types of components, you will need to 42 | specify which components to return. 43 | 44 | Note that the \code{sf} package now defines tidy spatial objects 45 | and is the recommended approach to spatial data. \code{sp} tidiers are now 46 | deprecated in favor of \code{sf::st_as_sf()} and coercion methods found in 47 | other packages. See 48 | \url{https://r-spatial.org/r/2023/05/15/evolution4.html} for more on 49 | migration from retiring spatial packages. 50 | } 51 | -------------------------------------------------------------------------------- /man/tidy.acf.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/stats-time-series.R 3 | \name{tidy.acf} 4 | \alias{tidy.acf} 5 | \title{Tidy a(n) acf object} 6 | \usage{ 7 | \method{tidy}{acf}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An \code{acf} object created by \code{\link[stats:acf]{stats::acf()}}, \code{\link[stats:acf]{stats::pacf()}} or 11 | \code{\link[stats:acf]{stats::ccf()}}.} 12 | 13 | \item{...}{Additional arguments. Not used. Needed to match generic 14 | signature only. \strong{Cautionary note:} Misspelled arguments will be 15 | absorbed in \code{...}, where they will be ignored. If the misspelled 16 | argument has a default value, the default value will be used. 17 | For example, if you pass \code{conf.lvel = 0.9}, all computation will 18 | proceed using \code{conf.level = 0.95}. Two exceptions here are: 19 | \itemize{ 20 | \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if 21 | it will be ignored. 22 | \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it 23 | will be ignored. 24 | }} 25 | } 26 | \description{ 27 | Tidy summarizes information about the components of a model. 28 | A model component might be a single term in a regression, a single 29 | hypothesis, a cluster, or a class. Exactly what tidy considers to be a 30 | model component varies across models but is usually self-evident. 31 | If a model has several distinct types of components, you will need to 32 | specify which components to return. 33 | } 34 | \examples{ 35 | 36 | tidy(acf(lh, plot = FALSE)) 37 | tidy(ccf(mdeaths, fdeaths, plot = FALSE)) 38 | tidy(pacf(lh, plot = FALSE)) 39 | } 40 | \seealso{ 41 | \code{\link[=tidy]{tidy()}}, \code{\link[stats:acf]{stats::acf()}}, \code{\link[stats:acf]{stats::pacf()}}, \code{\link[stats:acf]{stats::ccf()}} 42 | 43 | Other time series tidiers: 44 | \code{\link{tidy.spec}()}, 45 | \code{\link{tidy.ts}()}, 46 | \code{\link{tidy.zoo}()} 47 | } 48 | \concept{time series tidiers} 49 | \value{ 50 | A \code{\link[tibble:tibble]{tibble::tibble()}} with columns: 51 | \item{acf}{Autocorrelation.} 52 | \item{lag}{Lag values.} 53 | 54 | } 55 | -------------------------------------------------------------------------------- /man/tidy.density.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated-0-7-0.R 3 | \name{tidy.density} 4 | \alias{tidy.density} 5 | \title{(Deprecated) Tidy density objects} 6 | \usage{ 7 | \method{tidy}{density}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \code{density} object returned from \code{\link[stats:density]{stats::density()}}.} 11 | 12 | \item{...}{Additional arguments. Not used. Needed to match generic 13 | signature only. \strong{Cautionary note:} Misspelled arguments will be 14 | absorbed in \code{...}, where they will be ignored. If the misspelled 15 | argument has a default value, the default value will be used. 16 | For example, if you pass \code{conf.lvel = 0.9}, all computation will 17 | proceed using \code{conf.level = 0.95}. Two exceptions here are: 18 | \itemize{ 19 | \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if 20 | it will be ignored. 21 | \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it 22 | will be ignored. 23 | }} 24 | } 25 | \value{ 26 | A \link[tibble:tibble]{tibble::tibble} with two columns: points \code{x} where the density 27 | is estimated, and estimated density \code{y}. 28 | } 29 | \description{ 30 | (Deprecated) Tidy density objects 31 | } 32 | \seealso{ 33 | Other deprecated: 34 | \code{\link{bootstrap}()}, 35 | \code{\link{confint_tidy}()}, 36 | \code{\link{data.frame_tidiers}}, 37 | \code{\link{finish_glance}()}, 38 | \code{\link{fix_data_frame}()}, 39 | \code{\link{summary_tidiers}}, 40 | \code{\link{tidy.dist}()}, 41 | \code{\link{tidy.ftable}()}, 42 | \code{\link{tidy.numeric}()} 43 | } 44 | \concept{deprecated} 45 | -------------------------------------------------------------------------------- /man/tidy.ftable.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated-0-7-0.R 3 | \name{tidy.ftable} 4 | \alias{tidy.ftable} 5 | \title{(Deprecated) Tidy ftable objects} 6 | \usage{ 7 | \method{tidy}{ftable}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An \code{ftable} object returned from \code{\link[stats:ftable]{stats::ftable()}}.} 11 | 12 | \item{...}{Additional arguments. Not used. Needed to match generic 13 | signature only. \strong{Cautionary note:} Misspelled arguments will be 14 | absorbed in \code{...}, where they will be ignored. If the misspelled 15 | argument has a default value, the default value will be used. 16 | For example, if you pass \code{conf.lvel = 0.9}, all computation will 17 | proceed using \code{conf.level = 0.95}. Two exceptions here are: 18 | \itemize{ 19 | \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if 20 | it will be ignored. 21 | \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it 22 | will be ignored. 23 | }} 24 | } 25 | \value{ 26 | An ftable contains a "flat" contingency table. This melts it into a 27 | \link[tibble:tibble]{tibble::tibble} with one column for each variable, then a \code{Freq} 28 | column. 29 | } 30 | \description{ 31 | This function is deprecated. Please use \code{\link[tibble:as_tibble]{tibble::as_tibble()}} instead. 32 | } 33 | \seealso{ 34 | Other deprecated: 35 | \code{\link{bootstrap}()}, 36 | \code{\link{confint_tidy}()}, 37 | \code{\link{data.frame_tidiers}}, 38 | \code{\link{finish_glance}()}, 39 | \code{\link{fix_data_frame}()}, 40 | \code{\link{summary_tidiers}}, 41 | \code{\link{tidy.density}()}, 42 | \code{\link{tidy.dist}()}, 43 | \code{\link{tidy.numeric}()} 44 | } 45 | \concept{deprecated} 46 | -------------------------------------------------------------------------------- /man/tidy.muhaz.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/muhaz.R 3 | \name{tidy.muhaz} 4 | \alias{tidy.muhaz} 5 | \alias{muhaz_tidiers} 6 | \title{Tidy a(n) muhaz object} 7 | \usage{ 8 | \method{tidy}{muhaz}(x, ...) 9 | } 10 | \arguments{ 11 | \item{x}{A \code{muhaz} object returned by \code{\link[muhaz:muhaz]{muhaz::muhaz()}}.} 12 | 13 | \item{...}{Additional arguments. Not used. Needed to match generic 14 | signature only. \strong{Cautionary note:} Misspelled arguments will be 15 | absorbed in \code{...}, where they will be ignored. If the misspelled 16 | argument has a default value, the default value will be used. 17 | For example, if you pass \code{conf.lvel = 0.9}, all computation will 18 | proceed using \code{conf.level = 0.95}. Two exceptions here are: 19 | \itemize{ 20 | \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if 21 | it will be ignored. 22 | \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it 23 | will be ignored. 24 | }} 25 | } 26 | \description{ 27 | Tidy summarizes information about the components of a model. 28 | A model component might be a single term in a regression, a single 29 | hypothesis, a cluster, or a class. Exactly what tidy considers to be a 30 | model component varies across models but is usually self-evident. 31 | If a model has several distinct types of components, you will need to 32 | specify which components to return. 33 | } 34 | \examples{ 35 | \dontshow{if (rlang::is_installed(c("muhaz", "survival"))) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 36 | 37 | # load libraries for models and data 38 | library(muhaz) 39 | library(survival) 40 | 41 | # fit model 42 | x <- muhaz(ovarian$futime, ovarian$fustat) 43 | 44 | # summarize model fit with tidiers 45 | tidy(x) 46 | glance(x) 47 | \dontshow{\}) # examplesIf} 48 | } 49 | \seealso{ 50 | \code{\link[=tidy]{tidy()}}, \code{\link[muhaz:muhaz]{muhaz::muhaz()}} 51 | 52 | Other muhaz tidiers: 53 | \code{\link{glance.muhaz}()} 54 | } 55 | \concept{muhaz tidiers} 56 | \value{ 57 | A \code{\link[tibble:tibble]{tibble::tibble()}} with columns: 58 | \item{time}{Point in time.} 59 | \item{estimate}{Estimated hazard rate.} 60 | 61 | } 62 | -------------------------------------------------------------------------------- /man/tidy.negbin.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mass-negbin.R 3 | \name{tidy.negbin} 4 | \alias{tidy.negbin} 5 | \title{Tidy a(n) negbin object} 6 | \usage{ 7 | \method{tidy}{negbin}(x, conf.int = FALSE, conf.level = 0.95, exponentiate = FALSE, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \code{glm.nb} object returned by \code{\link[MASS:glm.nb]{MASS::glm.nb()}}.} 11 | 12 | \item{conf.int}{Logical indicating whether or not to include a confidence 13 | interval in the tidied output. Defaults to \code{FALSE}.} 14 | 15 | \item{conf.level}{The confidence level to use for the confidence interval 16 | if \code{conf.int = TRUE}. Must be strictly greater than 0 and less than 1. 17 | Defaults to 0.95, which corresponds to a 95 percent confidence interval.} 18 | 19 | \item{exponentiate}{Logical indicating whether or not to exponentiate the 20 | the coefficient estimates. This is typical for logistic and multinomial 21 | regressions, but a bad idea if there is no log or logit link. Defaults 22 | to \code{FALSE}.} 23 | 24 | \item{...}{For \code{tidy()}, additional arguments passed to \code{\link[=summary]{summary()}}. 25 | Otherwise ignored.} 26 | } 27 | \description{ 28 | Tidy summarizes information about the components of a model. 29 | A model component might be a single term in a regression, a single 30 | hypothesis, a cluster, or a class. Exactly what tidy considers to be a 31 | model component varies across models but is usually self-evident. 32 | If a model has several distinct types of components, you will need to 33 | specify which components to return. 34 | } 35 | \examples{ 36 | \dontshow{if (rlang::is_installed("MASS")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} 37 | 38 | # load libraries for models and data 39 | library(MASS) 40 | 41 | # fit model 42 | r <- glm.nb(Days ~ Sex / (Age + Eth * Lrn), data = quine) 43 | 44 | # summarize model fit with tidiers 45 | tidy(r) 46 | glance(r) 47 | \dontshow{\}) # examplesIf} 48 | } 49 | \seealso{ 50 | \code{\link[MASS:glm.nb]{MASS::glm.nb()}} 51 | 52 | Other glm.nb tidiers: 53 | \code{\link{glance.negbin}()} 54 | } 55 | \concept{glm.nb tidiers} 56 | -------------------------------------------------------------------------------- /man/tidy.rlm.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/mass-rlm.R 3 | \name{tidy.rlm} 4 | \alias{tidy.rlm} 5 | \title{Tidy a(n) rlm object} 6 | \usage{ 7 | \method{tidy}{rlm}(x, conf.int = FALSE, conf.level = 0.95, ...) 8 | } 9 | \arguments{ 10 | \item{x}{An \code{rlm} object returned by \code{\link[MASS:rlm]{MASS::rlm()}}.} 11 | 12 | \item{conf.int}{Logical indicating whether or not to include a confidence 13 | interval in the tidied output. Defaults to \code{FALSE}.} 14 | 15 | \item{conf.level}{The confidence level to use for the confidence interval 16 | if \code{conf.int = TRUE}. Must be strictly greater than 0 and less than 1. 17 | Defaults to 0.95, which corresponds to a 95 percent confidence interval.} 18 | 19 | \item{...}{Additional arguments. Not used. Needed to match generic 20 | signature only. \strong{Cautionary note:} Misspelled arguments will be 21 | absorbed in \code{...}, where they will be ignored. If the misspelled 22 | argument has a default value, the default value will be used. 23 | For example, if you pass \code{conf.lvel = 0.9}, all computation will 24 | proceed using \code{conf.level = 0.95}. Two exceptions here are: 25 | \itemize{ 26 | \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if 27 | it will be ignored. 28 | \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it 29 | will be ignored. 30 | }} 31 | } 32 | \description{ 33 | Tidy summarizes information about the components of a model. 34 | A model component might be a single term in a regression, a single 35 | hypothesis, a cluster, or a class. Exactly what tidy considers to be a 36 | model component varies across models but is usually self-evident. 37 | If a model has several distinct types of components, you will need to 38 | specify which components to return. 39 | } 40 | \seealso{ 41 | \code{\link[MASS:rlm]{MASS::rlm()}} 42 | 43 | Other rlm tidiers: 44 | \code{\link{augment.rlm}()}, 45 | \code{\link{glance.rlm}()} 46 | } 47 | \concept{rlm tidiers} 48 | -------------------------------------------------------------------------------- /man/tidy.table.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/base.R 3 | \name{tidy.table} 4 | \alias{tidy.table} 5 | \title{Tidy a(n) table object} 6 | \usage{ 7 | \method{tidy}{table}(x, ...) 8 | } 9 | \arguments{ 10 | \item{x}{A \link[base:table]{base::table} object.} 11 | 12 | \item{...}{Additional arguments. Not used. Needed to match generic 13 | signature only. \strong{Cautionary note:} Misspelled arguments will be 14 | absorbed in \code{...}, where they will be ignored. If the misspelled 15 | argument has a default value, the default value will be used. 16 | For example, if you pass \code{conf.lvel = 0.9}, all computation will 17 | proceed using \code{conf.level = 0.95}. Two exceptions here are: 18 | \itemize{ 19 | \item \code{tidy()} methods will warn when supplied an \code{exponentiate} argument if 20 | it will be ignored. 21 | \item \code{augment()} methods will warn when supplied a \code{newdata} argument if it 22 | will be ignored. 23 | }} 24 | } 25 | \value{ 26 | A \link[tibble:tibble]{tibble::tibble} in long-form containing frequency information 27 | for the table in a \code{Freq} column. The result is much like what you get 28 | from \code{\link[tidyr:pivot_longer]{tidyr::pivot_longer()}}. 29 | } 30 | \description{ 31 | Tidy summarizes information about the components of a model. 32 | A model component might be a single term in a regression, a single 33 | hypothesis, a cluster, or a class. Exactly what tidy considers to be a 34 | model component varies across models but is usually self-evident. 35 | If a model has several distinct types of components, you will need to 36 | specify which components to return. 37 | 38 | Deprecated. Please use \code{\link[tibble:as_tibble]{tibble::as_tibble()}} instead. 39 | } 40 | \details{ 41 | Directly calls \code{\link[tibble:as_tibble]{tibble::as_tibble()}} on a \link[base:table]{base::table} object. 42 | } 43 | \seealso{ 44 | \code{\link[tibble:as_tibble]{tibble::as_tibble.table()}} 45 | } 46 | -------------------------------------------------------------------------------- /man/vector_tidiers.Rd: -------------------------------------------------------------------------------- 1 | % Generated by roxygen2: do not edit by hand 2 | % Please edit documentation in R/deprecated-0-7-0.R 3 | \name{tidy.numeric} 4 | \alias{tidy.numeric} 5 | \alias{tidy.character} 6 | \alias{tidy.logical} 7 | \title{Tidy atomic vectors} 8 | \usage{ 9 | \method{tidy}{numeric}(x, ...) 10 | 11 | \method{tidy}{character}(x, ...) 12 | 13 | \method{tidy}{logical}(x, ...) 14 | } 15 | \arguments{ 16 | \item{x}{An object of class "numeric", "integer", "character", or "logical". 17 | Most likely a named vector} 18 | 19 | \item{...}{Extra arguments (not used)} 20 | } 21 | \description{ 22 | Vector tidiers are deprecated and will be removed from an upcoming release 23 | of broom. 24 | } 25 | \details{ 26 | Turn atomic vectors into data frames, where the names of the vector (if they 27 | exist) are a column and the values of the vector are a column. 28 | } 29 | \examples{ 30 | 31 | \dontrun{ 32 | x <- 1:5 33 | names(x) <- letters[1:5] 34 | tidy(x) 35 | } 36 | 37 | } 38 | \seealso{ 39 | Other deprecated: 40 | \code{\link{bootstrap}()}, 41 | \code{\link{confint_tidy}()}, 42 | \code{\link{data.frame_tidiers}}, 43 | \code{\link{finish_glance}()}, 44 | \code{\link{fix_data_frame}()}, 45 | \code{\link{summary_tidiers}}, 46 | \code{\link{tidy.density}()}, 47 | \code{\link{tidy.dist}()}, 48 | \code{\link{tidy.ftable}()} 49 | 50 | Other deprecated: 51 | \code{\link{bootstrap}()}, 52 | \code{\link{confint_tidy}()}, 53 | \code{\link{data.frame_tidiers}}, 54 | \code{\link{finish_glance}()}, 55 | \code{\link{fix_data_frame}()}, 56 | \code{\link{summary_tidiers}}, 57 | \code{\link{tidy.density}()}, 58 | \code{\link{tidy.dist}()}, 59 | \code{\link{tidy.ftable}()} 60 | 61 | Other deprecated: 62 | \code{\link{bootstrap}()}, 63 | \code{\link{confint_tidy}()}, 64 | \code{\link{data.frame_tidiers}}, 65 | \code{\link{finish_glance}()}, 66 | \code{\link{fix_data_frame}()}, 67 | \code{\link{summary_tidiers}}, 68 | \code{\link{tidy.density}()}, 69 | \code{\link{tidy.dist}()}, 70 | \code{\link{tidy.ftable}()} 71 | } 72 | \concept{deprecated} 73 | -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-120x120.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/apple-touch-icon-120x120.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-152x152.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/apple-touch-icon-152x152.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-180x180.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/apple-touch-icon-180x180.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-60x60.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/apple-touch-icon-60x60.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon-76x76.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/apple-touch-icon-76x76.png -------------------------------------------------------------------------------- /pkgdown/favicon/apple-touch-icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/apple-touch-icon.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/favicon-16x16.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon-32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/favicon-32x32.png -------------------------------------------------------------------------------- /pkgdown/favicon/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tidymodels/broom/d7ad27062b6c19d3a04f3e02c037182fbf8ccb4a/pkgdown/favicon/favicon.ico -------------------------------------------------------------------------------- /tests/spelling.R: -------------------------------------------------------------------------------- 1 | if (requireNamespace("spelling", quietly = TRUE)) { 2 | spelling::spell_check_test( 3 | vignettes = TRUE, 4 | error = FALSE, 5 | skip_on_cran = TRUE 6 | ) 7 | } 8 | -------------------------------------------------------------------------------- /tests/test-all.R: -------------------------------------------------------------------------------- 1 | library(testthat) 2 | test_check("broom") 3 | -------------------------------------------------------------------------------- /tests/testthat.R: -------------------------------------------------------------------------------- 1 | # This file is part of the standard setup for testthat. 2 | # It is recommended that you do not modify it. 3 | # 4 | # Where should you do additional test configuration? 5 | # Learn more about the roles of various files in: 6 | # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview 7 | # * https://testthat.r-lib.org/articles/special-files.html 8 | 9 | library(testthat) 10 | library(broom) 11 | 12 | test_check("broom") 13 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/data-frame.md: -------------------------------------------------------------------------------- 1 | # glance.tbl_df errors informatively 2 | 3 | Code 4 | glance.tbl_df(tibble::tibble(x = 1)) 5 | Condition 6 | Error in `glance.tbl_df()`: 7 | ! There is no glance method for tibbles. 8 | i Did you mean `tibble::glimpse()`? 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/drc.md: -------------------------------------------------------------------------------- 1 | # augment.drc 2 | 3 | Code 4 | augment(mod) 5 | Condition 6 | Error in `augment()`: 7 | ! Must specify either `data` or `newdata` argument. 8 | 9 | --- 10 | 11 | Code 12 | augment(mod2) 13 | Condition 14 | Error in `augment()`: 15 | ! Must specify either `data` or `newdata` argument. 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/ergm.md: -------------------------------------------------------------------------------- 1 | # tidy.ergm 2 | 3 | Code 4 | tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE) 5 | Condition 6 | Warning: 7 | Coefficients will be exponentiated, but the model didn't use a `log` or `logit` link. 8 | 9 | --- 10 | 11 | Code 12 | td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE) 13 | Condition 14 | Warning: 15 | Coefficients will be exponentiated, but the model didn't use a `log` or `logit` link. 16 | 17 | # glance.ergm 18 | 19 | Code 20 | gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE) 21 | Message 22 | Though `glance()` was supplied `mcmc = TRUE`, the model was not fitted using MCMC, 23 | i The corresponding columns will be omitted. 24 | 25 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/fixest.md: -------------------------------------------------------------------------------- 1 | # all other fixest estimators run 2 | 3 | Code 4 | augment(res_fenegbin) 5 | Condition 6 | Error in `augment()`: 7 | ! augment is only supported for fixest models estimated with `feols()`, `feglm()`, or `femlm()`. 8 | i Supplied model used `fenegbin()`. 9 | 10 | --- 11 | 12 | Code 13 | augment(res_fenegbin, df) 14 | Condition 15 | Error in `augment()`: 16 | ! augment is only supported for fixest models estimated with `feols()`, `feglm()`, or `femlm()`. 17 | i Supplied model used `fenegbin()`. 18 | 19 | --- 20 | 21 | Code 22 | augment(res_feNmlm, df) 23 | Condition 24 | Error in `augment()`: 25 | ! augment is only supported for fixest models estimated with `feols()`, `feglm()`, or `femlm()`. 26 | i Supplied model used `feNmlm()`. 27 | 28 | --- 29 | 30 | Code 31 | augment(res_fepois, df) 32 | Condition 33 | Error in `augment()`: 34 | ! augment is only supported for fixest models estimated with `feols()`, `feglm()`, or `femlm()`. 35 | i Supplied model used `fepois()`. 36 | 37 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/geepack.md: -------------------------------------------------------------------------------- 1 | # tidy.geeglm 2 | 3 | Code 4 | td2 <- tidy(fit, conf.int = FALSE, exponentiate = TRUE) 5 | Condition 6 | Warning: 7 | Coefficients will be exponentiated, but the model didn't use a `log` or `logit` link. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/joineRML.md: -------------------------------------------------------------------------------- 1 | # tidy.mjoint 2 | 3 | Code 4 | tidy(mjoint_fit, boot_se = "cat") 5 | Condition 6 | Error in `tidy()`: 7 | ! `boot_se` must be a object. 8 | 9 | # augment.mjoint 10 | 11 | Code 12 | augment(mjoint_fit, data = NULL) 13 | Condition 14 | Error in `augment()`: 15 | ! `data` argument is `NULL`. 16 | i Try specifying `data` manually. 17 | 18 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/lfe.md: -------------------------------------------------------------------------------- 1 | # tidy.felm 2 | 3 | Code 4 | .res <- tidy(fit, robust = TRUE) 5 | Condition 6 | Warning: 7 | The `robust` argument has been deprecated in `tidy.felm()` and will be ignored. 8 | i Please use the `se.type` argument instead. 9 | 10 | # glance.felm 11 | 12 | Code 13 | glance(fit_multi) 14 | Condition 15 | Error in `glance()`: 16 | ! `felm()` models with multiple responses are not supported. 17 | 18 | # augment.felm 19 | 20 | Code 21 | augment(fit_multi) 22 | Condition 23 | Error in `augment()`: 24 | ! `felm()` models with multiple responses are not supported. 25 | 26 | # tidy.felm errors informatively 27 | 28 | Code 29 | .res <- tidy.felm(fit, se.type = "cluster") 30 | Condition 31 | Warning: 32 | Clustered SEs requested, but weren't calculated in underlying model object. 33 | i Reverting to default SEs. 34 | 35 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/list-svd.md: -------------------------------------------------------------------------------- 1 | # tidy_svd errors informatively 2 | 3 | Code 4 | tidy_svd(matrix = c("u", "v")) 5 | Condition 6 | Error in `tidy_svd()`: 7 | ! Must specify a single matrix to tidy. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/list-xyz.md: -------------------------------------------------------------------------------- 1 | # tidy_xyz 2 | 3 | Code 4 | tidy(b) 5 | Condition 6 | Error in `tidy_xyz()`: 7 | ! To tidy an xyz list, the length of element `x` must equal the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. 8 | 9 | --- 10 | 11 | Code 12 | tidy(c) 13 | Condition 14 | Error in `tidy_xyz()`: 15 | ! To tidy an xyz list, the length of element `x` must equal the number of rows of element `z`, and the length of element `y` must equal the number of columns of element `z`. 16 | 17 | --- 18 | 19 | Code 20 | tidy(d) 21 | Condition 22 | Error in `tidy_xyz()`: 23 | ! `z` must be a matrix. 24 | 25 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/list.md: -------------------------------------------------------------------------------- 1 | # not all lists can be tidied 2 | 3 | Code 4 | tidy(nl) 5 | Condition 6 | Error in `tidy()`: 7 | ! No `tidy()` method recognized for this list. 8 | 9 | --- 10 | 11 | Code 12 | glance(nl) 13 | Condition 14 | Error in `glance()`: 15 | ! No `glance()` method recognized for this list. 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/mass-polr.md: -------------------------------------------------------------------------------- 1 | # tidy.polr messages informatively 2 | 3 | Code 4 | .res <- tidy(fit, p.values = TRUE) 5 | Message 6 | p-values can presently only be returned for models that contain no categorical variables with more than two levels. 7 | 8 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/mclust.md: -------------------------------------------------------------------------------- 1 | # augment.Mclust 2 | 3 | Code 4 | augment(fit, 1:10) 5 | Condition 6 | Error in `augment()`: 7 | ! `data` must be a data frame or matrix. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/mediation.md: -------------------------------------------------------------------------------- 1 | # tidy.mediate errors informatively 2 | 3 | Code 4 | tidy(psych_mediate) 5 | Condition 6 | Error in `tidy()`: 7 | ! No tidy method for objects of class from the psych package. 8 | i The `tidy.mediate()` method is intended for objects from the mediation package. 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/mgcv.md: -------------------------------------------------------------------------------- 1 | # tidy.gam handles messages informatively 2 | 3 | Code 4 | .res <- tidy(x, conf.int = TRUE) 5 | Message 6 | Confidence intervals only available for parametric terms. 7 | 8 | --- 9 | 10 | Code 11 | .res <- tidy(x, exponentiate = TRUE) 12 | Message 13 | Exponentiating coefficients only available for parametric terms. 14 | 15 | --- 16 | 17 | Code 18 | .res <- tidy(x, conf.int = TRUE, exponentiate = TRUE) 19 | Message 20 | Confidence intervals only available for parametric terms. 21 | Exponentiating coefficients only available for parametric terms. 22 | 23 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/quantreg-rqs.md: -------------------------------------------------------------------------------- 1 | # glance.rqs 2 | 3 | Code 4 | glance(fit) 5 | Condition 6 | Error in `glance()`: 7 | ! `glance()` cannot handle objects of class , i.e. models with more than one tau value. 8 | i Please use a purrr `map()`-based workflow with models instead. 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/robust-glmrob.md: -------------------------------------------------------------------------------- 1 | # augment.glmRob errors informatively 2 | 3 | Code 4 | augment(x) 5 | Condition 6 | Error in `augment()`: 7 | ! `augment.glmRob()` has been deprecated as the robust package doesn't provide the functionality necessary to implement an augment method. 8 | i Please see the augment method for objects from robustbase. 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/speedglm-speedglm.md: -------------------------------------------------------------------------------- 1 | # augment.speedglm errors 2 | 3 | Code 4 | augment(fit) 5 | Condition 6 | Error in `augment()`: 7 | ! No `augment()` method for objects of class . 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/speedglm-speedlm.md: -------------------------------------------------------------------------------- 1 | # augment.speedlm 2 | 3 | Code 4 | augment(fit3) 5 | Condition 6 | Error in `augment()`: 7 | ! Must specify `data` argument or refit with `fitted = TRUE`. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/stats-anova.md: -------------------------------------------------------------------------------- 1 | # tidy.anova 2 | 3 | Code 4 | .res <- tidy(loess_anova) 5 | Condition 6 | Warning: 7 | The column name ENP in ANOVA output was not recognized or transformed. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/stats-factanal.md: -------------------------------------------------------------------------------- 1 | # augment.factanal works 2 | 3 | Code 4 | augment(fit_none) 5 | Condition 6 | Error in `augment()`: 7 | ! Cannot augment objects fit with `scores = "none"`. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/stats-glm.md: -------------------------------------------------------------------------------- 1 | # glm tidiers warn informatively with glm.fit2 input 2 | 3 | Code 4 | .res <- tidy(gfit) 5 | Condition 6 | Warning: 7 | `x` seems to be outputted from the glm2 package. 8 | i Tidiers for glm2 output are currently not maintained; please use caution in interpreting broom output. 9 | 10 | # glm tidiers warn informatively with stanreg input 11 | 12 | Code 13 | .res <- tidy(gfit) 14 | Condition 15 | Error in `tidy()`: 16 | ! `x` seems to be outputted from the rstanarm package. 17 | i Tidiers for mixed model output now live in broom.mixed. 18 | 19 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/stats-htest.md: -------------------------------------------------------------------------------- 1 | # tidy.htest/oneway.test 2 | 3 | Code 4 | td <- tidy(ot) 5 | Message 6 | Multiple parameters; naming those columns num.df and den.df. 7 | 8 | --- 9 | 10 | Code 11 | gl <- glance(ot) 12 | Message 13 | Multiple parameters; naming those columns num.df and den.df. 14 | 15 | # augment.htest (chi squared test) 16 | 17 | Code 18 | augment(tt) 19 | Condition 20 | Error in `augment()`: 21 | ! `augment.htest()` is only defined for chi squared hypothesis tests. 22 | 23 | --- 24 | 25 | Code 26 | augment(wt) 27 | Condition 28 | Error in `augment()`: 29 | ! `augment.htest()` is only defined for chi squared hypothesis tests. 30 | 31 | --- 32 | 33 | Code 34 | augment(ct) 35 | Condition 36 | Error in `augment()`: 37 | ! `augment.htest()` is only defined for chi squared hypothesis tests. 38 | 39 | # tidy.htest handles various test types 40 | 41 | Code 42 | .res <- tidy(tt) 43 | Condition 44 | Warning: 45 | Multiple unnamed parameters in hypothesis test; dropping them. 46 | 47 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/stats-lm.md: -------------------------------------------------------------------------------- 1 | # tidy.lm works 2 | 3 | Code 4 | td_rd <- tidy(fit_rd, conf.int = TRUE) 5 | Condition 6 | Warning in `qt()`: 7 | NaNs produced 8 | 9 | # augment.lm 10 | 11 | Code 12 | augment(fit, newdata = mtcars, interval = "confidence", level = 0.95) 13 | Condition 14 | Warning: 15 | The `level` argument is not supported in the `augment()` method for `lm` objects and will be ignored. 16 | Output 17 | # A tibble: 32 x 16 18 | .rownames mpg cyl disp hp drat wt qsec vs am gear carb 19 | 20 | 1 Mazda RX4 21 6 160 110 3.9 2.62 16.5 0 1 4 4 21 | 2 Mazda RX4 ~ 21 6 160 110 3.9 2.88 17.0 0 1 4 4 22 | 3 Datsun 710 22.8 4 108 93 3.85 2.32 18.6 1 1 4 1 23 | 4 Hornet 4 D~ 21.4 6 258 110 3.08 3.22 19.4 1 0 3 1 24 | 5 Hornet Spo~ 18.7 8 360 175 3.15 3.44 17.0 0 0 3 2 25 | 6 Valiant 18.1 6 225 105 2.76 3.46 20.2 1 0 3 1 26 | 7 Duster 360 14.3 8 360 245 3.21 3.57 15.8 0 0 3 4 27 | 8 Merc 240D 24.4 4 147. 62 3.69 3.19 20 1 0 4 2 28 | 9 Merc 230 22.8 4 141. 95 3.92 3.15 22.9 1 0 4 2 29 | 10 Merc 280 19.2 6 168. 123 3.92 3.44 18.3 1 0 4 4 30 | # i 22 more rows 31 | # i 4 more variables: .fitted , .lower , .upper , .resid 32 | 33 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/stats-prcomp.md: -------------------------------------------------------------------------------- 1 | # tidy.prcomp 2 | 3 | Code 4 | tidy(pc, matrix = c("d", "u")) 5 | Condition 6 | Error in `tidy()`: 7 | ! Must select a single matrix to tidy. 8 | 9 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/survival-survfit.md: -------------------------------------------------------------------------------- 1 | # glance.survfit 2 | 3 | Code 4 | glance(sfit) 5 | Condition 6 | Error in `glance()`: 7 | ! Cannot `glance()` a multi-strata object. 8 | 9 | --- 10 | 11 | Code 12 | glance(fit2) 13 | Condition 14 | Error in `glance()`: 15 | ! Cannot `glance()` a multi-state object. 16 | 17 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/utilities.new.md: -------------------------------------------------------------------------------- 1 | # ellipsis checking works 2 | 3 | Code 4 | check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE) 5 | Condition 6 | Warning: 7 | The `exponentiate` argument is not supported in the `tidy()` method for `boop` objects and will be ignored. 8 | 9 | --- 10 | 11 | Code 12 | check_ellipses("exponentiate", "tidy", "boop", exponentiate = TRUE, quick = FALSE) 13 | Condition 14 | Warning: 15 | The `exponentiate` argument is not supported in the `tidy()` method for `boop` objects and will be ignored. 16 | 17 | # ellipsis checking works (whole game, tidy) 18 | 19 | Code 20 | tidy(mod, exponentiate = TRUE) 21 | Condition 22 | Warning: 23 | The `exponentiate` argument is not supported in the `tidy()` method for `nls` objects and will be ignored. 24 | Output 25 | # A tibble: 2 x 5 26 | term estimate std.error statistic p.value 27 | 28 | 1 k 49.7 3.79 13.1 5.96e-14 29 | 2 e 0.746 0.0199 37.5 8.86e-27 30 | 31 | # ellipsis checking works (whole game, augment) 32 | 33 | Code 34 | .res <- augment(mod, data = mtcars, newdata = mtcars) 35 | Condition 36 | Warning: 37 | The `newdata` argument is not supported in the `augment()` method for `kmeans` objects and will be ignored. 38 | 39 | # as_glance_tibble 40 | 41 | Code 42 | as_glance_tibble(x = 1, y = 1, na_types = "rrr") 43 | Condition 44 | Error in `as_glance_tibble()`: 45 | ! The number of columns provided does not match the number of column types provided. 46 | 47 | # appropriate warning on (g)lm-subclassed models 48 | 49 | Code 50 | warn_on_subclass(x, "tidy") 51 | 52 | --- 53 | 54 | Code 55 | warn_on_subclass(x, "tidy") 56 | 57 | # as_augment_tibble errors informatively 58 | 59 | Code 60 | as_augment_tibble(m) 61 | Condition 62 | Error in `as_augment_tibble()`: 63 | ! `m` is an unnamed matrix. 64 | i Please supply a matrix or data frame with column names. 65 | 66 | -------------------------------------------------------------------------------- /tests/testthat/_snaps/vars.md: -------------------------------------------------------------------------------- 1 | # tidy.vars 2 | 3 | Code 4 | .res <- tidy(fit, conf.int = TRUE) 5 | Condition 6 | Warning: 7 | Confidence intervals are not supported for objects. 8 | i The `conf.level` argument will be ignored. 9 | 10 | -------------------------------------------------------------------------------- /tests/testthat/helper.R: -------------------------------------------------------------------------------- 1 | skip_if_not_r_version <- function(min_version) { 2 | if (getRversion() < min_version) { 3 | testthat::skip(paste("R version at least", min_version, "is required.")) 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /tests/testthat/test-aer.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("AER") 7 | suppressPackageStartupMessages(library(AER)) 8 | library(dplyr) 9 | library(modeltests) 10 | 11 | data("CigarettesSW") 12 | df <- CigarettesSW |> 13 | mutate( 14 | rprice = price / cpi, 15 | rincome = income / population / cpi, 16 | tdiff = (taxs - tax) / cpi 17 | ) 18 | 19 | fit <- ivreg( 20 | log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax / cpi), 21 | data = df, 22 | subset = year == "1995" 23 | ) 24 | 25 | ivfit1 <- ivreg(mpg ~ hp | qsec + am, data = mtcars) 26 | ivfit2 <- ivreg(mpg ~ cyl + wt | qsec + am, data = mtcars) 27 | 28 | test_that("ivreg tidier arguments", { 29 | check_arguments(tidy.ivreg) 30 | check_arguments(glance.ivreg) 31 | check_arguments(augment.ivreg, strict = FALSE) 32 | }) 33 | 34 | test_that("tidy.ivreg", { 35 | td <- tidy(fit) 36 | td2 <- tidy(fit, conf.int = TRUE) 37 | 38 | tdiv1 <- tidy(ivfit1, instruments = FALSE) 39 | tdiv1_fstat <- tidy(ivfit1, instruments = TRUE) 40 | tdiv2 <- tidy(ivfit2, instruments = FALSE) 41 | tdiv2_fstat <- tidy(ivfit2, instruments = TRUE) 42 | 43 | check_tidy_output(td) 44 | check_tidy_output(td2) 45 | check_tidy_output(tdiv1) 46 | check_tidy_output(tdiv1_fstat) 47 | check_tidy_output(tdiv2) 48 | check_tidy_output(tdiv2_fstat) 49 | }) 50 | 51 | test_that("glance.ivreg", { 52 | gl <- glance(fit) 53 | gl2 <- glance(fit, diagnostics = TRUE) 54 | 55 | check_glance_outputs(gl) # separately because diagnostics = TRUE adds cols 56 | check_glance_outputs(gl2) 57 | }) 58 | 59 | test_that("augment.ivreg", { 60 | check_augment_function( 61 | aug = augment.ivreg, 62 | model = fit, 63 | data = df, 64 | newdata = df, 65 | strict = FALSE 66 | ) 67 | 68 | au <- augment(fit) 69 | expect_true(all(c(".resid", ".fitted") %in% names(au))) 70 | }) 71 | -------------------------------------------------------------------------------- /tests/testthat/test-aov.R: -------------------------------------------------------------------------------- 1 | library(broom) 2 | 3 | d <- data.frame( 4 | y = c(3, 4, 3.5, 4.1, 6, 7), 5 | group = c("a", "b", "a", "b", "c", "c") 6 | ) 7 | m <- aov(y ~ group, data = d) 8 | 9 | test_that("glance.aov", { 10 | glance_df <- glance(m) 11 | 12 | expect_equal(glance_df$logLik, -1.752246, tolerance = 0.001) 13 | expect_equal(glance_df$AIC, 11.50449, tolerance = 0.001) 14 | expect_equal(glance_df$BIC, 10.67153, tolerance = 0.001) 15 | expect_equal(glance_df$deviance, 0.6300, tolerance = 0.001) 16 | expect_equal(glance_df$nobs, 6L) 17 | }) 18 | -------------------------------------------------------------------------------- /tests/testthat/test-auc.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("AUC") 7 | 8 | test_that("AUC::roc tidier arguments", { 9 | check_arguments(tidy.roc) 10 | }) 11 | 12 | test_that("tidy.roc", { 13 | data(churn, package = "AUC") 14 | r <- AUC::roc(churn$predictions, churn$labels) 15 | 16 | td <- tidy(r) 17 | check_tidy_output(td) 18 | check_dims(td, expected_cols = 3) 19 | }) 20 | -------------------------------------------------------------------------------- /tests/testthat/test-bbmle.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("bbmle") 7 | 8 | test_that("tidy.mle2", { 9 | check_arguments(tidy.mle2) 10 | 11 | df <- tibble( 12 | x = 0:10, 13 | y = c(26, 17, 13, 12, 20, 5, 9, 8, 5, 4, 8) 14 | ) 15 | 16 | fit <- bbmle::mle2( 17 | y ~ dpois(lambda = ymean), 18 | start = list(ymean = 10), 19 | data = df 20 | ) 21 | 22 | td <- tidy(fit, conf.int = TRUE) 23 | 24 | check_tidy_output(td) 25 | check_dims(td, 1, 7) 26 | }) 27 | -------------------------------------------------------------------------------- /tests/testthat/test-betareg.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("betareg") 7 | 8 | suppressPackageStartupMessages(library(betareg)) 9 | data("GasolineYield") 10 | 11 | fit1 <- betareg(yield ~ batch + temp, data = GasolineYield) 12 | fit2 <- betareg(yield ~ batch + temp | temp, data = GasolineYield) 13 | 14 | test_that("betareg tidier arguments", { 15 | check_arguments(tidy.betareg) 16 | check_arguments(glance.betareg) 17 | check_arguments(augment.betareg, strict = FALSE) 18 | }) 19 | 20 | test_that("tidy.betareg", { 21 | td1 <- tidy(fit1, conf.int = TRUE, conf.level = .99) 22 | td2 <- tidy(fit2, conf.int = TRUE) 23 | 24 | check_tidy_output(td1) 25 | check_tidy_output(td2) 26 | 27 | expect_equal( 28 | unname(confint(fit2)), 29 | unname(as.matrix(td2[c("conf.low", "conf.high")])) 30 | ) 31 | 32 | check_dims(td1, 12, 8) 33 | }) 34 | 35 | test_that("glance.betareg", { 36 | gl1 <- glance(fit1) 37 | gl2 <- glance(fit2) 38 | 39 | check_glance_outputs(gl1, gl2) 40 | }) 41 | 42 | test_that("augment.betareg", { 43 | check_augment_function( 44 | augment.betareg, 45 | fit1, 46 | data = GasolineYield, 47 | newdata = GasolineYield 48 | ) 49 | 50 | check_augment_function( 51 | augment.betareg, 52 | fit2, 53 | data = GasolineYield, 54 | newdata = GasolineYield 55 | ) 56 | }) 57 | -------------------------------------------------------------------------------- /tests/testthat/test-biglm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("biglm") 7 | suppressPackageStartupMessages(library(biglm)) 8 | 9 | fit <- biglm(mpg ~ wt + disp, mtcars) 10 | fit2 <- bigglm(am ~ mpg, mtcars, family = binomial()) 11 | 12 | test_that("biglm tidier arguments", { 13 | check_arguments(tidy.biglm) 14 | check_arguments(glance.biglm) 15 | }) 16 | 17 | test_that("tidy.biglm", { 18 | td <- tidy(fit) 19 | td2 <- tidy(fit2, conf.int = TRUE, conf.level = 0.9, exponentiate = TRUE) 20 | 21 | check_tidy_output(td) 22 | check_tidy_output(td2) 23 | 24 | check_dims(td, 3, 4) 25 | }) 26 | 27 | 28 | test_that("glance.betareg", { 29 | gl <- glance(fit) 30 | check_glance_outputs(gl) 31 | 32 | gl2 <- glance(fit2) 33 | check_glance_outputs(gl2) # separate glance checks since different models 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-bingroup.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("binGroup") 7 | suppressPackageStartupMessages(library(binGroup)) 8 | 9 | bw <- binWidth(100, .1) 10 | bd <- binDesign(nmax = 300, delta = 0.06, p.hyp = 0.1, power = .8) 11 | 12 | test_that("binGroup tidier arguments", { 13 | check_arguments(tidy.binWidth) 14 | check_arguments(tidy.binDesign) 15 | check_arguments(glance.binDesign) 16 | }) 17 | 18 | test_that("tidy.binWidth", { 19 | td <- tidy(bw) 20 | check_tidy_output(td) 21 | check_dims(td, 1, 4) 22 | }) 23 | 24 | test_that("tidy.binDesign", { 25 | td <- tidy(bd) 26 | check_tidy_output(td) 27 | check_dims(td, expected_cols = 2) 28 | }) 29 | 30 | test_that("glance.binDesign", { 31 | gl <- glance(bd) 32 | check_glance_outputs(gl) 33 | check_dims(gl, expected_cols = 4) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-btergm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("network") 7 | skip_if_not_installed("btergm") 8 | 9 | test_that("tidy.btergm", { 10 | check_arguments(tidy.btergm, strict = FALSE) 11 | 12 | networks <- list() 13 | 14 | for (i in 1:10) { 15 | mat <- matrix(rbinom(100, 1, .25), nrow = 10, ncol = 10) 16 | diag(mat) <- 0 17 | nw <- network::network(mat) 18 | networks[[i]] <- nw 19 | } 20 | 21 | covariates <- list() 22 | 23 | for (i in 1:10) { 24 | mat <- matrix(rnorm(100), nrow = 10, ncol = 10) 25 | covariates[[i]] <- mat 26 | } 27 | 28 | suppressWarnings( 29 | fit <- btergm::btergm( 30 | networks ~ edges + istar(2) + edgecov(covariates), 31 | R = 100, 32 | verbose = FALSE 33 | ) 34 | ) 35 | 36 | td <- tidy(fit) 37 | tde <- tidy(fit, exponentiate = TRUE) 38 | 39 | check_tidy_output(td) 40 | check_tidy_output(tde) 41 | 42 | check_dims(td, 3, 4) 43 | check_dims(tde, 3, 4) 44 | }) 45 | -------------------------------------------------------------------------------- /tests/testthat/test-caret.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("caret") 7 | 8 | test_that("tidy.confusionMatrix", { 9 | check_arguments(tidy.confusionMatrix) 10 | 11 | set.seed(28) 12 | 13 | two_class_sample1 <- factor(rbinom(100, 1, .5)) 14 | two_class_sample2 <- factor(rbinom(100, 1, .5)) 15 | 16 | multi_class_sample1 <- factor(rbinom(100, 4, .5)) 17 | multi_class_sample2 <- factor(rbinom(100, 4, .5)) 18 | 19 | two_class_cm <- caret::confusionMatrix( 20 | two_class_sample1, 21 | two_class_sample2 22 | ) 23 | 24 | multi_class_cm <- caret::confusionMatrix( 25 | multi_class_sample1, 26 | multi_class_sample2 27 | ) 28 | 29 | td_2c_by_class <- tidy(two_class_cm) 30 | td_2c <- tidy(two_class_cm, by_class = FALSE) 31 | 32 | check_tidy_output(td_2c_by_class) 33 | check_tidy_output(td_2c) 34 | 35 | td_mc_by_class <- tidy(multi_class_cm) 36 | td_mc <- tidy(multi_class_cm, by_class = FALSE) 37 | 38 | check_tidy_output(td_mc_by_class) 39 | check_tidy_output(td_mc) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-cluster.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("cluster") 7 | suppressPackageStartupMessages(library(cluster)) 8 | 9 | skip_if_not_installed("modeldata") 10 | library(modeldata) 11 | data(hpc_data) 12 | 13 | x <- hpc_data[1:300, 2:5] 14 | fit <- pam(x, k = 3) 15 | 16 | test_that("pam tidier arguments", { 17 | check_arguments(tidy.pam) 18 | check_arguments(glance.pam) 19 | check_arguments(augment.pam) 20 | }) 21 | 22 | test_that("tidy.pam", { 23 | td <- tidy(fit) 24 | 25 | # includes names of input data columns, so strict = FALSE 26 | check_tidy_output(td, strict = FALSE) 27 | check_dims(td, 3, 11) 28 | }) 29 | 30 | test_that("glance.pam", { 31 | gl <- glance(fit) 32 | check_glance_outputs(gl) 33 | check_dims(gl, expected_cols = 1) 34 | }) 35 | 36 | test_that("augment.pam", { 37 | suppressWarnings( 38 | check_augment_function( 39 | aug = augment.pam, 40 | model = fit, 41 | data = x, 42 | newdata = x 43 | ) 44 | ) 45 | }) 46 | -------------------------------------------------------------------------------- /tests/testthat/test-cmprsk.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("cmprsk") 7 | suppressPackageStartupMessages(library(cmprsk)) 8 | set.seed(2) 9 | 10 | # simulate data 11 | lrf_time <- rexp(100) # time to loco-regional failure (lrf) 12 | lrf_event <- sample(0:2, 100, replace = TRUE) 13 | trt <- sample(0:1, 100, replace = TRUE) 14 | strt <- sample(1:2, 100, replace = TRUE) 15 | 16 | # fit model 17 | fit <- cmprsk::crr(lrf_time, lrf_event, cbind(trt, strt)) 18 | 19 | test_that("cmprsk tidier arguments", { 20 | check_arguments(tidy.crr) 21 | check_arguments(glance.crr) 22 | }) 23 | 24 | test_that("tidy.cmprsk", { 25 | td1 <- tidy(fit) 26 | td2 <- tidy(fit, conf.int = TRUE) 27 | td3 <- tidy(fit, conf.int = TRUE, conf.level = 0.99) 28 | 29 | check_tidy_output(td1) 30 | check_tidy_output(td2) 31 | check_tidy_output(td3) 32 | 33 | check_dims(td1, 2, 5) 34 | check_dims(td2, 2, 7) 35 | check_dims(td3, 2, 7) 36 | 37 | # check the `conf.level=` argument matches the result in `summary(conf.int=)` 38 | expect_equal( 39 | { 40 | res <- summary(fit, conf.int = 0.99)$conf.int |> 41 | log() |> 42 | unname() |> 43 | as.data.frame() 44 | dplyr::select(res, tail(names(res), 2)) |> 45 | unclass() |> 46 | unname() 47 | }, 48 | td3 |> 49 | dplyr::select(conf.low, conf.high) |> 50 | unclass() |> 51 | unname() 52 | ) 53 | }) 54 | -------------------------------------------------------------------------------- /tests/testthat/test-data-frame.R: -------------------------------------------------------------------------------- 1 | test_that("glance.tbl_df errors informatively", { 2 | expect_snapshot(error = TRUE, glance.tbl_df(tibble::tibble(x = 1))) 3 | }) 4 | -------------------------------------------------------------------------------- /tests/testthat/test-drc.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("drc") 7 | suppressPackageStartupMessages(library(drc)) 8 | 9 | mod <- drm( 10 | dead / total ~ conc, 11 | type, 12 | weights = total, 13 | data = selenium, 14 | fct = LL.2(), 15 | type = "binomial" 16 | ) 17 | 18 | mod2 <- drm(rootl ~ conc, data = ryegrass, fct = W2.4()) 19 | 20 | test_that("drc tidier arguments", { 21 | check_arguments(tidy.drc) 22 | check_arguments(glance.drc) 23 | check_arguments(augment.drc, strict = FALSE) 24 | }) 25 | 26 | test_that("tidy.drc", { 27 | td1 <- tidy(mod) 28 | td3 <- tidy(mod, conf.int = TRUE) 29 | 30 | check_tidy_output(td1, strict = FALSE) 31 | check_tidy_output(td3, strict = FALSE) 32 | 33 | td1 <- tidy(mod2) 34 | td3 <- tidy(mod2, conf.int = TRUE) 35 | 36 | check_tidy_output(td1, strict = FALSE) 37 | check_tidy_output(td3, strict = FALSE) 38 | }) 39 | 40 | test_that("glance.drc", { 41 | gl1 <- glance(mod) 42 | gl2 <- glance(mod2) 43 | 44 | check_glance_outputs(gl1, gl2) 45 | }) 46 | 47 | test_that("augment.drc", { 48 | expect_snapshot(error = TRUE, augment(mod)) 49 | 50 | check_augment_function( 51 | augment.drc, 52 | mod, 53 | data = selenium, 54 | newdata = selenium 55 | ) 56 | 57 | expect_snapshot(error = TRUE, augment(mod2)) 58 | 59 | check_augment_function( 60 | augment.drc, 61 | mod2, 62 | data = ryegrass, 63 | newdata = ryegrass 64 | ) 65 | }) 66 | 67 | test_that("confidence merge issue regression test (#798)", { 68 | td <- tidy(mod, conf.int = TRUE) 69 | 70 | expect_false(any(is.na(td$conf.low))) 71 | expect_false(any(is.na(td$conf.high))) 72 | }) 73 | -------------------------------------------------------------------------------- /tests/testthat/test-epiR.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("epiR") 4 | 5 | dat <- matrix(c(13, 2163, 5, 3349), nrow = 2, byrow = TRUE) 6 | rownames(dat) <- c("DF+", "DF-") 7 | colnames(dat) <- c("FUS+", "FUS-") 8 | 9 | skip_if_not_installed("MASS") 10 | suppressPackageStartupMessages(library(MASS)) 11 | birthwt <- MASS::birthwt 12 | 13 | birthwt$low <- factor(birthwt$low, levels = c(1, 0)) 14 | birthwt$smoke <- factor(birthwt$smoke, levels = c(1, 0)) 15 | birthwt$race <- factor(birthwt$race, levels = c(1, 2, 3)) 16 | tab1 <- table(birthwt$smoke, birthwt$low, dnn = c("Smoke", "Low BW")) 17 | tab2 <- table( 18 | birthwt$smoke, 19 | birthwt$low, 20 | birthwt$race, 21 | dnn = c("Smoke", "Low BW", "Race") 22 | ) 23 | 24 | suppressPackageStartupMessages(library(epiR)) 25 | fit1 <- epi.2by2( 26 | dat = as.table(dat), 27 | method = "cross.sectional", 28 | conf.level = 0.95, 29 | units = 100, 30 | outcome = "as.columns" 31 | ) 32 | fit2 <- epi.2by2( 33 | dat = tab1, 34 | method = "cohort.count", 35 | conf.level = 0.95, 36 | units = 100, 37 | outcome = "as.columns" 38 | ) 39 | fit3 <- epi.2by2( 40 | dat = tab2, 41 | method = "cohort.count", 42 | conf.level = 0.95, 43 | units = 100, 44 | outcome = "as.columns" 45 | ) 46 | 47 | test_that("epi2by2 arguments", { 48 | check_arguments(tidy.epi.2by2) 49 | }) 50 | 51 | test_that("tidy.epi2by2", { 52 | tidy1 <- tidy(fit1) 53 | tidy2 <- tidy(fit2) 54 | tidy3 <- tidy(fit3, parameters = "stat") 55 | 56 | check_tidy_output(tidy1) 57 | check_tidy_output(tidy2) 58 | check_tidy_output(tidy3) 59 | 60 | # check_dims(tidy1, 13, 4) 61 | }) 62 | -------------------------------------------------------------------------------- /tests/testthat/test-ergm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("ergm") 7 | suppressPackageStartupMessages(library(ergm)) 8 | 9 | data(florentine) 10 | data(faux.mesa.high) 11 | 12 | # cut down on elapsed time at the expense of model performance 13 | ctrl <- control.ergm(MCMLE.maxit = 2) 14 | 15 | gest <- ergm(flomarriage ~ edges + absdiff("wealth")) 16 | gest2 <- ergm(flomarriage ~ edges + absdiff("wealth"), family = "gaussian") 17 | suppressWarnings({ 18 | gest3 <- ergm(faux.mesa.high ~ edges + degree(1:3), control = ctrl) 19 | }) 20 | 21 | test_that("ergm tidier arguments", { 22 | check_arguments(tidy.ergm) 23 | check_arguments(glance.ergm) 24 | }) 25 | 26 | test_that("tidy.ergm", { 27 | expect_snapshot({ 28 | tde <- tidy(gest, conf.int = TRUE, exponentiate = TRUE) 29 | }) 30 | 31 | check_tidy_output(tde) 32 | 33 | # regression test for #688 34 | expect_true("term" %in% colnames(tde)) 35 | 36 | # number of columns in output varies with ergm version 37 | # so this test is temporarily deactivated 38 | # check_dims(tde, 2, 7) 39 | 40 | # tidy.ergm warns when exponentiating w/o link 41 | expect_snapshot(td2 <- tidy(gest2, conf.int = TRUE, exponentiate = TRUE)) 42 | 43 | check_tidy_output(td2) 44 | 45 | # see comment above: 46 | # check_dims(td2, 2, 7) 47 | }) 48 | 49 | test_that("glance.ergm", { 50 | gl <- glance(gest, deviance = TRUE) 51 | gl2 <- glance(gest3, deviance = TRUE, mcmc = TRUE) 52 | expect_snapshot(gl3 <- glance(gest, deviance = TRUE, mcmc = TRUE)) 53 | 54 | check_glance_outputs(gl) 55 | check_dims(gl, expected_cols = 9) 56 | check_dims(gl2, expected_cols = 12) 57 | check_dims(gl, expected_cols = 9) 58 | }) 59 | -------------------------------------------------------------------------------- /tests/testthat/test-gam.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("gam") 7 | 8 | data(kyphosis, package = "gam") 9 | fit <- gam::gam( 10 | Kyphosis ~ gam::s(Age, 4) + Number, 11 | family = binomial, 12 | data = kyphosis 13 | ) 14 | 15 | test_that("gam::gam tidier arguments", { 16 | check_arguments(tidy.Gam) 17 | check_arguments(glance.Gam) 18 | }) 19 | 20 | test_that("tidy.Gam", { 21 | td <- tidy(fit) 22 | check_tidy_output(td) 23 | check_dims(td, 3, 6) 24 | }) 25 | 26 | test_that("glance.Gam", { 27 | gl <- glance(fit) 28 | check_glance_outputs(gl) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-geepack.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("geepack") 7 | suppressPackageStartupMessages(library(geepack)) 8 | 9 | dat <- data.frame(state.region, state.x77) 10 | 11 | fit <- geeglm( 12 | Income ~ Frost + Murder, 13 | id = state.region, 14 | data = dat, 15 | corstr = "exchangeable" 16 | ) 17 | 18 | test_that("tidy.geeglm", { 19 | check_arguments(tidy.geeglm) 20 | 21 | td <- tidy(fit, conf.int = TRUE) 22 | 23 | expect_snapshot({ 24 | td2 <- tidy(fit, conf.int = FALSE, exponentiate = TRUE) 25 | }) 26 | 27 | check_tidy_output(td) 28 | check_tidy_output(td2) 29 | }) 30 | 31 | test_that("glance.geeglm", { 32 | gl <- glance(fit) 33 | check_glance_outputs(gl) 34 | }) 35 | -------------------------------------------------------------------------------- /tests/testthat/test-glmnet.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | skip_if_not_installed("glmnet") 5 | suppressPackageStartupMessages(library(glmnet)) 6 | 7 | set.seed(27) 8 | 9 | x <- matrix(rnorm(100 * 20), 100, 20) 10 | y <- rnorm(100) 11 | g <- sample(1:4, 100, replace = TRUE) 12 | 13 | fit <- glmnet(x, y) 14 | fit2 <- glmnet(x, g, family = "multinomial") 15 | 16 | cv_fit <- cv.glmnet(x, y) 17 | cv_fit2 <- cv.glmnet(x, g, family = "multinomial") 18 | 19 | test_that("glmnet tidier arguments", { 20 | check_arguments(tidy.glmnet) 21 | check_arguments(glance.glmnet) 22 | 23 | check_arguments(tidy.cv.glmnet) 24 | check_arguments(glance.cv.glmnet) 25 | }) 26 | 27 | test_that("tidy.glmnet", { 28 | td <- tidy(fit) 29 | tdz <- tidy(fit, return_zeros = TRUE) 30 | 31 | check_tidy_output(td) 32 | check_tidy_output(tdz) 33 | 34 | check_dims(td, expected_cols = 5) 35 | check_dims(tdz, expected_cols = 5) 36 | 37 | expect_true(all(td$estimate != 0)) 38 | expect_true(any(tdz$estimate == 0)) 39 | 40 | # multinomial 41 | 42 | td2 <- tidy(fit2) 43 | td2z <- tidy(fit2, return_zeros = TRUE) 44 | 45 | check_tidy_output(td2) 46 | check_tidy_output(td2z) 47 | 48 | expect_true(all(td2$estimate != 0)) 49 | expect_true(any(td2z$estimate == 0)) 50 | 51 | # regression tests 52 | expect_true(is.numeric(td$step) && !any(is.na(td$step))) 53 | expect_true(is.numeric(td2$step) && !any(is.na(td2$step))) 54 | }) 55 | 56 | test_that("glance.glmnet", { 57 | gl <- glance(fit) 58 | gl2 <- glance(fit2) 59 | 60 | check_glance_outputs(gl, gl2) 61 | }) 62 | 63 | test_that("tidy.cv.glmnet", { 64 | td <- tidy(cv_fit) 65 | 66 | check_tidy_output(td) 67 | check_dims(td, expected_cols = 6) 68 | 69 | # multinomial 70 | 71 | td2 <- tidy(cv_fit2) 72 | 73 | check_tidy_output(td2) 74 | check_dims(td2, expected_cols = 6) 75 | }) 76 | 77 | test_that("glance.cv.glmnet", { 78 | gl <- glance(cv_fit) 79 | gl2 <- glance(cv_fit2) 80 | 81 | check_glance_outputs(gl, gl2) 82 | }) 83 | -------------------------------------------------------------------------------- /tests/testthat/test-glmnetUtils.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("glmnetUtils") 7 | suppressPackageStartupMessages(library(glmnetUtils)) 8 | 9 | set.seed(27) 10 | 11 | skip_if_not_installed("modeldata") 12 | library(modeldata) 13 | data(hpc_data) 14 | 15 | hpc_data <- hpc_data[1:300, ] 16 | 17 | fit <- glmnet(formula = mpg ~ ., data = mtcars) 18 | fit2 <- glmnet( 19 | formula = class ~ compounds + input_fields + iterations + num_pending, 20 | data = hpc_data, 21 | family = "multinomial" 22 | ) 23 | 24 | cv_fit <- cv.glmnet(formula = mpg ~ ., data = mtcars) 25 | cv_fit2 <- cv.glmnet( 26 | formula = class ~ compounds + input_fields + iterations + num_pending, 27 | data = hpc_data, 28 | family = "multinomial" 29 | ) 30 | 31 | 32 | test_that("glmnet.formula tidier arguments", { 33 | check_arguments(tidy.glmnet) 34 | check_arguments(glance.glmnet) 35 | 36 | check_arguments(tidy.cv.glmnet) 37 | check_arguments(glance.cv.glmnet) 38 | }) 39 | 40 | test_that("tidy.glmnet.formula", { 41 | td <- tidy(fit) 42 | tdz <- tidy(fit, return_zeros = TRUE) 43 | 44 | check_tidy_output(td) 45 | check_tidy_output(tdz) 46 | 47 | check_dims(td, expected_cols = 5) 48 | check_dims(tdz, expected_cols = 5) 49 | 50 | expect_true(all(td$estimate != 0)) 51 | expect_true(any(tdz$estimate == 0)) 52 | 53 | # multinomial 54 | 55 | td2 <- tidy(fit2) 56 | td2z <- tidy(fit2, return_zeros = TRUE) 57 | 58 | check_tidy_output(td2) 59 | check_tidy_output(td2z) 60 | 61 | expect_s3_class(td2, "tbl_df") 62 | 63 | expect_equal(dim(td2), c(1511L, 6L)) 64 | expect_equal(dim(td2z), c(2000L, 6L)) 65 | 66 | expect_true(all(td2$estimate != 0)) 67 | expect_true(any(td2z$estimate == 0)) 68 | 69 | # regression tests 70 | expect_true(is.numeric(td$step) && !any(is.na(td$step))) 71 | expect_true(is.numeric(td2$step) && !any(is.na(td2$step))) 72 | }) 73 | 74 | test_that("glance.glmnet.formula", { 75 | gl <- glance(fit) 76 | gl2 <- glance(fit2) 77 | 78 | check_glance_outputs(gl, gl2) 79 | 80 | expect_s3_class(gl, "tbl_df") 81 | expect_equal(dim(gl), c(1L, 3L)) 82 | }) 83 | -------------------------------------------------------------------------------- /tests/testthat/test-gmm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("gmm") 7 | suppressPackageStartupMessages(library(gmm)) 8 | 9 | data(Finance) 10 | 11 | r <- Finance[1:300, 1:10] 12 | rm <- Finance[1:300, "rm"] 13 | rf <- Finance[1:300, "rf"] 14 | 15 | z <- as.matrix(r - rf) 16 | t <- nrow(z) 17 | zm <- rm - rf 18 | h <- matrix(zm, t, 1) 19 | 20 | fit <- gmm(z ~ zm, x = h) 21 | 22 | test_that("gmm tidier arguments", { 23 | check_arguments(tidy.gmm) 24 | check_arguments(glance.gmm) 25 | }) 26 | 27 | test_that("tidy.gmm", { 28 | td <- tidy(fit) 29 | td2 <- tidy(fit, conf.int = TRUE) 30 | 31 | check_tidy_output(td) 32 | check_tidy_output(td2) 33 | }) 34 | 35 | test_that("glance.gmm", { 36 | gl <- glance(fit) 37 | check_glance_outputs(gl) 38 | }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-hmisc.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("Hmisc") 7 | 8 | test_that("tidy.rcorr", { 9 | check_arguments(tidy.rcorr) 10 | 11 | mat <- replicate(52, rnorm(100)) 12 | mat[sample(length(mat), 2000)] <- NA 13 | colnames(mat) <- c(LETTERS, letters) 14 | rc <- Hmisc::rcorr(mat) 15 | 16 | td <- tidy(rc) 17 | 18 | check_tidy_output(td) 19 | check_dims(td, expected_cols = 5) 20 | }) 21 | -------------------------------------------------------------------------------- /tests/testthat/test-kendall.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("Kendall") 7 | suppressPackageStartupMessages(library(Kendall)) 8 | 9 | a <- c(2.5, 2.5, 2.5, 2.5, 5, 6.5, 6.5, 10, 10, 10, 10, 10, 14, 14, 14, 16, 17) 10 | b <- c(1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 2, 2) 11 | 12 | kfit <- Kendall(a, b) 13 | mkfit <- MannKendall(a) 14 | smkfit <- SeasonalMannKendall(ts(b)) 15 | 16 | 17 | test_that("tidy.Kendall", { 18 | check_arguments(tidy.Kendall) 19 | 20 | ktd <- tidy(kfit) 21 | mktd <- tidy(mkfit) 22 | smkfit <- tidy(smkfit) 23 | 24 | check_tidy_output(ktd) 25 | check_tidy_output(mktd) 26 | check_tidy_output(smkfit) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-ks.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("ks") 7 | 8 | test_that("tidy.kde", { 9 | check_arguments(tidy.kde) 10 | 11 | fit <- ks::kde(mtcars[, 1:3]) 12 | td <- tidy(fit) 13 | 14 | check_tidy_output(td) 15 | check_dims(td, expected_cols = 4) 16 | }) 17 | -------------------------------------------------------------------------------- /tests/testthat/test-lavaan.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("lavaan") 7 | suppressPackageStartupMessages(library(lavaan)) 8 | 9 | fit <- sem("mpg ~ wt", data = mtcars) 10 | form <- paste("F =~", paste0("x", 1:9, collapse = " + ")) 11 | fit2 <- cfa(form, data = HolzingerSwineford1939) 12 | 13 | test_that("lavaan tidier arguments", { 14 | check_arguments(tidy.lavaan) 15 | check_arguments(glance.lavaan) 16 | }) 17 | 18 | test_that("tidy.lavaan", { 19 | td <- tidy(fit, conf.int = TRUE) 20 | td2 <- tidy(fit2, conf.int = TRUE) 21 | tdc <- tidy(fit2, conf.int = TRUE, conf.level = .999) 22 | tdr <- tidy(fit2, rsquare = TRUE) 23 | 24 | check_tidy_output(td) 25 | check_tidy_output(td2) 26 | check_tidy_output(tdc) 27 | check_tidy_output(tdr) 28 | 29 | check_dims(td, 3, 11) 30 | # std.nox not available without fixed exogenous predictors (#1217) 31 | check_dims(td2, 19, 10) 32 | 33 | expect_equal(td$term, c("mpg ~ wt", "mpg ~~ mpg", "wt ~~ wt")) 34 | 35 | op_counts <- dplyr::count(td2, op)$n 36 | expect_true((all(9:10 %in% op_counts))) 37 | 38 | # check conf level 39 | expect_true(all(td2$conf.high <= tdc$conf.high)) 40 | 41 | # passing arguments via ... 42 | check_dims(filter(tdr, op == "r2"), expected_rows = 9) 43 | }) 44 | 45 | 46 | test_that("glance.lavaan", { 47 | gl <- glance(fit) 48 | check_glance_outputs(gl) 49 | 50 | gl2 <- glance(fit2) 51 | check_glance_outputs(gl2) 52 | }) 53 | -------------------------------------------------------------------------------- /tests/testthat/test-leaps.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("leaps") 7 | 8 | test_that("tidy.regsubsets", { 9 | check_arguments(tidy.regsubsets) 10 | 11 | all_fits <- leaps::regsubsets(hp ~ ., mtcars) 12 | td <- tidy(all_fits) 13 | 14 | # column names are essentially those for glance, 15 | # also column names from training data sneak through, 16 | # so strict tests will fail 17 | check_tidy_output(td, strict = FALSE) 18 | }) 19 | -------------------------------------------------------------------------------- /tests/testthat/test-list-irlba.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("irlba") 7 | 8 | mat <- scale(as.matrix(USJudgeRatings)) 9 | s <- svd(mat) 10 | p <- prcomp(mat) 11 | i <- irlba::irlba(mat) 12 | 13 | test_that("tidy_irlba", { 14 | check_arguments(tidy_irlba) 15 | 16 | tdu <- tidy(i, matrix = "u") 17 | check_tidy_output(tdu) 18 | check_dims(tdu, 215, 3) 19 | 20 | tdd <- tidy(i, matrix = "d") 21 | check_tidy_output(tdd) 22 | check_dims(tdd, 5, 4) 23 | 24 | tdv <- tidy(i, matrix = "v") 25 | check_tidy_output(tdv, strict = FALSE) 26 | check_dims(tdv, 60, 3) 27 | }) 28 | 29 | test_that("prcomp/svd/irlba consistency", { 30 | expect_equal(colnames(tidy(i)), colnames(tidy(p))) 31 | expect_equal(colnames(tidy(i)), colnames(tidy(s))) 32 | expect_equal(colnames(tidy(s)), colnames(tidy(p))) 33 | 34 | expect_equal( 35 | colnames(tidy(i, matrix = "d")), 36 | colnames(tidy(p, matrix = "d")) 37 | ) 38 | expect_equal( 39 | colnames(tidy(i, matrix = "d")), 40 | colnames(tidy(s, matrix = "d")) 41 | ) 42 | expect_equal( 43 | colnames(tidy(s, matrix = "d")), 44 | colnames(tidy(p, matrix = "d")) 45 | ) 46 | 47 | expect_equal( 48 | colnames(tidy(i, matrix = "v")), 49 | colnames(tidy(p, matrix = "v")) 50 | ) 51 | expect_equal( 52 | colnames(tidy(i, matrix = "v")), 53 | colnames(tidy(s, matrix = "v")) 54 | ) 55 | expect_equal( 56 | colnames(tidy(s, matrix = "v")), 57 | colnames(tidy(p, matrix = "v")) 58 | ) 59 | }) 60 | -------------------------------------------------------------------------------- /tests/testthat/test-list-optim.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | test_that("optim tidiers works", { 7 | func <- function(x) { 8 | (x[1] - 2)^2 + (x[2] - 3)^2 + (x[3] - 8)^2 9 | } 10 | 11 | o <- optim(c(1, 1, 1), func) 12 | 13 | check_arguments(tidy_optim) 14 | check_arguments(glance_optim) 15 | 16 | td <- tidy(o) 17 | check_tidy_output(td) 18 | check_dims(td, 3, 2) 19 | 20 | gl <- glance(o) 21 | check_glance_outputs(gl) 22 | }) 23 | 24 | test_that("optim std.error inclusion works", { 25 | func <- function(x) { 26 | (x[1] - 2)^2 + (x[2] - 3)^2 + (x[3] - 8)^2 27 | } 28 | 29 | o <- optim(c(1, 1, 1), func, hessian = TRUE) 30 | 31 | check_arguments(tidy_optim) 32 | check_arguments(glance_optim) 33 | 34 | td <- tidy(o) 35 | check_tidy_output(td) 36 | check_dims(td, 3, 3) 37 | expect_true("std.error" %in% names(td)) 38 | }) 39 | -------------------------------------------------------------------------------- /tests/testthat/test-list-svd.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | mat <- scale(as.matrix(USJudgeRatings)) 7 | s <- svd(mat) 8 | p <- prcomp(mat) 9 | 10 | test_that("tidy_svd", { 11 | check_arguments(tidy_svd) 12 | 13 | tdu <- tidy(s, matrix = "u") 14 | tdd <- tidy(s, matrix = "d") 15 | tdv <- tidy(s, matrix = "v") 16 | 17 | check_tidy_output(tdu) 18 | check_tidy_output(tdd) 19 | check_tidy_output(tdv, strict = FALSE) 20 | 21 | check_dims(tdu, 516, 3) 22 | check_dims(tdd, 12, 4) 23 | check_dims(tdv, 144, 3) 24 | }) 25 | 26 | test_that("tidy_svd errors informatively", { 27 | expect_snapshot(error = TRUE, tidy_svd(matrix = c("u", "v"))) 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-list-xyz.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | test_that("tidy_xyz", { 7 | check_arguments(tidy_xyz) 8 | 9 | a <- list( 10 | x = 1:5, 11 | y = 1:3, 12 | z = matrix(runif(5 * 3), nrow = 5) 13 | ) 14 | 15 | b <- list( 16 | x = 1:5, 17 | y = 1:3, 18 | z = matrix(runif(4 * 2), nrow = 4) 19 | ) 20 | 21 | c <- list( 22 | x = 1:5, 23 | y = 1:3, 24 | z = matrix(runif(10 * 2), nrow = 5) 25 | ) 26 | 27 | d <- list(x = 1:5, y = 1:3, z = "cat") 28 | 29 | check_arguments(tidy_xyz) 30 | 31 | td <- tidy(a) 32 | 33 | check_tidy_output(td, strict = FALSE) 34 | check_dims(td, 15, 3) 35 | 36 | expect_true(is.numeric(td$x)) 37 | expect_true(is.numeric(td$y)) 38 | expect_true(is.numeric(td$z)) 39 | 40 | expect_snapshot(error = TRUE, tidy(b)) 41 | expect_snapshot(error = TRUE, tidy(c)) 42 | expect_snapshot(error = TRUE, tidy(d)) 43 | }) 44 | -------------------------------------------------------------------------------- /tests/testthat/test-list.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | test_that("not all lists can be tidied", { 7 | nl <- list(a = NULL) 8 | 9 | expect_snapshot(error = TRUE, tidy(nl)) 10 | expect_snapshot(error = TRUE, glance(nl)) 11 | }) 12 | -------------------------------------------------------------------------------- /tests/testthat/test-lmbeta-lm-beta.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("lm.beta") 7 | suppressPackageStartupMessages(library(lm.beta)) 8 | 9 | test_that("lm.beta tidier arguments", { 10 | check_arguments(tidy.lm.beta) 11 | }) 12 | 13 | fit <- lm.beta::lm.beta(lm(mpg ~ wt, mtcars)) 14 | fit2 <- lm.beta::lm.beta(lm(mpg ~ wt + log(disp), mtcars)) 15 | 16 | # the cyl:qsec term isn't defined for this fit 17 | na_row_data <- mtcars[c(6, 9, 13:15, 22), ] 18 | fit_na_row <- lm(mpg ~ cyl * qsec + gear, data = na_row_data) 19 | 20 | # rank-deficient fit 21 | rd_data <- data.frame(y = rnorm(10), x = letters[seq_len(10)]) 22 | fit_rd <- lm(y ~ x - 1, data = rd_data) 23 | 24 | test_that("tidy.lm.beta works", { 25 | td <- tidy(fit) 26 | td2 <- tidy(fit2) 27 | 28 | # conf.int = TRUE works for rank deficient fits 29 | # should get a "NaNs produced" warning. 30 | # not snapshotting as we don't own the error message. 31 | expect_warning(td_rd <- tidy(fit_rd, conf.int = TRUE)) 32 | 33 | check_tidy_output(td) 34 | check_tidy_output(td2) 35 | 36 | check_tidy_output(td_rd) 37 | 38 | check_dims(td, expected_rows = 2) 39 | check_dims(td2, expected_rows = 3) 40 | 41 | expect_equal(td$term, c("(Intercept)", "wt")) 42 | expect_equal(td2$term, c("(Intercept)", "wt", "log(disp)")) 43 | 44 | # shouldn't error. regression test for issues 166, 241 45 | # rows for confidence intervals of undefined terms should be dropped 46 | expect_no_error(tidy(fit_na_row, conf.int = TRUE)) 47 | }) 48 | -------------------------------------------------------------------------------- /tests/testthat/test-lmodel2.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("lmodel2") 7 | suppressPackageStartupMessages(library(lmodel2)) 8 | 9 | data("mod2ex2") 10 | fit <- lmodel2(Prey ~ Predators, data = mod2ex2, "relative", "relative", 99) 11 | 12 | test_that("lmodel2 tidier arguments", { 13 | check_arguments(tidy.lmodel2) 14 | check_arguments(glance.lmodel2) 15 | }) 16 | 17 | test_that("tidy.lmodel2", { 18 | td <- tidy(fit) 19 | check_tidy_output(td) 20 | check_dims(td, 8, 6) 21 | }) 22 | 23 | test_that("glance.lmodel2", { 24 | gl <- glance(fit) 25 | check_glance_outputs(gl) 26 | }) 27 | -------------------------------------------------------------------------------- /tests/testthat/test-lmtest.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("lmtest") 7 | suppressPackageStartupMessages(library(lmtest)) 8 | 9 | skip_if_not_installed("sandwich") 10 | suppressPackageStartupMessages(library(sandwich)) 11 | 12 | m <- lm(dist ~ speed, data = cars) 13 | ct <- lmtest::coeftest(m) 14 | ct2 <- lmtest::coeftest(m, save = TRUE) 15 | ct3 <- lmtest::coeftest(m, vcov = sandwich::vcovHC) 16 | 17 | test_that("tidy.coeftest", { 18 | # skip_on_os("linux") 19 | 20 | check_arguments(tidy.coeftest) 21 | 22 | td <- tidy(ct) 23 | td2 <- tidy(ct2) 24 | td3 <- tidy(ct3) 25 | 26 | check_tidy_output(td) 27 | check_tidy_output(td2) 28 | check_tidy_output(td3) 29 | 30 | check_dims(td, 2, 5) 31 | 32 | # conf int 33 | td_ci <- tidy(ct, conf.int = TRUE, conf.level = 0.9) |> 34 | tibble::remove_rownames() 35 | check_tidy_output(td_ci) 36 | check_dims(td_ci, 2, 7) 37 | 38 | # should be like lm! 39 | td_lm_ci <- tidy(m, conf.int = TRUE, conf.level = 0.9) |> 40 | tibble::remove_rownames() 41 | expect_equal(td_lm_ci, td_ci) 42 | }) 43 | 44 | test_that("glance.coeftest", { 45 | gl <- glance(ct) 46 | gl2 <- glance(ct2) 47 | gl3 <- glance(ct3) 48 | 49 | check_glance_outputs(gl, gl3) 50 | check_glance_outputs(gl2) # separately because save = TRUE adds cols 51 | }) 52 | 53 | test_that("vcovCL.coeftest (#1227)", { 54 | m <- lm(Wind ~ 1, data = airquality) 55 | ct <- coeftest(m, vcovCL(m, cluster = ~Month)) 56 | ct_confint <- confint(ct, level = .9) 57 | output <- tidy(ct, conf.int = TRUE, conf.level = .9) 58 | expect_equal( 59 | output[c("conf.low", "conf.high")], 60 | as.data.frame(ct_confint), 61 | ignore_attr = TRUE 62 | ) 63 | }) 64 | -------------------------------------------------------------------------------- /tests/testthat/test-maps.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("maps") 7 | ca <- maps::map("county", "ca", plot = FALSE, fill = TRUE) 8 | 9 | test_that("tidy.map", { 10 | check_arguments(tidy.map) 11 | 12 | td <- tidy(ca) 13 | check_tidy_output(td, strict = FALSE) 14 | check_dims(td, expected_cols = 7) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-margins.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("margins") 7 | suppressPackageStartupMessages(library(margins)) 8 | 9 | fit1 <- glm(am ~ cyl + hp + wt, data = mtcars, family = binomial) 10 | marg1 <- margins(fit1) 11 | 12 | fit2 <- lm(mpg ~ wt * cyl * disp, data = mtcars) 13 | marg2a <- margins(fit2) 14 | marg2b <- margins(fit2, variable = "wt") 15 | marg2c <- margins(fit2, at = list(cyl = c(4, 6, 8))) 16 | marg2d <- margins( 17 | fit2, 18 | variables = "wt", 19 | at = list(cyl = c(4, 6, 8), drat = c(3, 3.5, 4)) 20 | ) 21 | 22 | test_that("margins tidier arguments", { 23 | check_arguments(tidy.margins) 24 | check_arguments(glance.margins) 25 | }) 26 | 27 | test_that("tidy.margins", { 28 | td1a <- tidy(marg1) 29 | td1b <- tidy(marg1, conf.int = TRUE) 30 | td2a <- tidy(marg2a) 31 | td2b <- tidy(marg2b) 32 | td2c <- tidy(marg2c) 33 | td2d <- tidy(marg2d) 34 | 35 | check_tidy_output(td1a) 36 | check_tidy_output(td1b) 37 | check_tidy_output(td2a) 38 | check_tidy_output(td2b) 39 | check_tidy_output(td2c) 40 | check_tidy_output(td2d) 41 | 42 | check_dims(td1a, 3, 5) 43 | }) 44 | 45 | test_that("glance.margins", { 46 | gl1 <- glance(fit1) 47 | gl2 <- glance(fit2) 48 | 49 | check_dims(gl1, expected_cols = 8) 50 | check_dims(gl2, expected_cols = 12) 51 | }) 52 | -------------------------------------------------------------------------------- /tests/testthat/test-mass-fitdistr.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("MASS") 7 | 8 | set.seed(27) 9 | x <- rnorm(100, 5, 2) 10 | fit <- suppressWarnings(MASS::fitdistr(x, dnorm, list(mean = 3, sd = 1))) 11 | 12 | test_that("fitdistr tidier arguments", { 13 | check_arguments(tidy.fitdistr) 14 | check_arguments(glance.fitdistr) 15 | }) 16 | 17 | test_that("tidy.fitdistr", { 18 | td <- tidy(fit) 19 | check_tidy_output(td) 20 | check_dims(td, 2, 3) 21 | }) 22 | 23 | test_that("glance.fitdistr", { 24 | gl <- glance(fit) 25 | check_glance_outputs(gl) 26 | check_dims(gl, expected_cols = 4) 27 | }) 28 | -------------------------------------------------------------------------------- /tests/testthat/test-mass-negbin.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | skip_if_not_installed("MASS") 5 | suppressPackageStartupMessages(library(MASS)) 6 | 7 | fit <- glm.nb(Days ~ Sex / (Age + Eth * Lrn), data = MASS::quine) 8 | 9 | test_that("MASS::glm.nb tidier arguments", { 10 | check_arguments(tidy.negbin) 11 | check_arguments(glance.negbin) 12 | }) 13 | 14 | test_that("tidy.negbin", { 15 | td1 <- tidy(fit) 16 | td2 <- tidy(fit, conf.int = TRUE) 17 | td3 <- tidy(fit, exponentiate = TRUE, conf.int = TRUE) 18 | 19 | check_tidy_output(td2) 20 | check_tidy_output(td1) 21 | 22 | expect_false(NA %in% td2$conf.low) 23 | expect_false(NA %in% td2$conf.high) 24 | 25 | # exponentiate arg check 26 | expect_equal( 27 | as.matrix(td3[, c("estimate", "conf.low", "conf.high")]), 28 | exp(as.matrix(td2[, c("estimate", "conf.low", "conf.high")])) 29 | ) 30 | }) 31 | 32 | test_that("glance.negbin", { 33 | gl <- glance(fit) 34 | check_glance_outputs(gl) 35 | check_dims(gl, 1, 8) 36 | }) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-mass-polr.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("MASS") 7 | suppressPackageStartupMessages(library(MASS)) 8 | 9 | fit <- polr( 10 | Sat ~ Infl + Type + Cont, 11 | weights = Freq, 12 | data = housing, 13 | Hess = TRUE 14 | ) 15 | 16 | fit2 <- polr(Sat ~ Freq, data = housing) 17 | 18 | test_that("MASS::polr tidier arguments", { 19 | check_arguments(tidy.polr) 20 | check_arguments(glance.polr) 21 | check_arguments(augment.polr) 22 | }) 23 | 24 | test_that("tidy.polr", { 25 | td <- tidy(fit) 26 | td2 <- tidy(fit, conf.int = TRUE, exponentiate = TRUE) 27 | td3 <- tidy(fit2, conf.int = TRUE, exponentiate = TRUE) 28 | 29 | check_tidy_output(td, strict = FALSE) 30 | check_tidy_output(td2, strict = FALSE) 31 | check_tidy_output(td3, strict = FALSE) 32 | 33 | check_dims(td, expected_cols = 5) 34 | check_dims(td2, expected_cols = 7) 35 | check_dims(td3, expected_cols = 7) 36 | }) 37 | 38 | test_that("glance.polr", { 39 | gl <- glance(fit) 40 | check_glance_outputs(gl) 41 | }) 42 | 43 | test_that("augment.polr", { 44 | check_augment_function( 45 | aug = augment.polr, 46 | model = fit, 47 | data = housing, 48 | newdata = housing, 49 | strict = FALSE 50 | ) 51 | 52 | au <- augment(fit, type.predict = "class") 53 | expect_s3_class(au$.fitted, "factor") 54 | expect_equal(predict(fit, type = "class"), au$.fitted) 55 | }) 56 | 57 | test_that("suppress Waiting for profiling to be done... message", { 58 | expect_silent(tidy(fit, conf.int = TRUE)) 59 | }) 60 | 61 | test_that("tidy.polr messages informatively", { 62 | mtcars$cyl <- as.factor(mtcars$cyl) 63 | mtcars$gear <- as.factor(mtcars$gear) 64 | 65 | fit <- polr( 66 | gear ~ cyl, 67 | data = mtcars, 68 | Hess = TRUE 69 | ) 70 | 71 | expect_snapshot(.res <- tidy(fit, p.values = TRUE)) 72 | }) 73 | -------------------------------------------------------------------------------- /tests/testthat/test-mass-ridgelm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("MASS") 7 | 8 | names(longley)[1] <- "y" 9 | fit2 <- MASS::lm.ridge(y ~ ., longley) 10 | fit3 <- MASS::lm.ridge(y ~ ., longley, lambda = seq(0.001, .05, .001)) 11 | 12 | test_that("MASS::lm.ridge tidier arguments", { 13 | check_arguments(tidy.ridgelm) 14 | check_arguments(glance.ridgelm) 15 | }) 16 | 17 | test_that("tidy.ridgelm", { 18 | td2 <- tidy(fit2) 19 | td3 <- tidy(fit3) 20 | 21 | check_tidy_output(td2) 22 | check_tidy_output(td3) 23 | }) 24 | 25 | test_that("glance.ridgelm", { 26 | gl2 <- glance(fit2) 27 | gl3 <- glance(fit3) 28 | check_glance_outputs(gl2, gl3) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-mass-rlm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("MASS") 7 | suppressPackageStartupMessages(library(MASS)) 8 | 9 | fit <- rlm(stack.loss ~ ., stackloss) 10 | 11 | test_that("MASS::rlm tidier arguments", { 12 | check_arguments(tidy.rlm) 13 | check_arguments(glance.rlm) 14 | check_arguments(augment.rlm) 15 | }) 16 | 17 | test_that("tidy.rlm", { 18 | td2 <- tidy(fit, conf.int = TRUE) 19 | 20 | check_tidy_output(td2) 21 | 22 | # regression test for #380 23 | expect_false(NA %in% td2$conf.low) 24 | expect_false(NA %in% td2$conf.high) 25 | }) 26 | 27 | test_that("glance.rlm", { 28 | gl <- glance(fit) 29 | check_glance_outputs(gl) 30 | check_dims(gl, 1, 7) 31 | }) 32 | 33 | test_that("augment.rlm", { 34 | skip_on_os("linux") 35 | 36 | check_augment_function( 37 | aug = augment.rlm, 38 | model = fit, 39 | data = stackloss, 40 | newdata = stackloss 41 | ) 42 | }) 43 | -------------------------------------------------------------------------------- /tests/testthat/test-mediation.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("mediation") 7 | suppressPackageStartupMessages(library(mediation)) 8 | 9 | data(jobs) 10 | b <- lm(job_seek ~ treat + econ_hard + sex + age, data = jobs) 11 | c <- lm(depress2 ~ treat + job_seek + econ_hard + sex + age, data = jobs) 12 | mod <- mediate(b, c, sims = 50, treat = "treat", mediator = "job_seek") 13 | 14 | test_that("mediation tidier arguments", { 15 | check_arguments(tidy.mediate) 16 | }) 17 | 18 | test_that("tidy.mediation", { 19 | td1 <- tidy(mod, conf.int = TRUE, conf.level = 0.99) 20 | td2 <- tidy(mod, conf.int = TRUE) 21 | 22 | check_tidy_output(td1) 23 | check_tidy_output(td2) 24 | 25 | check_dims(td1, 4, 6) 26 | }) 27 | 28 | test_that("tidy.mediate errors informatively", { 29 | # Test error for psych package mediate object 30 | psych_mediate <- structure(list(), class = c("mediate", "psych")) 31 | expect_snapshot(error = TRUE, tidy(psych_mediate)) 32 | }) 33 | -------------------------------------------------------------------------------- /tests/testthat/test-mgcv.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("mgcv") 7 | 8 | fit <- mgcv::gam(weight ~ s(Time) + factor(Diet), data = ChickWeight) 9 | 10 | test_that("mgcv tidier arguments", { 11 | check_arguments(tidy.gam) 12 | check_arguments(glance.gam) 13 | check_arguments(augment.gam, strict = FALSE) 14 | }) 15 | 16 | test_that("tidy.gam", { 17 | td <- tidy(fit) 18 | tdp <- tidy(fit, parametric = TRUE, conf.int = TRUE) 19 | tdp_exp <- tidy(fit, parametric = TRUE, conf.int = TRUE, exponentiate = TRUE) 20 | 21 | check_tidy_output(td, strict = FALSE) 22 | check_tidy_output(tdp) 23 | 24 | # test coef exponentiated 25 | expect_equal( 26 | as.matrix(tdp_exp[, c("estimate", "conf.low", "conf.high")]), 27 | exp(as.matrix(tdp[, c("estimate", "conf.low", "conf.high")])) 28 | ) 29 | }) 30 | 31 | test_that("glance.gam", { 32 | gl <- glance(fit) 33 | check_glance_outputs(gl) 34 | }) 35 | 36 | test_that("augment.gam", { 37 | suppressWarnings( 38 | check_augment_function( 39 | augment.gam, 40 | fit, 41 | data = ChickWeight, 42 | newdata = ChickWeight 43 | ) 44 | ) 45 | }) 46 | 47 | test_that("tidy.gam handles messages informatively", { 48 | x <- fit <- mgcv::gam(weight ~ s(Time) + factor(Diet), data = ChickWeight) 49 | expect_snapshot(.res <- tidy(x, conf.int = TRUE)) 50 | expect_snapshot(.res <- tidy(x, exponentiate = TRUE)) 51 | expect_snapshot(.res <- tidy(x, conf.int = TRUE, exponentiate = TRUE)) 52 | }) 53 | -------------------------------------------------------------------------------- /tests/testthat/test-mlogit.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("mlogit") 7 | skip_if_not_installed("AER") 8 | suppressPackageStartupMessages(library(mlogit)) 9 | suppressPackageStartupMessages(library(AER)) 10 | library(dplyr) 11 | 12 | data("Fishing", package = "mlogit") 13 | Fish <- dfidx(Fishing, varying = 2:9, shape = "wide", choice = "mode") 14 | fit1 <- mlogit(mode ~ price + catch, data = Fish) 15 | 16 | data("TravelMode", package = "AER") 17 | fit2 <- mlogit(choice ~ wait + travel + vcost, TravelMode, heterosc = TRUE) 18 | 19 | test_that("mlogit tidier arguments", { 20 | check_arguments(tidy.mlogit) 21 | check_arguments(glance.mlogit) 22 | check_arguments(augment.mlogit, strict = FALSE) 23 | }) 24 | 25 | test_that("tidy.mlogit", { 26 | td1 <- tidy(fit1) 27 | td2 <- tidy(fit1, conf.int = TRUE) 28 | td3 <- tidy(fit2) 29 | td4 <- tidy(fit2, conf.int = TRUE) 30 | 31 | check_tidy_output(td1) 32 | check_tidy_output(td2) 33 | check_tidy_output(td3) 34 | check_tidy_output(td4) 35 | }) 36 | 37 | test_that("glance.mlogit", { 38 | gl1 <- glance(fit1) 39 | gl2 <- glance(fit2) 40 | 41 | check_glance_outputs(gl1) 42 | check_glance_outputs(gl2) 43 | }) 44 | 45 | test_that("augment.mlogit", { 46 | check_augment_function( 47 | aug = augment.mlogit, 48 | model = fit1, 49 | data = Fish, 50 | newdata = Fish, 51 | strict = FALSE 52 | ) 53 | 54 | au1 <- augment(fit1) 55 | au2 <- augment(fit2) 56 | 57 | expect_true(all( 58 | c("id", "alternative", "chosen", ".resid", ".fitted") %in% names(au1) 59 | )) 60 | expect_true(all( 61 | c("id", "alternative", "chosen", ".resid", ".fitted") %in% names(au2) 62 | )) 63 | }) 64 | -------------------------------------------------------------------------------- /tests/testthat/test-muhaz.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("muhaz") 7 | skip_if_not_installed("survival") # does this skip with base R? 8 | 9 | suppressPackageStartupMessages(library(muhaz)) 10 | 11 | # load the ovarian data 12 | data(cancer, package = "survival") 13 | 14 | fit <- muhaz(ovarian$futime, ovarian$fustat) 15 | 16 | test_that("muhaz tidier arguments", { 17 | check_arguments(tidy.muhaz) 18 | check_arguments(glance.muhaz) 19 | }) 20 | 21 | test_that("tidy.muhaz", { 22 | td <- tidy(fit) 23 | check_tidy_output(td) 24 | check_dims(td, expected_cols = 2) 25 | }) 26 | 27 | test_that("glance.muhaz", { 28 | gl <- glance(fit) 29 | check_glance_outputs(gl, strict = FALSE) 30 | check_dims(gl, expected_cols = 5) 31 | }) 32 | -------------------------------------------------------------------------------- /tests/testthat/test-multcomp.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("multcomp") 7 | suppressPackageStartupMessages(library(multcomp)) 8 | 9 | amod <- aov(breaks ~ wool + tension, data = warpbreaks) 10 | wht <- glht(amod, linfct = mcp(tension = "Tukey")) 11 | 12 | test_that("multcomp tidier arguments", { 13 | check_arguments(tidy.glht) 14 | check_arguments(tidy.confint.glht) 15 | check_arguments(tidy.summary.glht) 16 | check_arguments(tidy.cld) 17 | }) 18 | 19 | test_that("tidy.glht", { 20 | td <- tidy(wht) 21 | check_tidy_output(td, strict = FALSE) 22 | check_dims(td, 3, 7) 23 | }) 24 | 25 | test_that("tidy.confint.glht", { 26 | td <- tidy(confint(wht)) 27 | check_tidy_output(td) 28 | check_dims(td, 3, 5) 29 | }) 30 | 31 | test_that("tidy.summary.glht works", { 32 | td <- tidy(summary(wht, test = adjusted("bonferroni"))) 33 | check_tidy_output(td, strict = FALSE) 34 | check_dims(td, 3, 7) 35 | 36 | expect_true("adj.p.value" %in% colnames(td)) 37 | expect_identical(td, tidy(wht, test = adjusted("bonferroni"))) 38 | 39 | td <- tidy(summary(wht, test = adjusted("none"))) 40 | expect_true("p.value" %in% colnames(td)) 41 | }) 42 | 43 | test_that("tidy.cld works", { 44 | td <- tidy(multcomp::cld(wht)) 45 | check_tidy_output(td, strict = FALSE) 46 | check_dims(td, 3, 2) 47 | }) 48 | 49 | test_that("tidy.glht consistency with tidy.TukeyHSD", { 50 | set.seed(13986) 51 | td_hsd <- tidy(TukeyHSD(amod, "tension")) 52 | td_glht <- tidy(wht, conf.int = TRUE) |> 53 | dplyr::select(-statistic) |> 54 | mutate(contrast = gsub(" ", "", contrast)) 55 | 56 | expect_equal( 57 | as.data.frame(td_hsd), 58 | as.data.frame(td_glht), 59 | ignore_attr = TRUE, 60 | tolerance = 0.001 61 | ) 62 | }) 63 | -------------------------------------------------------------------------------- /tests/testthat/test-nnet.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("nnet") 7 | suppressPackageStartupMessages(library(nnet)) 8 | 9 | fit <- multinom(gear ~ mpg + factor(am), data = mtcars, trace = FALSE) 10 | 11 | response <- t(rmultinom(100, 1, c(0.1, 0.2, 0.3, 0.4))) 12 | fit_matrix_response <- multinom(response ~ 1, trace = FALSE) 13 | 14 | test_that("nnet tidier arguments", { 15 | check_arguments(tidy.multinom) 16 | check_arguments(glance.multinom) 17 | }) 18 | 19 | test_that("tidy.multinom when y has only 2 levels", { 20 | dfr <- data.frame(a = rnorm(100)) 21 | dfr$y <- dfr$a + rnorm(100) 22 | twolevels <- nnet::multinom(I(y > 0) ~ a, dfr, trace = FALSE) 23 | td1 <- tidy(twolevels, conf.int = TRUE) 24 | check_tidy_output(td1) 25 | check_dims(td1, 2, 8) 26 | }) 27 | 28 | test_that("tidy.multinom", { 29 | td1 <- tidy(fit, conf.int = TRUE) 30 | td2 <- tidy(fit_matrix_response, conf.int = TRUE) 31 | check_tidy_output(td1) 32 | check_tidy_output(td2) 33 | check_dims(td1, 6, 8) 34 | check_dims(td2, 3, 8) 35 | }) 36 | 37 | test_that("glance.multinom", { 38 | gl <- glance(fit) 39 | check_glance_outputs(gl) 40 | check_dims(gl, expected_cols = 4) 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test-null-and-default.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | test_that("tidy.NULL", { 5 | expect_equal(tidy(NULL), tibble()) 6 | }) 7 | 8 | test_that("tidy.default", { 9 | expect_snapshot(error = TRUE, td <- tidy(raw(1))) 10 | 11 | x <- 5 12 | class(x) <- c("foo", "bar") 13 | expect_snapshot(error = TRUE, glance(x)) 14 | expect_snapshot(error = TRUE, glance(x)) 15 | }) 16 | 17 | 18 | test_that("glance.NULL", { 19 | expect_equal(glance(NULL), tibble()) 20 | }) 21 | 22 | test_that("glance.default", { 23 | expect_snapshot(error = TRUE, glance(TRUE)) 24 | expect_snapshot(error = TRUE, glance(1)) 25 | expect_snapshot(error = TRUE, glance(1L)) 26 | expect_snapshot(error = TRUE, glance("a")) 27 | 28 | x <- 5 29 | class(x) <- c("foo", "bar") 30 | expect_snapshot(error = TRUE, glance(x)) 31 | expect_snapshot(error = TRUE, glance(x)) 32 | }) 33 | 34 | test_that("augment.NULL", { 35 | expect_equal(augment(NULL), tibble()) 36 | }) 37 | 38 | test_that("augment.default", { 39 | expect_snapshot(error = TRUE, augment(TRUE)) 40 | expect_snapshot(error = TRUE, augment(1)) 41 | expect_snapshot(error = TRUE, augment(1L)) 42 | expect_snapshot(error = TRUE, augment("a")) 43 | 44 | x <- 5 45 | class(x) <- c("foo", "bar") 46 | expect_snapshot(error = TRUE, augment(x)) 47 | expect_snapshot(error = TRUE, augment(x)) 48 | }) 49 | -------------------------------------------------------------------------------- /tests/testthat/test-plm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("plm") 7 | suppressPackageStartupMessages(library(plm)) 8 | 9 | data(Produc, package = "plm") 10 | fit <- plm( 11 | log(gsp) ~ log(pcap) + log(pc) + log(emp) + unemp, 12 | data = Produc, 13 | index = c("state", "year") 14 | ) 15 | 16 | test_that("plm tidier arguments", { 17 | check_arguments(tidy.plm) 18 | check_arguments(glance.plm) 19 | check_arguments(augment.plm) 20 | }) 21 | 22 | test_that("tidy.plm", { 23 | td <- tidy(fit, conf.int = TRUE) 24 | check_tidy_output(td) 25 | check_dims(td, 4, 7) 26 | }) 27 | 28 | test_that("glance.plm", { 29 | gl <- glance(fit) 30 | check_glance_outputs(gl) 31 | check_dims(gl, expected_cols = 7) 32 | }) 33 | 34 | test_that("augment.plm", { 35 | check_augment_function( 36 | aug = augment.plm, 37 | model = fit, 38 | data = Produc, 39 | newdata = Produc 40 | ) 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test-polca.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("poLCA") 7 | skip_if_not_installed("MASS") 8 | suppressPackageStartupMessages(library(poLCA)) 9 | 10 | data(values) 11 | fit <- poLCA(cbind(A, B, C, D) ~ 1, values, nclass = 2, verbose = FALSE) 12 | 13 | test_that("poLCA tidier arguments", { 14 | check_arguments(tidy.poLCA) 15 | check_arguments(glance.poLCA) 16 | check_arguments(augment.poLCA) 17 | }) 18 | 19 | test_that("tidy.poLCA", { 20 | td <- tidy(fit) 21 | check_tidy_output(td) 22 | check_dims(td, 16, 5) 23 | }) 24 | 25 | test_that("glance.poLCA", { 26 | gl <- glance(fit) 27 | check_glance_outputs(gl) 28 | check_dims(gl, expected_cols = 8) 29 | }) 30 | 31 | test_that("augment.poLCA", { 32 | au <- augment(fit) 33 | 34 | check_augment_function( 35 | aug = augment.poLCA, 36 | model = fit, 37 | data = values, 38 | newdata = values, 39 | strict = FALSE 40 | ) 41 | }) 42 | -------------------------------------------------------------------------------- /tests/testthat/test-psych.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("psych") 7 | 8 | test_that("tidy.kappa works", { 9 | check_arguments(tidy.kappa) 10 | 11 | # breaks on R 3.4 is df is a tibble 12 | df <- cbind( 13 | rater1 = 1:9, 14 | rater2 = c(1, 3, 1, 6, 1, 5, 5, 6, 7) 15 | ) 16 | 17 | fit <- psych::cohen.kappa(df) 18 | 19 | td <- tidy(fit) 20 | check_tidy_output(td) 21 | check_dims(td, 2, 4) 22 | }) 23 | -------------------------------------------------------------------------------- /tests/testthat/test-quantreg-nlrq.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("quantreg") 7 | suppressPackageStartupMessages(library(quantreg)) 8 | 9 | set.seed(27) 10 | 11 | df <- tibble::tibble( 12 | x = rep(1:25, 20), 13 | y = SSlogis(x, 10, 12, 2) * rnorm(500, 1, 0.1) 14 | ) 15 | 16 | fit <- nlrq( 17 | y ~ SSlogis(x, Asym, mid, scal), 18 | data = df, 19 | tau = 0.5, 20 | trace = FALSE 21 | ) 22 | 23 | test_that("quantreg::nlrq tidier arguments", { 24 | check_arguments(tidy.nlrq) 25 | check_arguments(glance.nlrq) 26 | check_arguments(augment.nlrq) 27 | }) 28 | 29 | test_that("tidy.nlrq", { 30 | td <- tidy(fit) 31 | td_iid <- tidy(fit, se.type = "iid") 32 | tdci <- tidy(fit, conf.int = TRUE) 33 | 34 | check_tidy_output(td) 35 | check_tidy_output(td_iid) 36 | check_tidy_output(tdci) 37 | }) 38 | 39 | test_that("glance.nlrq", { 40 | gl <- glance(fit) 41 | check_glance_outputs(gl) 42 | }) 43 | 44 | test_that("augment.nlrq", { 45 | au <- augment(fit) 46 | check_tibble(au, method = "augment", strict = FALSE) 47 | 48 | check_augment_function( 49 | aug = augment.nlrq, 50 | model = fit, 51 | data = df, 52 | newdata = df 53 | ) 54 | }) 55 | -------------------------------------------------------------------------------- /tests/testthat/test-quantreg-rq.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("quantreg") 7 | suppressPackageStartupMessages(library(quantreg)) 8 | 9 | data(stackloss) 10 | 11 | df <- as_tibble(stack.x) |> 12 | mutate(stack.loss = stack.loss) 13 | 14 | dflarge_n <- df |> slice(rep(row_number(), 500)) 15 | 16 | fit <- rq(stack.loss ~ ., data = df, tau = .5) 17 | fit2 <- rq(stack.loss ~ 1, data = df, tau = .5) 18 | fitlarge_n <- rq(stack.loss ~ ., data = dflarge_n, tau = .5) 19 | 20 | test_that("quantreg::rq tidier arguments", { 21 | check_arguments(tidy.rq) 22 | check_arguments(glance.rq) 23 | check_arguments(augment.rq) 24 | }) 25 | 26 | test_that("tidy.rq", { 27 | td <- tidy(fit) 28 | td2 <- tidy(fit2) 29 | tdlarge_n <- tidy(fitlarge_n) 30 | td_iid <- tidy(fit, conf.int = TRUE, se.type = "iid") 31 | 32 | check_tidy_output(td) 33 | check_tidy_output(td2) 34 | check_tidy_output(tdlarge_n) 35 | check_tidy_output(td_iid) 36 | 37 | check_dims(td, 4, 5) 38 | check_dims(td2, 1, 5) 39 | check_dims(tdlarge_n, 4, 6) 40 | check_dims(td_iid, 4, 8) 41 | }) 42 | 43 | test_that("glance.rq", { 44 | gl <- glance(fit) 45 | gl2 <- glance(fit2) 46 | check_glance_outputs(gl, gl2) 47 | }) 48 | 49 | test_that("augment.rq", { 50 | au <- augment(fit, interval = "confidence") 51 | check_tibble(au, method = "augment", strict = FALSE) 52 | check_dims(au, 21, 9) 53 | 54 | check_augment_function( 55 | aug = augment.rq, 56 | model = fit, 57 | data = df, 58 | newdata = df, 59 | strict = FALSE 60 | ) 61 | 62 | check_augment_function( 63 | aug = augment.rq, 64 | model = fit2, 65 | data = df, 66 | newdata = df, 67 | strict = FALSE 68 | ) 69 | }) 70 | -------------------------------------------------------------------------------- /tests/testthat/test-quantreg-rqs.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("quantreg") 7 | suppressPackageStartupMessages(library(quantreg)) 8 | 9 | airquality <- na.omit(airquality) 10 | 11 | fit <- rq(Ozone ~ ., data = airquality, tau = 1:19 / 20) 12 | fit2 <- rq(Ozone ~ Temp - 1, data = airquality, tau = 1:19 / 20) 13 | 14 | test_that("quantreg::rqs tidier arguments", { 15 | check_arguments(tidy.rqs) 16 | # glance.rqs only exists for informative error 17 | check_arguments(augment.rqs, strict = FALSE) 18 | }) 19 | 20 | test_that("tidy.rqs", { 21 | td <- tidy(fit) 22 | td2 <- tidy(fit2) 23 | td_iid <- tidy(fit, se.type = "iid") 24 | 25 | check_tidy_output(td) 26 | check_tidy_output(td2) 27 | check_tidy_output(td_iid) 28 | }) 29 | 30 | test_that("glance.rqs", { 31 | expect_snapshot(error = TRUE, glance(fit)) 32 | }) 33 | 34 | test_that("augment.rqs", { 35 | check_augment_function( 36 | aug = augment.rqs, 37 | model = fit, 38 | data = airquality, 39 | newdata = airquality, 40 | strict = FALSE 41 | ) 42 | 43 | check_augment_function( 44 | aug = augment.rqs, 45 | model = fit2, 46 | data = airquality, 47 | newdata = airquality, 48 | strict = FALSE 49 | ) 50 | }) 51 | -------------------------------------------------------------------------------- /tests/testthat/test-robust-glmrob.R: -------------------------------------------------------------------------------- 1 | test_that("augment.glmRob errors informatively", { 2 | x <- structure(1L, class = "glmRob") 3 | expect_snapshot(error = TRUE, augment(x)) 4 | }) 5 | -------------------------------------------------------------------------------- /tests/testthat/test-robust.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("robust") 7 | suppressPackageStartupMessages(library(robust)) 8 | 9 | fit <- lmRob(mpg ~ wt, data = mtcars) 10 | fit2 <- glmRob(am ~ wt, data = mtcars, family = "binomial") 11 | 12 | test_that("robust tidier arguments", { 13 | check_arguments(tidy.lmRob) 14 | check_arguments(glance.lmRob) 15 | check_arguments(augment.lmRob) 16 | 17 | check_arguments(tidy.glmRob) 18 | check_arguments(glance.glmRob) 19 | }) 20 | 21 | test_that("tidy.lmRob", { 22 | td <- tidy(fit) 23 | td2 <- tidy(fit, conf.int = TRUE) 24 | 25 | check_tidy_output(td) 26 | check_tidy_output(td2) 27 | }) 28 | 29 | test_that("glance.lmRob", { 30 | gl <- glance(fit) 31 | check_glance_outputs(gl) 32 | }) 33 | 34 | test_that("augment.lmRob", { 35 | check_augment_function( 36 | aug = augment.lmRob, 37 | model = fit, 38 | data = mtcars, 39 | newdata = mtcars 40 | ) 41 | }) 42 | 43 | test_that("tidy.glmRob", { 44 | td <- tidy(fit2) 45 | td2 <- tidy(fit2) 46 | 47 | check_tidy_output(td) 48 | check_tidy_output(td2) 49 | }) 50 | 51 | test_that("glance.glmRob", { 52 | gl <- glance(fit2) 53 | check_glance_outputs(gl) 54 | }) 55 | 56 | test_that("no more rlang issues with model objects from robust", { 57 | # from issue 720 58 | 59 | expect_equal( 60 | tidy(fit, conf.int = TRUE), 61 | tidy(fit) 62 | ) 63 | 64 | expect_equal( 65 | tidy(fit, exponentiate = TRUE), 66 | tidy(fit) 67 | ) 68 | 69 | expect_equal( 70 | tidy(fit2, conf.int = TRUE), 71 | tidy(fit2) 72 | ) 73 | 74 | expect_equal( 75 | tidy(fit2, exponentiate = TRUE), 76 | tidy(fit2) 77 | ) 78 | }) 79 | -------------------------------------------------------------------------------- /tests/testthat/test-robustbase.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("robustbase") 7 | suppressPackageStartupMessages(library(robustbase)) 8 | 9 | fit <- lmrob(mpg ~ wt, data = mtcars) 10 | fit2 <- glmrob(am ~ wt, data = mtcars, family = "binomial") 11 | 12 | clotting <- data.frame( 13 | u = c(5, 10, 15, 20, 30, 40, 60, 80, 100), 14 | lot1 = c(118, 58, 42, 35, 27, 25, 21, 19, 18), 15 | lot2 = c(69, 35, 26, 21, 18, 16, 13, 12, 12) 16 | ) 17 | 18 | fit_rd <- robustbase::glmrob( 19 | formula = lot1 ~ log(u), 20 | data = clotting, 21 | family = Gamma 22 | ) 23 | 24 | test_that("robustbase tidier arguments", { 25 | check_arguments(tidy.lmrob) 26 | check_arguments(glance.lmrob) 27 | check_arguments(augment.lmrob) 28 | 29 | check_arguments(tidy.glmrob) 30 | # check_arguments(glance.glmrob) 31 | check_arguments(augment.glmrob) 32 | }) 33 | 34 | test_that("tidy.lmrob", { 35 | # check tidy.lmrob returns right columns 36 | td <- tidy(fit) 37 | check_tidy_output(td) 38 | # check tidy.lmrob returns confidence intervals for params when requested 39 | td_ci <- tidy(fit, conf.int = TRUE) 40 | check_dims(td_ci, 2, 7) 41 | }) 42 | 43 | test_that("glance.lmrob", { 44 | gl <- glance(fit) 45 | check_glance_outputs(gl) 46 | 47 | suppressWarnings( 48 | gl_rd <- glance(fit_rd) 49 | ) 50 | 51 | check_glance_outputs(gl_rd) 52 | }) 53 | 54 | test_that("augment.lmrob", { 55 | check_augment_function( 56 | aug = augment.lmrob, 57 | model = fit, 58 | data = mtcars, 59 | newdata = mtcars 60 | ) 61 | # check that .se.fit column is included 62 | check_dims(augment(fit, se_fit = TRUE), 32, 6) 63 | }) 64 | 65 | test_that("tidy.glmrob", { 66 | td <- tidy(fit2) 67 | check_tidy_output(td) 68 | td_ci <- tidy(fit2, conf.int = TRUE) 69 | check_dims(td_ci, 2, 7) 70 | }) 71 | 72 | # test_that("glance.glmrob", { 73 | # }) 74 | 75 | test_that("augment.glmrob", { 76 | check_augment_function( 77 | aug = augment.glmrob, 78 | model = fit2, 79 | data = mtcars, 80 | newdata = mtcars 81 | ) 82 | 83 | # check that .se.fit column is included 84 | check_dims(augment(fit2, se_fit = TRUE), 32, 6) 85 | }) 86 | -------------------------------------------------------------------------------- /tests/testthat/test-spdep.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("spdep") 7 | suppressPackageStartupMessages(library(spdep)) 8 | 9 | skip_if_not_installed("spatialreg") 10 | suppressPackageStartupMessages(library(spatialreg)) 11 | 12 | data(oldcol, package = "spdep") 13 | listw <- spdep::nb2listw(COL.nb, style = "W") 14 | 15 | fit_lag <- lagsarlm( 16 | CRIME ~ INC + HOVAL, 17 | data = COL.OLD, 18 | listw = listw, 19 | method = "eigen" 20 | ) 21 | fit_error <- errorsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, listw) 22 | 23 | fit_sac <- sacsarlm(CRIME ~ INC + HOVAL, data = COL.OLD, listw) 24 | 25 | test_that("spdep tidier arguments", { 26 | check_arguments(tidy.sarlm) 27 | check_arguments(glance.sarlm) 28 | check_arguments(augment.sarlm, strict = FALSE) 29 | }) 30 | 31 | test_that("tidy.sarlm", { 32 | td1 <- tidy(fit_lag) 33 | td2 <- tidy(fit_error) 34 | td3 <- tidy(fit_sac) 35 | td4 <- tidy(fit_sac, conf.int = TRUE) 36 | 37 | check_tidy_output(td1) 38 | check_tidy_output(td2) 39 | check_tidy_output(td3) 40 | check_tidy_output(td4) 41 | 42 | check_dims(td1, 4, 5) 43 | check_dims(td2, 4, 5) 44 | check_dims(td3, 5, 5) 45 | check_dims(td4, 5, 7) 46 | }) 47 | 48 | 49 | test_that("glance.sarlm", { 50 | gl1 <- glance(fit_lag) 51 | gl2 <- glance(fit_error) 52 | gl3 <- glance(fit_sac) 53 | 54 | check_glance_outputs(gl1, gl2, gl3) 55 | 56 | check_dims(gl1, 1, 6) 57 | check_dims(gl2, 1, 6) 58 | check_dims(gl3, 1, 6) 59 | }) 60 | 61 | test_that("augment.sarlm", { 62 | check_augment_function( 63 | aug = augment.sarlm, 64 | model = fit_lag, 65 | data = fit_lag$X, 66 | strict = FALSE 67 | ) 68 | }) 69 | -------------------------------------------------------------------------------- /tests/testthat/test-speedglm-speedglm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("speedglm") 7 | suppressPackageStartupMessages(library(speedglm)) 8 | 9 | clotting <- data.frame( 10 | u = c(5, 10, 15, 20, 30, 40, 60, 80, 100), 11 | lot1 = c(118, 58, 42, 35, 27, 25, 21, 19, 18) 12 | ) 13 | 14 | fit <- speedglm(lot1 ~ log(u), data = clotting, family = Gamma(log)) 15 | 16 | test_that("speedglm tidiers arguments", { 17 | check_arguments(tidy.speedglm) 18 | check_arguments(glance.speedglm) 19 | }) 20 | 21 | test_that("tidy.speedglm", { 22 | td <- tidy(fit, conf.int = TRUE, exponentiate = TRUE) 23 | check_tidy_output(td) 24 | 25 | # watch out for the bizarro factor p-values reported in #660 26 | expect_type(td$p.value, "double") 27 | 28 | check_dims(td, 2, 7) 29 | }) 30 | 31 | test_that("glance.speedglm", { 32 | gl <- glance(fit) 33 | check_glance_outputs(gl) 34 | }) 35 | 36 | test_that("augment.speedglm errors", { 37 | # speedglm sub-classes speedlm, and there's an augment.speedlm() 38 | # method we want to make sure isn't accidentally invoked 39 | expect_snapshot(error = TRUE, augment(fit)) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-speedglm-speedlm.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("speedglm") 7 | suppressPackageStartupMessages(library(speedglm)) 8 | 9 | fit <- speedlm(mpg ~ wt, mtcars, fitted = TRUE) 10 | fit2 <- speedlm(mpg ~ wt + disp, mtcars, fitted = TRUE) 11 | fit3 <- speedlm(mpg ~ wt, mtcars) 12 | 13 | test_that("speedlm tidiers arguments", { 14 | check_arguments(tidy.speedlm) 15 | check_arguments(glance.speedlm) 16 | check_arguments(augment.speedlm) 17 | }) 18 | 19 | test_that("tidy.speedlm", { 20 | td <- tidy(fit) 21 | td2 <- tidy(fit2) 22 | 23 | check_tidy_output(td) 24 | check_tidy_output(td2) 25 | 26 | check_dims(td, 2) 27 | check_dims(td2, 3) 28 | 29 | expect_equal(td$term, c("(Intercept)", "wt")) 30 | expect_equal(td2$term, c("(Intercept)", "wt", "disp")) 31 | }) 32 | 33 | test_that("glance.speedlm", { 34 | gl <- glance(fit) 35 | check_glance_outputs(gl) 36 | }) 37 | 38 | test_that("augment.speedlm", { 39 | check_augment_function( 40 | aug = augment.speedlm, 41 | model = fit, 42 | data = mtcars, 43 | newdata = mtcars 44 | ) 45 | 46 | check_augment_function( 47 | aug = augment.speedlm, 48 | model = fit2, 49 | data = mtcars, 50 | newdata = mtcars 51 | ) 52 | 53 | expect_snapshot(error = TRUE, augment(fit3)) 54 | }) 55 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-arima.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | fit1 <- arima(lh, order = c(1, 0, 0)) 7 | 8 | fit2 <- arima( 9 | USAccDeaths, 10 | order = c(0, 1, 1), 11 | seasonal = list(order = c(0, 1, 1)), 12 | method = "CSS" 13 | ) 14 | 15 | test_that("Arima tidier arguments", { 16 | check_arguments(tidy.Arima) 17 | check_arguments(glance.Arima) 18 | }) 19 | 20 | test_that("tidy.Arima", { 21 | td1 <- tidy(fit1, conf.int = TRUE) 22 | force(td1) 23 | check_tidy_output(td1) 24 | check_dims(td1, 2, 5) 25 | 26 | td2 <- tidy(fit2) 27 | check_tidy_output(td2) 28 | check_dims(td2, 2, 3) 29 | }) 30 | 31 | test_that("glance.Arima", { 32 | gl1 <- glance(fit1) 33 | gl2 <- glance(fit2) 34 | 35 | check_glance_outputs(gl1, gl2, strict = FALSE) 36 | }) 37 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-decompose.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | test_that("augment.decomposed.ts", { 7 | check_arguments(augment.decomposed.ts, strict = FALSE) 8 | 9 | d1a <- stats::decompose(nottem, type = "additive") 10 | d1b <- stats::decompose(nottem, type = "multiplicative") 11 | d2 <- stats::stl(nottem, s.window = "periodic", robust = TRUE) 12 | 13 | a1a <- augment(d1a) 14 | a1b <- augment(d1b) 15 | a2 <- augment(d2) 16 | 17 | check_tibble(a1a, method = "augment") 18 | check_tibble(a1b, method = "augment") 19 | check_tibble(a2, method = "augment") 20 | 21 | check_dims(a1a, 240, 4) 22 | check_dims(a1b, 240, 4) 23 | check_dims(a2, 240, 5) 24 | }) 25 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-kmeans.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | set.seed(2) 5 | x <- rbind( 6 | matrix(rnorm(100, sd = 0.3), ncol = 2), 7 | matrix(rnorm(100, mean = 1, sd = 0.3), ncol = 2) 8 | ) 9 | 10 | fit <- kmeans(x, 2) 11 | 12 | d <- data.frame(x = runif(100), y = runif(100)) 13 | fit2 <- kmeans(x = d, centers = 5) 14 | 15 | test_that("kmeans tidier arguments", { 16 | check_arguments(tidy.kmeans) 17 | check_arguments(glance.kmeans) 18 | check_arguments(augment.kmeans, strict = FALSE) 19 | }) 20 | 21 | # tidy.kmeans uses the orginal column names to name columns in output. 22 | # Therefore, strict must be set to FALSE for this test to pass. 23 | test_that("tidy.kmeans", { 24 | td <- tidy(fit) 25 | check_tidy_output(td, strict = FALSE) 26 | }) 27 | 28 | test_that("tidy.kmeans", { 29 | gl <- glance(fit) 30 | check_glance_outputs(gl) 31 | }) 32 | 33 | test_that("augment.kmeans", { 34 | check_augment_function( 35 | aug = augment.kmeans, 36 | model = fit, 37 | data = x, 38 | newdata = x, 39 | strict = FALSE 40 | ) 41 | 42 | check_augment_function( 43 | aug = augment.kmeans, 44 | model = fit2, 45 | data = d, 46 | newdata = d, 47 | strict = FALSE 48 | ) 49 | }) 50 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-loess.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | test_that("augment.loess", { 5 | check_arguments(augment.loess) 6 | 7 | fit <- loess(mpg ~ wt, mtcars) 8 | 9 | check_augment_function( 10 | aug = augment.loess, 11 | model = fit, 12 | data = mtcars, 13 | newdata = mtcars 14 | ) 15 | }) 16 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-nls.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("MASS") 7 | 8 | fit <- nls( 9 | wt ~ a + b * mpg + c / disp, 10 | data = mtcars, 11 | start = list(a = 1, b = 2, c = 3) 12 | ) 13 | 14 | fit2 <- nls(wt ~ b * mpg, data = mtcars, start = list(b = 2)) 15 | 16 | test_that("nls tidier arguments", { 17 | check_arguments(tidy.nls) 18 | check_arguments(glance.nls) 19 | check_arguments(augment.nls) 20 | }) 21 | 22 | test_that("tidy.nls", { 23 | td <- tidy(fit, conf.int = TRUE) 24 | check_tidy_output(td) 25 | check_dims(td, 3, 7) 26 | 27 | expect_equal(td$term, c("a", "b", "c")) 28 | }) 29 | 30 | test_that("glance.nls", { 31 | gl <- glance(fit) 32 | check_glance_outputs(gl) 33 | check_dims(gl, expected_cols = 9) 34 | }) 35 | 36 | test_that("augment.nls", { 37 | check_augment_function( 38 | aug = augment.nls, 39 | model = fit, 40 | data = mtcars, 41 | newdata = mtcars 42 | ) 43 | 44 | check_augment_function( 45 | aug = augment.nls, 46 | model = fit2, 47 | data = mtcars, 48 | newdata = mtcars 49 | ) 50 | }) 51 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-smooth.spline.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | fit <- smooth.spline(mtcars$wt, mtcars$mpg) 5 | 6 | test_that("smooth.spline tidier arguments", { 7 | check_arguments(glance.smooth.spline) 8 | check_arguments(augment.smooth.spline) 9 | }) 10 | 11 | test_that("glance.smooth.spline", { 12 | gl <- glance(fit) 13 | check_glance_outputs(gl) 14 | }) 15 | 16 | test_that("augment.smooth.spline", { 17 | check_augment_function( 18 | aug = augment.smooth.spline, 19 | model = fit, 20 | data = mtcars, 21 | strict = FALSE 22 | ) 23 | }) 24 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-summary-lm.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | test_that("summary.lm tidier arguments", { 5 | check_arguments(tidy.summary.lm) 6 | check_arguments(glance.summary.lm) 7 | }) 8 | 9 | fit <- lm(mpg ~ wt, mtcars) 10 | fit_summ <- summary(fit) 11 | 12 | fit2 <- lm(mpg ~ wt + log(disp), mtcars) 13 | fit2_summ <- summary(fit2) 14 | 15 | test_that("tidy.summary.lm works", { 16 | td <- tidy(fit) 17 | std <- tidy(fit_summ) 18 | td2 <- tidy(fit2, conf.int = TRUE) 19 | std2 <- tidy(fit2_summ, conf.int = TRUE) 20 | 21 | check_tidy_output(std) 22 | check_tidy_output(std2) 23 | 24 | expect_equal(td, std) 25 | expect_equal(td2, std2) 26 | }) 27 | 28 | test_that("glance.summary.lm", { 29 | gl <- glance(fit) 30 | gl2 <- glance(fit2) 31 | sgl <- glance(fit_summ) 32 | sgl2 <- glance(fit2_summ) 33 | 34 | check_glance_outputs(sgl, sgl2) 35 | 36 | expect_equal( 37 | dplyr::select(gl, -c("logLik", "AIC", "BIC", "deviance")), 38 | sgl 39 | ) 40 | expect_equal( 41 | dplyr::select(gl2, -c("logLik", "AIC", "BIC", "deviance")), 42 | sgl2 43 | ) 44 | }) 45 | -------------------------------------------------------------------------------- /tests/testthat/test-stats-time-series.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | library(modeltests) 3 | 4 | test_that("tidy.acf works", { 5 | check_arguments(tidy.acf) 6 | 7 | result <- acf(lh, plot = FALSE) 8 | td <- tidy(result) 9 | check_tidy_output(td) 10 | check_dims(td, 17, 2) 11 | }) 12 | 13 | 14 | test_that("tidy.ts", { 15 | check_arguments(tidy.ts) 16 | 17 | x <- ts(1:10, frequency = 4, start = c(1959, 2)) 18 | td <- tidy(x) 19 | check_tidy_output(td) 20 | 21 | z <- ts(matrix(rnorm(300), 100, 3), start = c(1961, 1), frequency = 12) 22 | td2 <- tidy(z) 23 | check_tidy_output(td2) 24 | }) 25 | 26 | 27 | test_that("tidy.spec", { 28 | check_arguments(tidy.spec) 29 | 30 | spc <- spectrum(lh, plot = FALSE) 31 | td <- tidy(spc) 32 | 33 | check_tidy_output(td, strict = FALSE) 34 | check_dims(td, 24, 2) 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test-survey.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survey") 7 | suppressPackageStartupMessages(library(survey)) 8 | 9 | skip_if_not_installed("MASS") 10 | 11 | data("housing", package = "MASS") 12 | design <- svydesign(ids = ~1, weights = ~Freq, data = housing) 13 | fit <- svyolr(Sat ~ Infl + Type + Cont, design = design) 14 | 15 | data("api", package = "survey") 16 | dstrat <- svydesign( 17 | id = ~1, 18 | strata = ~stype, 19 | weights = ~pw, 20 | data = apistrat, 21 | fpc = ~fpc 22 | ) 23 | fit_svyglm <- svyglm( 24 | formula = sch.wide ~ ell + meals + mobility, 25 | design = dstrat, 26 | family = quasibinomial() 27 | ) 28 | 29 | 30 | test_that("survey tidier arguments", { 31 | # check_arguments(tidy.svyolr) 32 | check_arguments(glance.svyolr) 33 | }) 34 | 35 | test_that("tidy.svyolr", { 36 | td2 <- tidy(fit, conf.int = TRUE, exponentiate = TRUE) 37 | check_tidy_output(td2) 38 | }) 39 | 40 | test_that("glance.svyolr", { 41 | gl <- glance(fit) 42 | check_glance_outputs(gl) 43 | check_dims(gl, 1, 3) 44 | }) 45 | 46 | test_that("glance.svyglm: make sure `nobs` is there", { 47 | gl <- glance(fit_svyglm) 48 | check_glance_outputs(gl) 49 | check_dims(gl, 1, 7) 50 | expect_true("nobs" %in% colnames(glance(fit_svyglm))) 51 | }) 52 | 53 | test_that("conf.int merging regression test (#804)", { 54 | expect_no_error(tidy(fit_svyglm, conf.int = TRUE)) 55 | }) 56 | -------------------------------------------------------------------------------- /tests/testthat/test-survival-aareg.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survival") 7 | suppressPackageStartupMessages(library(survival)) 8 | 9 | afit1 <- aareg( 10 | Surv(time, status) ~ age + sex + ph.ecog, 11 | data = lung, 12 | dfbeta = FALSE 13 | ) 14 | 15 | afit2 <- aareg( 16 | Surv(time, status) ~ age + sex + ph.ecog, 17 | data = lung, 18 | dfbeta = TRUE 19 | ) 20 | 21 | test_that("aareg tidier arguments", { 22 | check_arguments(tidy.aareg) 23 | check_arguments(glance.aareg) 24 | }) 25 | 26 | test_that("tidy.aareg", { 27 | td <- tidy(afit1) 28 | td2 <- tidy(afit2) 29 | 30 | check_tidy_output(td, strict = FALSE) 31 | check_tidy_output(td2, strict = FALSE) 32 | 33 | check_dims(td, 4, 6) 34 | check_dims(td2, 4, 7) 35 | 36 | expect_equal(td$term, c("Intercept", "age", "sex", "ph.ecog")) 37 | expect_equal(td2$term, c("Intercept", "age", "sex", "ph.ecog")) 38 | }) 39 | 40 | test_that("glance.aareg", { 41 | gl <- glance(afit1) 42 | gl2 <- glance(afit2) 43 | 44 | check_glance_outputs(gl, gl2) 45 | }) 46 | -------------------------------------------------------------------------------- /tests/testthat/test-survival-cch.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survival") 7 | suppressPackageStartupMessages(library(survival)) 8 | 9 | subcoh <- nwtco$in.subcohort 10 | selccoh <- with(nwtco, rel == 1 | subcoh == 1) 11 | ccoh.data <- nwtco[selccoh, ] 12 | ccoh.data$subcohort <- subcoh[selccoh] 13 | ccoh.data$histol <- factor(ccoh.data$histol, labels = c("FH", "UH")) 14 | ccoh.data$stage <- 15 | factor(ccoh.data$stage, labels = c("I", "II", "III", "IV")) 16 | ccoh.data$age <- ccoh.data$age / 12 17 | 18 | fit <- cch( 19 | Surv(edrel, rel) ~ stage + histol + age, 20 | data = ccoh.data, 21 | subcoh = ~subcohort, 22 | id = ~seqno, 23 | cohort.size = 4028 24 | ) 25 | 26 | test_that("cch tidier arguments", { 27 | check_arguments(tidy.cch, strict = FALSE) 28 | check_arguments(glance.cch) 29 | }) 30 | 31 | test_that("tidy.cch", { 32 | td <- tidy(fit) 33 | check_tidy_output(td) 34 | }) 35 | 36 | test_that("glance.cch", { 37 | gl <- glance(fit) 38 | check_glance_outputs(gl) 39 | }) 40 | -------------------------------------------------------------------------------- /tests/testthat/test-survival-pyears.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survival") 7 | suppressPackageStartupMessages(library(survival)) 8 | 9 | temp.yr <- tcut(mgus$dxyr, 55:92, labels = as.character(55:91)) 10 | temp.age <- tcut(mgus$age, 34:101, labels = as.character(34:100)) 11 | ptime <- ifelse(is.na(mgus$pctime), mgus$futime, mgus$pctime) 12 | pstat <- ifelse(is.na(mgus$pctime), 0, 1) 13 | 14 | fit <- pyears( 15 | Surv(ptime / 365.25, pstat) ~ temp.yr + temp.age + sex, 16 | mgus, 17 | data.frame = TRUE 18 | ) 19 | 20 | fit2 <- pyears( 21 | Surv(ptime / 365.25, pstat) ~ temp.yr + temp.age + sex, 22 | mgus, 23 | data.frame = FALSE 24 | ) 25 | 26 | test_that("pyears tidier arguments", { 27 | check_arguments(tidy.pyears) 28 | check_arguments(glance.pyears) 29 | }) 30 | 31 | test_that("tidy.pyears", { 32 | td <- tidy(fit) 33 | td2 <- tidy(fit2) 34 | 35 | check_tidy_output(td, strict = FALSE) 36 | check_tidy_output(td2, strict = FALSE) 37 | }) 38 | 39 | test_that("glance.pyears", { 40 | gl <- glance(fit) 41 | gl2 <- glance(fit2) 42 | 43 | check_glance_outputs(gl, gl2) 44 | }) 45 | -------------------------------------------------------------------------------- /tests/testthat/test-survival-survdiff.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survival") 7 | suppressPackageStartupMessages(library(survival)) 8 | 9 | fit <- survdiff(Surv(futime, fustat) ~ rx, data = ovarian) 10 | fit2 <- survdiff(Surv(time, status) ~ pat.karno + strata(inst), data = lung) 11 | fit3 <- survdiff( 12 | Surv(time, status) ~ pat.karno + ph.ecog + strata(inst) + strata(sex), 13 | data = lung 14 | ) 15 | 16 | expect <- survexp( 17 | futime ~ 1, 18 | rmap = list( 19 | age = (accept.dt - birth.dt), 20 | sex = 1, 21 | year = accept.dt, 22 | race = "white" 23 | ), 24 | jasa, 25 | cohort = FALSE, 26 | ratetable = survexp.usr 27 | ) 28 | 29 | fit4 <- survdiff(Surv(jasa$futime, jasa$fustat) ~ offset(expect)) 30 | fit5 <- survdiff(Surv(futime, fustat) ~ rx + ecog.ps, data = ovarian) 31 | rm(expect) 32 | 33 | test_that("survdiff tidier arguments", { 34 | check_arguments(tidy.survdiff) 35 | check_arguments(glance.survdiff) 36 | }) 37 | 38 | test_that("tidy.survdiff", { 39 | td <- tidy(fit) 40 | td2 <- tidy(fit2) 41 | td3 <- tidy(fit3) 42 | td4 <- tidy(fit4) 43 | td5 <- tidy(fit5) 44 | 45 | # The output from tidy.survdiff uses variable names as column names because 46 | # the output contains a row for each level of the (statistical) factor. This 47 | # output meets the criteria for 'tidy' data. Therefore, strict may be 48 | # set to FALSE to allow these tests to pass. 49 | check_tidy_output(td, strict = FALSE) 50 | check_tidy_output(td2, strict = FALSE) 51 | check_tidy_output(td3, strict = FALSE) 52 | check_tidy_output(td4) 53 | check_tidy_output(td5, strict = FALSE) 54 | }) 55 | 56 | test_that("glance.survdiff", { 57 | gl <- glance(fit) 58 | gl2 <- glance(fit2) 59 | gl3 <- glance(fit3) 60 | gl4 <- glance(fit4) 61 | gl5 <- glance(fit5) 62 | 63 | check_glance_outputs(gl, gl2, gl3, gl4, gl5) 64 | }) 65 | -------------------------------------------------------------------------------- /tests/testthat/test-survival-survexp.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survival") 7 | suppressPackageStartupMessages(library(survival)) 8 | 9 | fit <- suppressWarnings( 10 | survexp( 11 | futime ~ 1, 12 | rmap = list( 13 | sex = "male", 14 | year = accept.dt, 15 | age = accept.dt - birth.dt 16 | ), 17 | method = "conditional", 18 | data = jasa 19 | ) 20 | ) 21 | 22 | test_that("survfit tidier arguments", { 23 | check_arguments(tidy.survexp) 24 | check_arguments(glance.survexp) 25 | }) 26 | 27 | test_that("tidy.survexp", { 28 | td <- tidy(fit) 29 | check_tidy_output(td) 30 | }) 31 | 32 | test_that("glance.survexp", { 33 | gl <- glance(fit) 34 | check_glance_outputs(gl) 35 | }) 36 | -------------------------------------------------------------------------------- /tests/testthat/test-survival-survfit.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survival") 7 | suppressPackageStartupMessages(library(survival)) 8 | 9 | cfit <- coxph(Surv(time, status) ~ age + strata(sex), lung) 10 | sfit <- survfit(cfit) 11 | 12 | cfit2 <- coxph(Surv(time, status) ~ age, lung) 13 | sfit2 <- survfit(cfit2) 14 | 15 | fit2 <- survfit( 16 | Surv(stop, status * as.numeric(event), type = "mstate") ~ 1, 17 | data = mgus1, 18 | subset = (start == 0) 19 | ) 20 | 21 | test_that("survfit tidier arguments", { 22 | check_arguments(tidy.survfit) 23 | check_arguments(glance.survfit) 24 | }) 25 | 26 | test_that("tidy.survfit", { 27 | td <- tidy(sfit) 28 | td2 <- tidy(fit2) 29 | 30 | check_tidy_output(td) 31 | check_tidy_output(td2) 32 | }) 33 | 34 | test_that("glance.survfit", { 35 | expect_snapshot(error = TRUE, glance(sfit)) 36 | expect_snapshot(error = TRUE, glance(fit2)) 37 | 38 | gl <- glance(sfit2) 39 | check_glance_outputs(gl) 40 | }) 41 | -------------------------------------------------------------------------------- /tests/testthat/test-survival-survreg.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("survival") 7 | suppressPackageStartupMessages(library(survival)) 8 | 9 | sr <- survreg( 10 | Surv(futime, fustat) ~ ecog.ps + rx, 11 | ovarian, 12 | dist = "exponential" 13 | ) 14 | 15 | test_that("survreg tidier arguments", { 16 | check_arguments(tidy.survreg) 17 | check_arguments(glance.survreg) 18 | check_arguments(augment.survreg) 19 | }) 20 | 21 | test_that("tidy.survreg", { 22 | td <- tidy(sr) 23 | td2 <- tidy(sr, conf.int = TRUE) 24 | 25 | check_tidy_output(td) 26 | check_tidy_output(td2) 27 | 28 | check_dims(td, 3, 5) 29 | check_dims(td2, 3, 7) 30 | 31 | expect_equal(td$term, c("(Intercept)", "ecog.ps", "rx")) 32 | expect_equal(td2$term, c("(Intercept)", "ecog.ps", "rx")) 33 | }) 34 | 35 | test_that("glance.survreg", { 36 | gl <- glance(sr) 37 | check_glance_outputs(gl) 38 | }) 39 | 40 | test_that("augment.survreg", { 41 | check_augment_function( 42 | aug = augment.survreg, 43 | model = sr, 44 | data = ovarian, 45 | newdata = ovarian 46 | ) 47 | }) 48 | 49 | test_that("tidy.survreg with robust std err", { 50 | sr <- survreg( 51 | Surv(futime, fustat) ~ ecog.ps + rx, 52 | ovarian, 53 | dist = "exponential", 54 | robust = TRUE 55 | ) 56 | td <- tidy(sr) 57 | td2 <- tidy(sr, conf.int = TRUE) 58 | 59 | check_tidy_output(td) 60 | check_tidy_output(td2) 61 | 62 | check_dims(td, 3, 5) 63 | check_dims(td2, 3, 7) 64 | }) 65 | -------------------------------------------------------------------------------- /tests/testthat/test-tseries.R: -------------------------------------------------------------------------------- 1 | skip_if_not_installed("modeltests") 2 | suppressPackageStartupMessages(library(modeltests)) 3 | 4 | suppressMessages(skip_if_not_installed("tseries")) 5 | suppressPackageStartupMessages(library(tseries)) 6 | 7 | dax <- diff(log(EuStockMarkets))[, "DAX"] 8 | fit <- garch(dax, control = garch.control(trace = FALSE)) 9 | 10 | test_that("tseries tidier arguments", { 11 | check_arguments(tidy.garch) 12 | check_arguments(glance.garch) 13 | }) 14 | 15 | test_that("tidy.garch", { 16 | td <- tidy(fit) 17 | check_tidy_output(td) 18 | check_dims(td, 3) 19 | 20 | td <- tidy(fit, conf.int = TRUE, conf.level = .99) 21 | check_tidy_output(td) 22 | check_dims(td, 3, 7) 23 | }) 24 | 25 | test_that("glance.garch", { 26 | gl <- glance(fit) 27 | check_glance_outputs(gl) 28 | check_dims(gl, 1, 8) 29 | }) 30 | -------------------------------------------------------------------------------- /tests/testthat/test-vars.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | skip_if_not_installed("modeltests") 3 | skip_if_not_installed("vars") 4 | 5 | suppressPackageStartupMessages(library(vars)) 6 | library(modeltests) 7 | 8 | data("Canada", package = "vars") 9 | fit <- VAR(Canada, p = 1, type = "both") 10 | 11 | test_that("vars tidier arguments", { 12 | check_arguments(tidy.varest) 13 | check_arguments(glance.varest) 14 | }) 15 | 16 | test_that("tidy.vars", { 17 | td <- tidy(fit) 18 | check_tidy_output(td) 19 | check_dims(td, 24, 6) 20 | # vars does not produce confidence intervals 21 | expect_snapshot(.res <- tidy(fit, conf.int = TRUE)) 22 | }) 23 | 24 | 25 | test_that("glance.vars", { 26 | gl <- glance(fit) 27 | check_glance_outputs(gl) 28 | }) 29 | -------------------------------------------------------------------------------- /tests/testthat/test-zoo.R: -------------------------------------------------------------------------------- 1 | skip_on_cran() 2 | 3 | skip_if_not_installed("modeltests") 4 | library(modeltests) 5 | 6 | skip_if_not_installed("zoo") 7 | 8 | test_that("tidy.zoo", { 9 | set.seed(1071) 10 | z.index <- zoo::as.Date(sample(12450:12500, 10)) 11 | z.data <- matrix(rnorm(30), ncol = 3) 12 | 13 | colnames(z.data) <- c("Aa", "Bb", "Cc") 14 | z <- zoo::zoo(z.data, z.index) 15 | 16 | check_arguments(tidy.zoo) 17 | 18 | td <- tidy(z) 19 | check_tidy_output(td) 20 | check_dims(td, 30, 3) 21 | 22 | colnames(z.data) <- c("Not dataframe", "(compatible", "names -") 23 | z <- zoo::zoo(z.data, z.index) 24 | td <- tidy(z) 25 | expect_true(all(unique(td$series) %in% colnames(z.data))) 26 | 27 | # test for univariate functionality 28 | z2 <- zoo::zoo(rnorm(30), z.index) 29 | td2 <- tidy(z2) 30 | 31 | check_tidy_output(td2) 32 | check_dims(td2, 10, 2) 33 | }) 34 | -------------------------------------------------------------------------------- /vignettes/.gitignore: -------------------------------------------------------------------------------- 1 | *.html 2 | *.R 3 | -------------------------------------------------------------------------------- /vignettes/adding-tidiers.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Writing new tidier methods" 3 | date: "`r Sys.Date()`" 4 | output: rmarkdown::html_vignette 5 | vignette: > 6 | %\VignetteIndexEntry{Writing new tidier methods} 7 | %\VignetteEngine{knitr::rmarkdown} 8 | %\VignetteEncoding{UTF-8} 9 | --- 10 | 11 | After the release of broom version 1.0.0, the broom dev team now asks that 12 | attempts to add tidier methods supporting a model object are 13 | directed to the model-owning package. An article describing best practices 14 | in doing so can be found on the {tidymodels} website at 15 | https://www.tidymodels.org/learn/develop/broom/, and we will continue 16 | adding additional resources to that article as we develop them. Some additional 17 | packages that supply themed tidiers are: 18 | 19 | - Mixed model tidiers belong in [`broom.mixed`](https://github.com/bbolker/broom.mixed) 20 | - Natural language related tidiers belong in [`tidytext`](https://github.com/juliasilge/tidytext) 21 | - Tree tidiers belong in [`broomstick`](https://github.com/njtierney/broomstick) 22 | - Tidiers for objects from BioConductor belong in [`biobroom`](https://bioconductor.org/packages/release/bioc/html/biobroom.html) 23 | 24 | To aid in the process of writing new tidiers, we have provided 25 | [learning resources](https://www.tidymodels.org/learn/develop/broom/) as well 26 | as lightweight dependencies to re-export tidier generics on the {tidymodels} 27 | website. 28 | -------------------------------------------------------------------------------- /vignettes/available-methods.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Available methods" 3 | date: "`r Sys.Date()`" 4 | output: rmarkdown::html_vignette 5 | vignette: > 6 | %\VignetteIndexEntry{Available methods} 7 | %\VignetteEngine{knitr::rmarkdown} 8 | %\VignetteEncoding{UTF-8} 9 | --- 10 | 11 | ```{r} 12 | #| label: setup 13 | #| include: false 14 | knitr::opts_chunk$set( 15 | collapse = TRUE, 16 | comment = "#>" 17 | ) 18 | ``` 19 | 20 | The following methods are currently available in `broom`: 21 | 22 | 23 | ```{R} 24 | #| echo: false 25 | #| message: false 26 | library(broom) 27 | library(dplyr) 28 | library(stringr) 29 | 30 | method_df <- function(method_name) { 31 | m <- as.vector(methods(method_name)) 32 | tibble::tibble( 33 | class = str_remove(m, str_c(method_name, "[.]")), 34 | !!method_name := "x" 35 | ) 36 | } 37 | 38 | method_df("tidy") |> 39 | left_join(method_df("glance")) |> 40 | left_join(method_df("augment")) |> 41 | mutate_all(tidyr::replace_na, "") |> 42 | knitr::kable() 43 | ``` 44 | -------------------------------------------------------------------------------- /vignettes/bootstrapping.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Tidy bootstrapping" 3 | date: "`r Sys.Date()`" 4 | output: rmarkdown::html_vignette 5 | vignette: > 6 | %\VignetteIndexEntry{Tidy bootstrapping} 7 | %\VignetteEngine{knitr::rmarkdown} 8 | %\VignetteEncoding{UTF-8} 9 | --- 10 | 11 | ```{r} 12 | #| label: setup 13 | #| include: false 14 | knitr::opts_chunk$set( 15 | collapse = TRUE, 16 | comment = "#>", 17 | message = FALSE 18 | ) 19 | ``` 20 | 21 | # Tidy bootstrapping 22 | 23 | This vignette is now an [article](https://www.tidymodels.org/learn/statistics/bootstrap/) on the {tidymodels} website. 24 | -------------------------------------------------------------------------------- /vignettes/kmeans.Rmd: -------------------------------------------------------------------------------- 1 | --- 2 | title: "kmeans with dplyr and broom" 3 | output: rmarkdown::html_vignette 4 | vignette: > 5 | %\VignetteIndexEntry{kmeans with dplyr and broom} 6 | %\VignetteEngine{knitr::rmarkdown} 7 | %\VignetteEncoding{UTF-8} 8 | --- 9 | 10 | # Tidying k-means clustering 11 | 12 | This vignette is now an [article](https://www.tidymodels.org/learn/statistics/k-means/) on the {tidymodels} website. 13 | --------------------------------------------------------------------------------