diff --git a/.Rbuildignore b/.Rbuildignore index e51e0195..7bcd5335 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -13,3 +13,4 @@ ^hex_blorr\.png$ ^cran-comments\.md$ ^\.github$ +^Meta$ diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index b0f3cd6b..3cdf68c8 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,16 +1,14 @@ -# For help debugging build failures open an issue on the RStudio community with the 'github-actions' tag. -# https://community.rstudio.com/new-topic?category=Package%20development&tags=github-actions +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: - - master - - develop + branches: [master, develop] pull_request: - branches: - - master - - develop + branches: [master, develop] -name: R-CMD-check +name: R-CMD-check.yaml + +permissions: read-all jobs: R-CMD-check: @@ -22,63 +20,33 @@ jobs: fail-fast: false matrix: config: + - {os: macos-latest, r: 'release'} - {os: windows-latest, r: 'release'} - - {os: macOS-latest, r: 'release'} - - {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} - - {os: ubuntu-20.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"} + - {os: ubuntu-latest, r: 'devel', http-user-agent: 'release'} + - {os: ubuntu-latest, r: 'release'} + - {os: ubuntu-latest, r: 'oldrel-1'} env: - R_REMOTES_NO_ERRORS_FROM_WARNINGS: true - RSPM: ${{ matrix.config.rspm }} GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + R_KEEP_PKG_SOURCE: yes steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 + + - uses: r-lib/actions/setup-pandoc@v2 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 with: r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} + use-public-rspm: true - - uses: r-lib/actions/setup-pandoc@v1 - - - name: Query dependencies - run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") - shell: Rscript {0} - - - name: Cache R packages - if: runner.os != 'Windows' - uses: actions/cache@v2 + - uses: r-lib/actions/setup-r-dependencies@v2 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install system dependencies - if: runner.os == 'Linux' - run: | - while read -r cmd - do - eval sudo $cmd - done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))') - - - name: Install dependencies - run: | - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("rcmdcheck") - shell: Rscript {0} - - - name: Check - env: - _R_CHECK_CRAN_INCOMING_REMOTE_: false - run: rcmdcheck::rcmdcheck(args = c("--no-manual", "--as-cran"), error_on = "warning", check_dir = "check") - shell: Rscript {0} + extra-packages: any::rcmdcheck + needs: check - - name: Upload check results - if: failure() - uses: actions/upload-artifact@main + - uses: r-lib/actions/check-r-package@v2 with: - name: ${{ runner.os }}-r${{ matrix.config.r }}-results - path: check + upload-snapshots: true + build_args: 'c("--no-manual","--compact-vignettes=gs+qpdf")' diff --git a/.github/workflows/rhub.yaml b/.github/workflows/rhub.yaml new file mode 100644 index 00000000..74ec7b05 --- /dev/null +++ b/.github/workflows/rhub.yaml @@ -0,0 +1,95 @@ +# R-hub's generic GitHub Actions workflow file. It's canonical location is at +# https://github.com/r-hub/actions/blob/v1/workflows/rhub.yaml +# You can update this file to a newer version using the rhub2 package: +# +# rhub::rhub_setup() +# +# It is unlikely that you need to modify this file manually. + +name: R-hub +run-name: "${{ github.event.inputs.id }}: ${{ github.event.inputs.name || format('Manually run by {0}', github.triggering_actor) }}" + +on: + workflow_dispatch: + inputs: + config: + description: 'A comma separated list of R-hub platforms to use.' + type: string + default: 'linux,windows,macos' + name: + description: 'Run name. You can leave this empty now.' + type: string + id: + description: 'Unique ID. You can leave this empty now.' + type: string + +jobs: + + setup: + runs-on: ubuntu-latest + outputs: + containers: ${{ steps.rhub-setup.outputs.containers }} + platforms: ${{ steps.rhub-setup.outputs.platforms }} + + steps: + # NO NEED TO CHECKOUT HERE + - uses: r-hub/actions/setup@v1 + with: + config: ${{ github.event.inputs.config }} + id: rhub-setup + + linux-containers: + needs: setup + if: ${{ needs.setup.outputs.containers != '[]' }} + runs-on: ubuntu-latest + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.containers) }} + container: + image: ${{ matrix.config.container }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/run-check@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + + other-platforms: + needs: setup + if: ${{ needs.setup.outputs.platforms != '[]' }} + runs-on: ${{ matrix.config.os }} + name: ${{ matrix.config.label }} + strategy: + fail-fast: false + matrix: + config: ${{ fromJson(needs.setup.outputs.platforms) }} + + steps: + - uses: r-hub/actions/checkout@v1 + - uses: r-hub/actions/setup-r@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/platform-info@v1 + with: + token: ${{ secrets.RHUB_TOKEN }} + job-config: ${{ matrix.config.job-config }} + - uses: r-hub/actions/setup-deps@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} + - uses: r-hub/actions/run-check@v1 + with: + job-config: ${{ matrix.config.job-config }} + token: ${{ secrets.RHUB_TOKEN }} diff --git a/.github/workflows/test-coverage.yaml b/.github/workflows/test-coverage.yaml index 9245d3ad..5679b541 100644 --- a/.github/workflows/test-coverage.yaml +++ b/.github/workflows/test-coverage.yaml @@ -1,48 +1,61 @@ +# Workflow derived from https://github.com/r-lib/actions/tree/v2/examples +# Need help debugging build failures? Start at https://github.com/r-lib/actions#where-to-find-help on: push: - branches: - - master - - develop + branches: [master, develop] pull_request: - branches: - - master - - develop + branches: [master, develop] -name: test-coverage +name: test-coverage.yaml + +permissions: read-all jobs: test-coverage: - runs-on: macOS-latest + runs-on: ubuntu-latest env: GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }} + steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - - uses: r-lib/actions/setup-r@v1 + - uses: r-lib/actions/setup-r@v2 + with: + use-public-rspm: true - - uses: r-lib/actions/setup-pandoc@v1 + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + extra-packages: any::covr, any::xml2 + needs: coverage - - name: Query dependencies + - name: Test coverage run: | - install.packages('remotes') - saveRDS(remotes::dev_package_deps(dependencies = TRUE), ".github/depends.Rds", version = 2) - writeLines(sprintf("R-%i.%i", getRversion()$major, getRversion()$minor), ".github/R-version") + cov <- covr::package_coverage( + quiet = FALSE, + clean = FALSE, + install_path = file.path(normalizePath(Sys.getenv("RUNNER_TEMP"), winslash = "/"), "package") + ) + covr::to_cobertura(cov) shell: Rscript {0} - - name: Cache R packages - uses: actions/cache@v2 + - uses: codecov/codecov-action@v4 with: - path: ${{ env.R_LIBS_USER }} - key: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1-${{ hashFiles('.github/depends.Rds') }} - restore-keys: ${{ runner.os }}-${{ hashFiles('.github/R-version') }}-1- - - - name: Install dependencies + fail_ci_if_error: ${{ github.event_name != 'pull_request' && true || false }} + file: ./cobertura.xml + plugin: noop + disable_search: true + token: ${{ secrets.CODECOV_TOKEN }} + + - name: Show testthat output + if: always() run: | - install.packages(c("remotes")) - remotes::install_deps(dependencies = TRUE) - remotes::install_cran("covr") - shell: Rscript {0} + ## -------------------------------------------------------------------- + find '${{ runner.temp }}/package' -name 'testthat.Rout*' -exec cat '{}' \; || true + shell: bash - - name: Test coverage - run: covr::codecov() - shell: Rscript {0} + - name: Upload test results + if: failure() + uses: actions/upload-artifact@v4 + with: + name: coverage-test-failures + path: ${{ runner.temp }}/package diff --git a/.gitignore b/.gitignore index c833a2c6..7a7155e0 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,5 @@ .RData .Ruserdata inst/doc +/doc/ +/Meta/ diff --git a/DESCRIPTION b/DESCRIPTION index 3cbab1a0..0822e057 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: blorr Type: Package Title: Tools for Developing Binary Logistic Regression Models -Version: 0.3.0.9000 +Version: 0.3.1 Authors@R: person("Aravind", "Hebbali", email = "hebbali.aravind@gmail.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0001-9220-9669")) Description: Tools designed to make it easier for beginner and intermediate users to build and validate @@ -25,14 +25,15 @@ Suggests: knitr, magrittr, rmarkdown, - testthat, + testthat (>= 3.0.0), vdiffr, xplorerr License: MIT + file LICENSE -URL: URL: https://blorr.rsquaredacademy.com/, https://github.com/rsquaredacademy/blorr +URL: https://blorr.rsquaredacademy.com/, https://github.com/rsquaredacademy/blorr BugReports: https://github.com/rsquaredacademy/blorr/issues VignetteBuilder: knitr Encoding: UTF-8 LazyData: true -RoxygenNote: 7.1.0 +RoxygenNote: 7.3.2 LinkingTo: Rcpp +Config/testthat/edition: 3 diff --git a/R/blr-bivariate-analysis.R b/R/blr-bivariate-analysis.R index fba8cc83..420641de 100644 --- a/R/blr-bivariate-analysis.R +++ b/R/blr-bivariate-analysis.R @@ -335,10 +335,10 @@ plot.blr_segment_dist <- function(x, title = NA, xaxis_title = "Levels", breaks = seq(0, 1, by = 0.1), labels = paste0(seq(0, 1, by = 0.1) * 100, '%'), sec.axis = sec_axis( - trans = ~., - breaks = seq(0, 1, by = 0.1), - labels = paste0(seq(0, 1, by = 0.1) * 100, '%'), - name = sec_yaxis_title)) + transform = ~., + breaks = seq(0, 1, by = 0.1), + labels = paste0(seq(0, 1, by = 0.1) * 100, '%'), + name = sec_yaxis_title)) if (print_plot) { print(p) diff --git a/R/blr-blorr.R b/R/blr-blorr.R index e8316388..940b946f 100644 --- a/R/blr-blorr.R +++ b/R/blr-blorr.R @@ -5,8 +5,11 @@ #' See the README on #' \href{https://github.com/rsquaredacademy/blorr}{GitHub} #' +#' @keywords internal #' @docType package #' @name blorr +#' @aliases blorr-package +"_PACKAGE" NULL ## quiets concerns of R CMD check re: the .'s that appear in pipelines diff --git a/R/blr-data-hsb.R b/R/blr-data-hsb.R index 95d5c2ee..ed612938 100644 --- a/R/blr-data-hsb.R +++ b/R/blr-data-hsb.R @@ -19,6 +19,6 @@ #' \item{honcomp}{1 if write > 60, else 0} #' } #' -#' @source \url{http://www.ats.ucla.edu/stat/spss/whatstat/whatstat.htm} +#' @source \url{https://www.openintro.org/data/index.php?data=hsb} #' -"hsb2" \ No newline at end of file +"hsb2" diff --git a/R/blr-gains-table.R b/R/blr-gains-table.R index 9bf03237..5bb4b3f7 100644 --- a/R/blr-gains-table.R +++ b/R/blr-gains-table.R @@ -128,9 +128,7 @@ plot.blr_gains_table <- function(x, title = "Lift Chart", xaxis_title = "% Popul #' @param print_plot logical; if \code{TRUE}, prints the plot else returns a plot object. #' #' @references -#' \url{https://doi.org/10.1198/tast.2009.08210} -#' -#' \url{https://www.ncbi.nlm.nih.gov/pubmed/843576} +#' \url{https://pubmed.ncbi.nlm.nih.gov/843576/} #' #' @examples #' model <- glm(honcomp ~ female + read + science, data = hsb2, diff --git a/R/blr-lorenz-curve.R b/R/blr-lorenz-curve.R index a8f790ac..a20a3c54 100644 --- a/R/blr-lorenz-curve.R +++ b/R/blr-lorenz-curve.R @@ -16,8 +16,6 @@ #' Müller M, Rönz B (2000): Credit Scoring using Semiparametric Methods. In: Franke J, Härdle W, Stahl G (Eds.): #' Measuring Risk in Complex Stochastic Systems. New York, Springer-Verlag. #' -#' \url{https://doi.org/10.2753/REE1540-496X470605} -#' #' @examples #' model <- glm(honcomp ~ female + read + science, data = hsb2, #' family = binomial(link = 'logit')) diff --git a/R/blr-pairs.R b/R/blr-pairs.R index ff48a633..9ac7af86 100644 --- a/R/blr-pairs.R +++ b/R/blr-pairs.R @@ -6,11 +6,6 @@ #' #' @return A tibble. #' -#' @references -#' \url{https://doi.org/10.1080/10485259808832744} -#' -#' \url{https://doi.org/10.1177/1536867X0600600302} -#' #' @examples #' model <- glm(honcomp ~ female + read + science, data = hsb2, #' family = binomial(link = 'logit')) diff --git a/README.Rmd b/README.Rmd index fa5b4d8b..0f4915e8 100644 --- a/README.Rmd +++ b/README.Rmd @@ -18,9 +18,10 @@ options(tibble.width = Inf) > Tools for building binary logistic regression models -[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/blorr)](https://cran.r-project.org/package=blorr) [![cran checks](https://cranchecks.info/badges/summary/blorr)](https://cran.r-project.org/web/checks/check_results_blorr.html) ![r-universe](https://rsquaredacademy.r-universe.dev/badges/blorr) -[![R build status](https://github.com/rsquaredacademy/blorr/workflows/R-CMD-check/badge.svg)](https://github.com/rsquaredacademy/blorr/actions) [![Lifecycle: stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) -[![Coverage status](https://codecov.io/gh/rsquaredacademy/blorr/branch/master/graph/badge.svg)](https://codecov.io/github/rsquaredacademy/blorr?branch=master) [![status](https://tinyverse.netlify.com/badge/blorr)](https://CRAN.R-project.org/package=blorr) [![](https://cranlogs.r-pkg.org/badges/grand-total/blorr)](https://cran.r-project.org/package=blorr) +[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/blorr)](https://cran.r-project.org/package=blorr) +[![R-CMD-check](https://github.com/rsquaredacademy/blorr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rsquaredacademy/blorr/actions/workflows/R-CMD-check.yaml) +[![Coverage status](https://app.codecov.io/gh/rsquaredacademy/blorr/branch/master/graph/badge.svg)](https://app.codecov.io/github/rsquaredacademy/blorr?branch=master) + ## Overview @@ -143,6 +144,3 @@ If you encounter a bug, please file a minimal reproducible example using [reprex](https://reprex.tidyverse.org/index.html) on github. For questions and clarifications, use [StackOverflow](https://stackoverflow.com/). -## Code of Conduct - -Please note that this project is released with a [Contributor Code of Conduct](CONDUCT.md). By participating in this project you agree to abide by its terms. diff --git a/README.md b/README.md index 1436f9d8..092bf642 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,11 @@ -[![CRAN\_Status\_Badge](https://www.r-pkg.org/badges/version/blorr)](https://cran.r-project.org/package=blorr) -[![cran -checks](https://cranchecks.info/badges/summary/blorr)](https://cran.r-project.org/web/checks/check_results_blorr.html) -![r-universe](https://rsquaredacademy.r-universe.dev/badges/blorr) [![R -build -status](https://github.com/rsquaredacademy/blorr/workflows/R-CMD-check/badge.svg)](https://github.com/rsquaredacademy/blorr/actions) -[![Lifecycle: -stable](https://img.shields.io/badge/lifecycle-stable-brightgreen.svg)](https://lifecycle.r-lib.org/articles/stages.html) +[![CRAN_Status_Badge](https://www.r-pkg.org/badges/version/blorr)](https://cran.r-project.org/package=blorr) +[![R-CMD-check](https://github.com/rsquaredacademy/blorr/actions/workflows/R-CMD-check.yaml/badge.svg)](https://github.com/rsquaredacademy/blorr/actions/workflows/R-CMD-check.yaml) [![Coverage -status](https://codecov.io/gh/rsquaredacademy/blorr/branch/master/graph/badge.svg)](https://codecov.io/github/rsquaredacademy/blorr?branch=master) -[![status](https://tinyverse.netlify.com/badge/blorr)](https://CRAN.R-project.org/package=blorr) -[![](https://cranlogs.r-pkg.org/badges/grand-total/blorr)](https://cran.r-project.org/package=blorr) +status](https://app.codecov.io/gh/rsquaredacademy/blorr/branch/master/graph/badge.svg)](https://app.codecov.io/github/rsquaredacademy/blorr?branch=master) + ## Overview @@ -45,8 +38,8 @@ install.packages("blorr", repos = "https://rsquaredacademy.r-universe.dev") ## Articles -- [A Short Introduction to the blorr - Package](https://blorr.rsquaredacademy.com/articles/introduction.html) +- [A Short Introduction to the blorr + Package](https://blorr.rsquaredacademy.com/articles/introduction.html) ## Usage @@ -278,9 +271,3 @@ If you encounter a bug, please file a minimal reproducible example using [reprex](https://reprex.tidyverse.org/index.html) on github. For questions and clarifications, use [StackOverflow](https://stackoverflow.com/). - -## Code of Conduct - -Please note that this project is released with a [Contributor Code of -Conduct](CONDUCT.md). By participating in this project you agree to -abide by its terms. diff --git a/man/blorr.Rd b/man/blorr.Rd index e83c91c0..4eafac6b 100644 --- a/man/blorr.Rd +++ b/man/blorr.Rd @@ -3,6 +3,7 @@ \docType{package} \name{blorr} \alias{blorr} +\alias{blorr-package} \title{\code{blorr} package} \description{ Tools for developing binary logistic regression models @@ -11,3 +12,17 @@ Tools for developing binary logistic regression models See the README on \href{https://github.com/rsquaredacademy/blorr}{GitHub} } +\seealso{ +Useful links: +\itemize{ + \item \url{https://blorr.rsquaredacademy.com/} + \item \url{https://github.com/rsquaredacademy/blorr} + \item Report bugs at \url{https://github.com/rsquaredacademy/blorr/issues} +} + +} +\author{ +\strong{Maintainer}: Aravind Hebbali \email{hebbali.aravind@gmail.com} (\href{https://orcid.org/0000-0001-9220-9669}{ORCID}) + +} +\keyword{internal} diff --git a/man/blr_bivariate_analysis.Rd b/man/blr_bivariate_analysis.Rd index e1d60474..166fbb01 100644 --- a/man/blr_bivariate_analysis.Rd +++ b/man/blr_bivariate_analysis.Rd @@ -35,10 +35,10 @@ blr_bivariate_analysis(hsb2, honcomp, female, prog, race, schtyp) } \seealso{ Other bivariate analysis procedures: +\code{\link{blr_segment}()}, \code{\link{blr_segment_dist}()}, \code{\link{blr_segment_twoway}()}, -\code{\link{blr_segment}()}, -\code{\link{blr_woe_iv_stats}()}, -\code{\link{blr_woe_iv}()} +\code{\link{blr_woe_iv}()}, +\code{\link{blr_woe_iv_stats}()} } \concept{bivariate analysis procedures} diff --git a/man/blr_gini_index.Rd b/man/blr_gini_index.Rd index 1c7667f2..41300039 100644 --- a/man/blr_gini_index.Rd +++ b/man/blr_gini_index.Rd @@ -32,8 +32,6 @@ credit scoring. New Jersey, Wiley. Müller M, Rönz B (2000): Credit Scoring using Semiparametric Methods. In: Franke J, Härdle W, Stahl G (Eds.): Measuring Risk in Complex Stochastic Systems. New York, Springer-Verlag. - -\url{https://doi.org/10.2753/REE1540-496X470605} } \seealso{ Other model validation techniques: diff --git a/man/blr_ks_chart.Rd b/man/blr_ks_chart.Rd index 8d4ef474..236f7922 100644 --- a/man/blr_ks_chart.Rd +++ b/man/blr_ks_chart.Rd @@ -41,9 +41,7 @@ blr_ks_chart(gt) } \references{ -\url{https://doi.org/10.1198/tast.2009.08210} - -\url{https://www.ncbi.nlm.nih.gov/pubmed/843576} +\url{https://pubmed.ncbi.nlm.nih.gov/843576/} } \seealso{ Other model validation techniques: diff --git a/man/blr_pairs.Rd b/man/blr_pairs.Rd index 9f27dcda..e9496b11 100644 --- a/man/blr_pairs.Rd +++ b/man/blr_pairs.Rd @@ -21,11 +21,6 @@ family = binomial(link = 'logit')) blr_pairs(model) -} -\references{ -\url{https://doi.org/10.1080/10485259808832744} - -\url{https://doi.org/10.1177/1536867X0600600302} } \seealso{ Other model fit statistics: diff --git a/man/blr_segment.Rd b/man/blr_segment.Rd index f7992877..6cdf9d32 100644 --- a/man/blr_segment.Rd +++ b/man/blr_segment.Rd @@ -31,7 +31,7 @@ Other bivariate analysis procedures: \code{\link{blr_bivariate_analysis}()}, \code{\link{blr_segment_dist}()}, \code{\link{blr_segment_twoway}()}, -\code{\link{blr_woe_iv_stats}()}, -\code{\link{blr_woe_iv}()} +\code{\link{blr_woe_iv}()}, +\code{\link{blr_woe_iv_stats}()} } \concept{bivariate analysis procedures} diff --git a/man/blr_segment_dist.Rd b/man/blr_segment_dist.Rd index 6ff1f142..c2717397 100644 --- a/man/blr_segment_dist.Rd +++ b/man/blr_segment_dist.Rd @@ -61,9 +61,9 @@ plot(k) \seealso{ Other bivariate analysis procedures: \code{\link{blr_bivariate_analysis}()}, -\code{\link{blr_segment_twoway}()}, \code{\link{blr_segment}()}, -\code{\link{blr_woe_iv_stats}()}, -\code{\link{blr_woe_iv}()} +\code{\link{blr_segment_twoway}()}, +\code{\link{blr_woe_iv}()}, +\code{\link{blr_woe_iv_stats}()} } \concept{bivariate analysis procedures} diff --git a/man/blr_segment_twoway.Rd b/man/blr_segment_twoway.Rd index 8e00bd48..c025e230 100644 --- a/man/blr_segment_twoway.Rd +++ b/man/blr_segment_twoway.Rd @@ -31,9 +31,9 @@ blr_segment_twoway(hsb2, honcomp, prog, female) \seealso{ Other bivariate analysis procedures: \code{\link{blr_bivariate_analysis}()}, -\code{\link{blr_segment_dist}()}, \code{\link{blr_segment}()}, -\code{\link{blr_woe_iv_stats}()}, -\code{\link{blr_woe_iv}()} +\code{\link{blr_segment_dist}()}, +\code{\link{blr_woe_iv}()}, +\code{\link{blr_woe_iv_stats}()} } \concept{bivariate analysis procedures} diff --git a/man/blr_woe_iv.Rd b/man/blr_woe_iv.Rd index af856b0a..9231bac8 100644 --- a/man/blr_woe_iv.Rd +++ b/man/blr_woe_iv.Rd @@ -66,9 +66,9 @@ credit scoring. New Jersey, Wiley. \seealso{ Other bivariate analysis procedures: \code{\link{blr_bivariate_analysis}()}, +\code{\link{blr_segment}()}, \code{\link{blr_segment_dist}()}, \code{\link{blr_segment_twoway}()}, -\code{\link{blr_segment}()}, \code{\link{blr_woe_iv_stats}()} } \concept{bivariate analysis procedures} diff --git a/man/blr_woe_iv_stats.Rd b/man/blr_woe_iv_stats.Rd index 7c75604c..15ee72db 100644 --- a/man/blr_woe_iv_stats.Rd +++ b/man/blr_woe_iv_stats.Rd @@ -24,9 +24,9 @@ blr_woe_iv_stats(hsb2, honcomp, prog, race, female, schtyp) \seealso{ Other bivariate analysis procedures: \code{\link{blr_bivariate_analysis}()}, +\code{\link{blr_segment}()}, \code{\link{blr_segment_dist}()}, \code{\link{blr_segment_twoway}()}, -\code{\link{blr_segment}()}, \code{\link{blr_woe_iv}()} } \concept{bivariate analysis procedures} diff --git a/man/hsb2.Rd b/man/hsb2.Rd index 808bed02..1d7fe88a 100644 --- a/man/hsb2.Rd +++ b/man/hsb2.Rd @@ -22,7 +22,7 @@ A data frame with 200 rows and 11 variables: } } \source{ -\url{http://www.ats.ucla.edu/stat/spss/whatstat/whatstat.htm} +\url{https://www.openintro.org/data/index.php?data=hsb} } \usage{ hsb2 diff --git a/src-i386/RcppExports.cpp b/src-i386/RcppExports.cpp deleted file mode 100644 index e6f369e2..00000000 --- a/src-i386/RcppExports.cpp +++ /dev/null @@ -1,29 +0,0 @@ -// Generated by using Rcpp::compileAttributes() -> do not edit by hand -// Generator token: 10BE3573-1514-4C36-9D1C-5A225CD40393 - -#include - -using namespace Rcpp; - -// blr_pairs_cpp -DataFrame blr_pairs_cpp(NumericVector x, NumericVector y); -RcppExport SEXP _blorr_blr_pairs_cpp(SEXP xSEXP, SEXP ySEXP) { -BEGIN_RCPP - Rcpp::RObject rcpp_result_gen; - Rcpp::RNGScope rcpp_rngScope_gen; - Rcpp::traits::input_parameter< NumericVector >::type x(xSEXP); - Rcpp::traits::input_parameter< NumericVector >::type y(ySEXP); - rcpp_result_gen = Rcpp::wrap(blr_pairs_cpp(x, y)); - return rcpp_result_gen; -END_RCPP -} - -static const R_CallMethodDef CallEntries[] = { - {"_blorr_blr_pairs_cpp", (DL_FUNC) &_blorr_blr_pairs_cpp, 2}, - {NULL, NULL, 0} -}; - -RcppExport void R_init_blorr(DllInfo *dll) { - R_registerRoutines(dll, NULL, CallEntries, NULL, NULL); - R_useDynamicSymbols(dll, FALSE); -} diff --git a/src-i386/RcppExports.o b/src-i386/RcppExports.o deleted file mode 100644 index 0457e7ad..00000000 Binary files a/src-i386/RcppExports.o and /dev/null differ diff --git a/src-i386/blr-pairs-cpp.cpp b/src-i386/blr-pairs-cpp.cpp deleted file mode 100644 index 47aa87da..00000000 --- a/src-i386/blr-pairs-cpp.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -using namespace Rcpp; - -// [[Rcpp::plugins("cpp11")]] -// [[Rcpp::export]] -DataFrame blr_pairs_cpp(NumericVector x, NumericVector y) { - - // loop counters - int n1 = x.size(); - int n2 = y.size(); - - // count pairs - int pairs_count = 0; - int concordant = 0; - int discordant = 0; - int ties = 0; - - // compute - for(int i = 0; i < n1; i++) { - for(int j = 0; j < n2; j++) { - - pairs_count++; - - if (x[i] > y[j]) { - concordant++; - } else if (x[i] == y[j]) { - ties++; - } else { - discordant++; - } - - } - } - - DataFrame df = DataFrame::create(Named("pairs") = pairs_count, - Named("concordant") = concordant, - Named("discordant") = discordant, - Named("ties") = ties); - - return df; - -} - diff --git a/src-i386/blr-pairs-cpp.o b/src-i386/blr-pairs-cpp.o deleted file mode 100644 index 9f4ba3de..00000000 Binary files a/src-i386/blr-pairs-cpp.o and /dev/null differ diff --git a/src/RcppExports.cpp b/src/RcppExports.cpp index e6f369e2..de981966 100644 --- a/src/RcppExports.cpp +++ b/src/RcppExports.cpp @@ -5,6 +5,11 @@ using namespace Rcpp; +#ifdef RCPP_USE_GLOBAL_ROSTREAM +Rcpp::Rostream& Rcpp::Rcout = Rcpp::Rcpp_cout_get(); +Rcpp::Rostream& Rcpp::Rcerr = Rcpp::Rcpp_cerr_get(); +#endif + // blr_pairs_cpp DataFrame blr_pairs_cpp(NumericVector x, NumericVector y); RcppExport SEXP _blorr_blr_pairs_cpp(SEXP xSEXP, SEXP ySEXP) { diff --git a/tests/testthat.R b/tests/testthat.R index 2870a1b3..65677eba 100644 --- a/tests/testthat.R +++ b/tests/testthat.R @@ -1,3 +1,11 @@ +# This file is part of the standard setup for testthat. +# It is recommended that you do not modify it. +# +# Where should you do additional test configuration? +# Learn more about the roles of various files in: +# * https://r-pkgs.org/testing-design.html#sec-tests-files-overview +# * https://testthat.r-lib.org/articles/special-files.html + library(testthat) library(blorr) diff --git a/tests/testthat/_snaps/backward-aic.md b/tests/testthat/_snaps/backward-aic.md new file mode 100644 index 00000000..8b3e8ab9 --- /dev/null +++ b/tests/testthat/_snaps/backward-aic.md @@ -0,0 +1,17 @@ +# output from backward variable elimination is as expected + + Code + blr_step_aic_backward(model) + Output + + + Backward Elimination Summary + -------------------------------------------- + Variable AIC BIC Deviance + -------------------------------------------- + Full Model 162.424 188.811 146.424 + prog 158.953 178.743 146.953 + socst 157.286 173.777 147.286 + -------------------------------------------- + + diff --git a/tests/testthat/_snaps/bivariate-analysis.md b/tests/testthat/_snaps/bivariate-analysis.md new file mode 100644 index 00000000..f0436d5b --- /dev/null +++ b/tests/testthat/_snaps/bivariate-analysis.md @@ -0,0 +1,89 @@ +# blr_bivariate_analysis prints the correct output + + Code + k + Output + Bivariate Analysis + --------------------------------------------------------------------- + Variable Information Value LR Chi Square LR DF LR p-value + --------------------------------------------------------------------- + female 0.10 3.9350 1 0.0473 + prog 0.43 16.1450 2 3e-04 + --------------------------------------------------------------------- + +# blr_segment prints the correct output + + Code + k + Output + Event By Attributes + ------------------- + pred 1s% + ------------------- + 1 0.01 + 2 0.03 + 3 0.01 + 4 0.22 + ------------------- + + +# blr_twoway_segment prints the correct output + + Code + k + Output + prog + ----------------------------------------- + honcomp 1 2 3 4 + ----------------------------------------- + 1 0.000 0.000 0.000 0.035 + ----------------------------------------- + 2 0.010 0.020 0.005 0.165 + ----------------------------------------- + 3 0.000 0.005 0.005 0.020 + ----------------------------------------- + +--- + + Code + k + Output + Event Segmentation + ------------------------------------- + pred n 1s n% 1s% + ------------------------------------- + 1 24 2 0.12 0.01 + 2 11 5 0.06 0.03 + 3 20 2 0.10 0.01 + 4 145 44 0.72 0.22 + ------------------------------------- + + +# blr_woe_iv prints the correct output + + Code + k + Output + Weight of Evidence + ------------------------------------------------------------------------- + levels count_0s count_1s dist_0s dist_1s woe iv + ------------------------------------------------------------------------- + 1 38 7 0.26 0.13 0.67 0.08 + 2 65 40 0.44 0.75 -0.53 0.17 + 3 44 6 0.30 0.11 0.97 0.18 + ------------------------------------------------------------------------- + + Information Value + ----------------------------- + Variable Information Value + ----------------------------- + prog 0.4329 + ----------------------------- + +# output from blr_woe_iv_stats is as expected + + Code + k + Output + NULL + diff --git a/tests/testthat/_snaps/blr-plots/c-fitted-plot.svg b/tests/testthat/_snaps/blr-plots/c-fitted-plot.svg new file mode 100644 index 00000000..fa35faeb --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/c-fitted-plot.svg @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.1 +0.2 +0.3 + + + + + + + + +0.00 +0.25 +0.50 +0.75 +Fitted Values +CI Displacement C +CI Displacement C vs Fitted Values Plot + + diff --git a/tests/testthat/_snaps/blr-plots/c-leverage-plot.svg b/tests/testthat/_snaps/blr-plots/c-leverage-plot.svg new file mode 100644 index 00000000..a40428e0 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/c-leverage-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.1 +0.2 +0.3 + + + + + + + + + +0.00 +0.02 +0.04 +0.06 +0.08 +Leverage +CI Displacement C +CI Displacement C vs Leverage Plot + + diff --git a/tests/testthat/_snaps/blr-plots/c-plot.svg b/tests/testthat/_snaps/blr-plots/c-plot.svg new file mode 100644 index 00000000..66b31405 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/c-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.1 +0.2 +0.3 + + + + + + + + + +0 +50 +100 +150 +200 +id +CI Displacement C +CI Displacement C Plot + + diff --git a/tests/testthat/_snaps/blr-plots/cbar-plot.svg b/tests/testthat/_snaps/blr-plots/cbar-plot.svg new file mode 100644 index 00000000..ca928ecd --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/cbar-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.0 +0.1 +0.2 +0.3 + + + + + + + + + +0 +50 +100 +150 +200 +id +CI Displacement CBAR +CI Displacement CBAR Plot + + diff --git a/tests/testthat/_snaps/blr-plots/decile-capture-rate-chart.svg b/tests/testthat/_snaps/blr-plots/decile-capture-rate-chart.svg new file mode 100644 index 00000000..cacaa4db --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/decile-capture-rate-chart.svg @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.7 +0.65 +0.5 +0.35 +0.15 +0.15 +0.05 +0.1 +0 +0 + + + +0.0 +0.2 +0.4 +0.6 + + + + + + + + +2.5 +5.0 +7.5 +10.0 +Decile +Capture Rate +Capture Rate by Decile + + diff --git a/tests/testthat/_snaps/blr-plots/decile-lift-chart.svg b/tests/testthat/_snaps/blr-plots/decile-lift-chart.svg new file mode 100644 index 00000000..aab77647 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/decile-lift-chart.svg @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +2.64 +2.45 +1.89 +1.32 +0.57 +0.57 +0.19 +0.38 +0 +0 + + + +0 +1 +2 + + + + + + + +2.5 +5.0 +7.5 +10.0 +Decile +Decile Mean / Global Mean +Decile Lift Chart + + diff --git a/tests/testthat/_snaps/blr-plots/deviance-fitted-plot.svg b/tests/testthat/_snaps/blr-plots/deviance-fitted-plot.svg new file mode 100644 index 00000000..1c5c9ae4 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/deviance-fitted-plot.svg @@ -0,0 +1,256 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +-1 +0 +1 +2 + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +Fitted Values +Deviance Residual +Deviance Residual vs Fitted Values + + diff --git a/tests/testthat/_snaps/blr-plots/deviance-residual-plot.svg b/tests/testthat/_snaps/blr-plots/deviance-residual-plot.svg new file mode 100644 index 00000000..f609b6e4 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/deviance-residual-plot.svg @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +-1 +0 +1 +2 + + + + + + + + + + +0 +50 +100 +150 +200 +id +Deviance Residuals +Deviance Residuals Plot + + diff --git a/tests/testthat/_snaps/blr-plots/difchisq-fitted-plot.svg b/tests/testthat/_snaps/blr-plots/difchisq-fitted-plot.svg new file mode 100644 index 00000000..e93798ec --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/difchisq-fitted-plot.svg @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +5 +10 +15 +20 +25 + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +Fitted Values +Delta Chi Square +Delta Chi Square vs Fitted Values Plot + + diff --git a/tests/testthat/_snaps/blr-plots/difchisq-leverage-plot.svg b/tests/testthat/_snaps/blr-plots/difchisq-leverage-plot.svg new file mode 100644 index 00000000..036cea16 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/difchisq-leverage-plot.svg @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +5 +10 +15 +20 +25 + + + + + + + + + + + +0.00 +0.02 +0.04 +0.06 +0.08 +Leverage +Delta Chi Square +Delta Chi Square vs Leverage Plot + + diff --git a/tests/testthat/_snaps/blr-plots/difchisq-plot.svg b/tests/testthat/_snaps/blr-plots/difchisq-plot.svg new file mode 100644 index 00000000..e5f153c8 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/difchisq-plot.svg @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +5 +10 +15 +20 +25 + + + + + + + + + + + +0 +50 +100 +150 +200 +id +Delta Chisquare +Delta Chisquare Plot + + diff --git a/tests/testthat/_snaps/blr-plots/difdev-fitted-plot.svg b/tests/testthat/_snaps/blr-plots/difdev-fitted-plot.svg new file mode 100644 index 00000000..e5842829 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/difdev-fitted-plot.svg @@ -0,0 +1,253 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +2 +4 +6 + + + + + + + + +0.00 +0.25 +0.50 +0.75 +Fitted Values +Delta Deviance +Delta Deviance vs Fitted Values Plot + + diff --git a/tests/testthat/_snaps/blr-plots/difdev-leverage-plot.svg b/tests/testthat/_snaps/blr-plots/difdev-leverage-plot.svg new file mode 100644 index 00000000..6fbc2487 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/difdev-leverage-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +2 +4 +6 + + + + + + + + + +0.00 +0.02 +0.04 +0.06 +0.08 +Leverage +Delta Deviance +Delta Deviance vs Leverage Plot + + diff --git a/tests/testthat/_snaps/blr-plots/difdev-plot.svg b/tests/testthat/_snaps/blr-plots/difdev-plot.svg new file mode 100644 index 00000000..68e5decc --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/difdev-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0 +2 +4 +6 + + + + + + + + + +0 +50 +100 +150 +200 +id +Delta Deviance +Delta Deviance Plot + + diff --git a/tests/testthat/_snaps/blr-plots/fitted-leverage-plot.svg b/tests/testthat/_snaps/blr-plots/fitted-leverage-plot.svg new file mode 100644 index 00000000..93aa8e29 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/fitted-leverage-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 + + + + + + + + + +0.00 +0.02 +0.04 +0.06 +0.08 +Leverage +Fitted Values +Fitted Values vs Leverage Plot + + diff --git a/tests/testthat/_snaps/blr-plots/forward-selection-plot.svg b/tests/testthat/_snaps/blr-plots/forward-selection-plot.svg new file mode 100644 index 00000000..e69de29b diff --git a/tests/testthat/_snaps/blr-plots/ks-chart.svg b/tests/testthat/_snaps/blr-plots/ks-chart.svg new file mode 100644 index 00000000..b3e18973 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/ks-chart.svg @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +KS: 59% + + +0% +25% +50% +75% +100% + + + + + + + + + + +0% +25% +50% +75% +100% +Cumulative Population % + + + + + + + + +Cumulative 0s % +Cumulative 1s % +KS Chart + + diff --git a/tests/testthat/_snaps/blr-plots/leverage-fitted-plot.svg b/tests/testthat/_snaps/blr-plots/leverage-fitted-plot.svg new file mode 100644 index 00000000..2dd41f4e --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/leverage-fitted-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.02 +0.04 +0.06 +0.08 + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +Fitted Values +Leverage +Leverage vs Fitted Values + + diff --git a/tests/testthat/_snaps/blr-plots/leverage-plot.svg b/tests/testthat/_snaps/blr-plots/leverage-plot.svg new file mode 100644 index 00000000..0fd2019c --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/leverage-plot.svg @@ -0,0 +1,257 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.02 +0.04 +0.06 +0.08 + + + + + + + + + + +0 +50 +100 +150 +200 +id +Leverage +Leverage Plot + + diff --git a/tests/testthat/_snaps/blr-plots/lift-chart.svg b/tests/testthat/_snaps/blr-plots/lift-chart.svg new file mode 100644 index 00000000..03695867 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/lift-chart.svg @@ -0,0 +1,76 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0% +25% +50% +75% +100% + + + + + + + + + + +0% +25% +50% +75% +100% +% Population +% Cumulative 1s +Lift Chart + + diff --git a/tests/testthat/_snaps/blr-plots/lorenz-curve.svg b/tests/testthat/_snaps/blr-plots/lorenz-curve.svg new file mode 100644 index 00000000..1168b88b --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/lorenz-curve.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 + + + + + + + + + + +0.00 +0.25 +0.50 +0.75 +1.00 +Cumulative Events % +Cumulative Non Events % +Gini Index = 0.53 +Lorenz Curve + + diff --git a/tests/testthat/_snaps/blr-plots/pearson-residual-plot.svg b/tests/testthat/_snaps/blr-plots/pearson-residual-plot.svg new file mode 100644 index 00000000..664b8265 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/pearson-residual-plot.svg @@ -0,0 +1,255 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 +4 + + + + + + + + + +0 +50 +100 +150 +200 +id +Standardized Pearson Residuals +Standardized Pearson Residuals + + diff --git a/tests/testthat/_snaps/blr-plots/residual-fitted-plot.svg b/tests/testthat/_snaps/blr-plots/residual-fitted-plot.svg new file mode 100644 index 00000000..00b3c6d6 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/residual-fitted-plot.svg @@ -0,0 +1,254 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-2 +0 +2 +4 + + + + + + + + +0.00 +0.25 +0.50 +0.75 +Fitted Values +Standardized Pearson Residual +Standardized Pearson Residual vs Fitted Values + + diff --git a/tests/testthat/_snaps/blr-plots/roc-curve.svg b/tests/testthat/_snaps/blr-plots/roc-curve.svg new file mode 100644 index 00000000..67ad01e1 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/roc-curve.svg @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0% +25% +50% +75% +100% + + + + + + + + + + +0% +25% +50% +75% +100% +1 - Specificity +Sensitivity +ROC Curve + + diff --git a/tests/testthat/_snaps/blr-plots/segment-distribution-plot.svg b/tests/testthat/_snaps/blr-plots/segment-distribution-plot.svg new file mode 100644 index 00000000..43ef4f09 --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/segment-distribution-plot.svg @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +0% +10% +20% +30% +40% +50% + + + + + + + + + + + + +0% +10% +20% +30% +40% +50% + + + +1 +2 +3 +Levels +Sample Distribution +1s Distribution +pred + + diff --git a/tests/testthat/_snaps/blr-plots/stepwise-backward-selection-plot.svg b/tests/testthat/_snaps/blr-plots/stepwise-backward-selection-plot.svg new file mode 100644 index 00000000..e69de29b diff --git a/tests/testthat/_snaps/blr-plots/stepwise-selection-plot.svg b/tests/testthat/_snaps/blr-plots/stepwise-selection-plot.svg new file mode 100644 index 00000000..e69de29b diff --git a/tests/testthat/_snaps/blr-plots/woe-plot.svg b/tests/testthat/_snaps/blr-plots/woe-plot.svg new file mode 100644 index 00000000..b133bafc --- /dev/null +++ b/tests/testthat/_snaps/blr-plots/woe-plot.svg @@ -0,0 +1,55 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + +-0.5 +0.0 +0.5 +1.0 + + + + + + + +1 +2 +3 +Levels +WoE +prog + + diff --git a/tests/testthat/_snaps/blr-regress.md b/tests/testthat/_snaps/blr-regress.md new file mode 100644 index 00000000..625b6af0 --- /dev/null +++ b/tests/testthat/_snaps/blr-regress.md @@ -0,0 +1,47 @@ +# output from blr_regress is as expected + + Code + k + Output + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 196 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -12.7772 1.9755 -6.4677 0.0000 + female1 1 1.4825 0.4474 3.3139 9e-04 + read 1 0.1035 0.0258 4.0186 1e-04 + science 1 0.0948 0.0305 3.1129 0.0019 + ----------------------------------------------------------------- + + Odds Ratio Estimates + --------------------------------------------------------- + Effects Estimate 95% Wald Conf. Limit + --------------------------------------------------------- + female1 4.4039 1.8955 11.0521 + read 1.1091 1.0569 1.1699 + science 1.0994 1.0377 1.1702 + --------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8561 Somers' D 0.7147 + % Discordant 0.1425 Gamma 0.7136 + % Tied 0.0014 Tau-a 0.2794 + Pairs 7791 c 0.8568 + --------------------------------------------------------------- + + diff --git a/tests/testthat/_snaps/coll-diag.md b/tests/testthat/_snaps/coll-diag.md new file mode 100644 index 00000000..5d1cf86e --- /dev/null +++ b/tests/testthat/_snaps/coll-diag.md @@ -0,0 +1,26 @@ +# blr_coll_diag prints the correct output + + Code + k + Output + Tolerance and Variance Inflation Factor + --------------------------------------- + Variable Tolerance VIF + 1 female1 0.9824347 1.017879 + 2 read 0.6021370 1.660752 + 3 science 0.5939847 1.683545 + + + Eigenvalue and Condition Index + ------------------------------ + Eigenvalue Condition Index intercept female1 read + 1 3.57391760 1.000000 3.500782e-06 2.232611e-05 0.0006577134 + 2 0.39409893 3.011408 5.155657e-06 8.559696e-04 0.0015266309 + 3 0.01888407 13.757025 1.632498e-03 4.397949e-05 0.1143698337 + 4 0.01309940 16.517583 5.619292e-05 1.312420e-05 0.2758987745 + science + 1 0.0009448623 + 2 0.0025603607 + 3 0.0545537252 + 4 0.5468553525 + diff --git a/tests/testthat/_snaps/forward-aic.md b/tests/testthat/_snaps/forward-aic.md new file mode 100644 index 00000000..2ac7a10e --- /dev/null +++ b/tests/testthat/_snaps/forward-aic.md @@ -0,0 +1,15 @@ +# output from forward variable selection is as expected + + Code + blr_step_aic_forward(model) + Output + + Selection Summary + --------------------------------------------------- + Step Variable AIC BIC Deviance + --------------------------------------------------- + 1 read 183.063 189.660 179.063 + 2 female 176.887 176.887 176.887 + 3 science 168.236 168.236 168.236 + --------------------------------------------------- + diff --git a/tests/testthat/_snaps/forward-p.md b/tests/testthat/_snaps/forward-p.md new file mode 100644 index 00000000..7ac5502c --- /dev/null +++ b/tests/testthat/_snaps/forward-p.md @@ -0,0 +1,73 @@ +# output from forward variable p selection is as expected + + Code + blr_step_p_forward(model) + Output + Forward Selection Method + --------------------------- + + Candidate Terms: + + 1. female + 2. read + 3. science + + We are selecting variables based on p value... + + Variables Entered: + + - read + - female + - science + + + Final Model Output + ------------------ + + - Creating model overview. + - Creating response profile. + - Extracting maximum likelihood estimates. + - Estimating concordant and discordant pairs. + Model Overview + ------------------------------------------------------------------------ + Data Set Resp Var Obs. Df. Model Df. Residual Convergence + ------------------------------------------------------------------------ + data honcomp 200 199 196 TRUE + ------------------------------------------------------------------------ + + Response Summary + -------------------------------------------------------- + Outcome Frequency Outcome Frequency + -------------------------------------------------------- + 0 147 1 53 + -------------------------------------------------------- + + Maximum Likelihood Estimates + ----------------------------------------------------------------- + Parameter DF Estimate Std. Error z value Pr(>|z|) + ----------------------------------------------------------------- + (Intercept) 1 -12.7772 1.9755 -6.4677 0.0000 + read 1 0.1035 0.0258 4.0186 1e-04 + female1 1 1.4825 0.4474 3.3139 9e-04 + science 1 0.0948 0.0305 3.1129 0.0019 + ----------------------------------------------------------------- + + Association of Predicted Probabilities and Observed Responses + --------------------------------------------------------------- + % Concordant 0.8561 Somers' D 0.7147 + % Discordant 0.1425 Gamma 0.7136 + % Tied 0.0014 Tau-a 0.2794 + Pairs 7791 c 0.8568 + --------------------------------------------------------------- + + + Selection Summary + ---------------------------------------------------- + Variable + Step Entered AIC BIC Deviance + ---------------------------------------------------- + 1 read 183.0630 189.6596 179.0630 + 2 female 176.8874 186.7824 170.8874 + 3 science 168.2364 181.4296 160.2364 + ---------------------------------------------------- + diff --git a/tests/testthat/_snaps/hosmer-lemeshow.md b/tests/testthat/_snaps/hosmer-lemeshow.md new file mode 100644 index 00000000..513da60d --- /dev/null +++ b/tests/testthat/_snaps/hosmer-lemeshow.md @@ -0,0 +1,29 @@ +# hosmer lemeshow test prints the correct output + + Code + k + Output + Partition for the Hosmer & Lemeshow Test + -------------------------------------------------------------- + def = 1 def = 0 + Group Total Observed Expected Observed Expected + -------------------------------------------------------------- + 1 20 0 0.29 20 19.71 + 2 21 1 0.74 20 20.26 + 3 19 0 1.05 19 17.95 + 4 22 2 2.04 20 19.96 + 5 18 2 2.93 16 15.07 + 6 20 4 4.47 16 15.53 + 7 20 9 6.17 11 13.83 + 8 21 9 8.93 12 12.07 + 9 19 13 11.16 6 7.84 + 10 20 13 15.22 7 4.78 + -------------------------------------------------------------- + + Goodness of Fit Test + ------------------------------ + Chi-Square DF Pr > ChiSq + ------------------------------ + 5.8839 8 0.6602 + ------------------------------ + diff --git a/tests/testthat/_snaps/model-fit-stats.md b/tests/testthat/_snaps/model-fit-stats.md new file mode 100644 index 00000000..afe1b82d --- /dev/null +++ b/tests/testthat/_snaps/model-fit-stats.md @@ -0,0 +1,52 @@ +# blr_model_fit_stats prints the correct output + + Code + k + Output + Model Fit Statistics + --------------------------------------------------------------------------------- + Log-Lik Intercept Only: -115.644 Log-Lik Full Model: -80.118 + Deviance(196): 160.236 LR(3): 71.052 + Prob > LR: 0.000 + MCFadden's R2 0.307 McFadden's Adj R2: 0.273 + ML (Cox-Snell) R2: 0.299 Cragg-Uhler(Nagelkerke) R2: 0.436 + McKelvey & Zavoina's R2: 0.518 Efron's R2: 0.330 + Count R2: 0.810 Adj Count R2: 0.283 + BIC: 181.430 AIC: 168.236 + --------------------------------------------------------------------------------- + + +# blr_multi_model_fit_stats prints the correct output + + Code + k + Output + Measures Model 1 Model 2 + loglik_null Log-Lik Intercept Only -115.644 -115.644 + loglik_model Log-Lik Full Model -80.118 -84.570 + m_deviance Deviance 160.236 169.141 + lr_ratio LR 71.052 62.148 + lr_pval Prob > LR 0.000 0.000 + mcfadden MCFadden's R2 0.307 0.269 + adj_mcfadden McFadden's Adj R2 0.273 0.225 + m_aic ML (Cox-Snell) R2 168.236 179.141 + cox_snell Cragg-Uhler(Nagelkerke) R2 0.299 0.267 + m_bic McKelvey & Zavoina's R2 181.430 195.632 + mckelvey Efron's R2 0.518 0.440 + effron Count R2 0.330 0.281 + nagelkerke Adj Count R2 0.436 0.390 + count_r2 AIC 0.810 0.785 + count_adj BIC 0.283 0.189 + +# blr_lr_test prints the correct output + + Code + k + Output + Likelihood Ratio Test + ------------------------------ + Chi-Square DF Pr > ChiSq + ------------------------------ + 71.0525 3 0.0000 + ------------------------------ + diff --git a/tests/testthat/_snaps/model-validation.md b/tests/testthat/_snaps/model-validation.md new file mode 100644 index 00000000..1468ae18 --- /dev/null +++ b/tests/testthat/_snaps/model-validation.md @@ -0,0 +1,33 @@ +# prints the correct output + + Code + k + Output + Confusion Matrix and Statistics + + Reference + Prediction 0 1 + 0 125 16 + 1 22 37 + + + Accuracy : 0.8100 + No Information Rate : 0.7350 + + Kappa : 0.5293 + + McNemars's Test P-Value : 0.4173 + + Sensitivity : 0.6981 + Specificity : 0.8503 + Pos Pred Value : 0.6271 + Neg Pred Value : 0.8865 + Prevalence : 0.2650 + Detection Rate : 0.1850 + Detection Prevalence : 0.2950 + Balanced Accuracy : 0.7742 + Precision : 0.6271 + Recall : 0.6981 + + 'Positive' Class : 1 + diff --git a/tests/testthat/_snaps/stepwise-aic.md b/tests/testthat/_snaps/stepwise-aic.md new file mode 100644 index 00000000..47a00b75 --- /dev/null +++ b/tests/testthat/_snaps/stepwise-aic.md @@ -0,0 +1,43 @@ +# output from forward variable selection is as expected + + Code + blr_step_aic_both(model) + Output + Stepwise Selection Method + ------------------------- + + Candidate Terms: + + 1 . x1 + 2 . x2 + 3 . x3 + 4 . x4 + 5 . x5 + 6 . x6 + + + Variables Entered/Removed: + + - x6 added + - x1 added + - x3 added + - x2 added + - x6 removed + - x5 added + + No more variables to be added or removed. + + + Stepwise Summary + ----------------------------------------------------------- + Variable Method AIC BIC Deviance + ----------------------------------------------------------- + x6 addition 18869.627 18885.434 18865.627 + x1 addition 18571.376 18595.087 18565.376 + x3 addition 18016.724 18048.338 18008.724 + x2 addition 16642.374 16681.891 16632.374 + x6 removal 16640.653 16672.267 16632.653 + x5 addition 16639.219 16678.736 16629.219 + ----------------------------------------------------------- + + diff --git a/tests/testthat/test-backward-aic.R b/tests/testthat/test-backward-aic.R new file mode 100644 index 00000000..2585357b --- /dev/null +++ b/tests/testthat/test-backward-aic.R @@ -0,0 +1,10 @@ +test_that("output from backward variable elimination is as expected", { + + model <- glm( + honcomp ~ female + read + science + math + prog + socst, + data = hsb2, family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_aic_backward(model)) + +}) diff --git a/tests/testthat/test-backward-elimination.R b/tests/testthat/test-backward-elimination.R index 302106f5..3b3d9294 100644 --- a/tests/testthat/test-backward-elimination.R +++ b/tests/testthat/test-backward-elimination.R @@ -1,5 +1,3 @@ -context("test-backward-elimination.R") - test_that("output from backward variable elimination is as expected", { model <- glm( honcomp ~ female + read + science + math + prog + socst, @@ -9,7 +7,7 @@ test_that("output from backward variable elimination is as expected", { actual <- blr_step_aic_backward(model)$predictors expected <- c("prog", "socst") - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from backward variable p elimination is as expected", { @@ -21,494 +19,6 @@ test_that("output from backward variable p elimination is as expected", { actual <- blr_step_p_backward(model)$removed expected <- c("prog", "socst") - expect_equivalent(actual, expected) -}) - -test_that("print output from backward variable elimination is as expected", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - x <- cat("Backward Elimination Method ---------------------------- - -Candidate Terms: - -1 . female -2 . read -3 . science -4 . math -5 . prog -6 . socst - - -Variables Removed: - -✖ prog -✖ socst - - - Backward Elimination Summary --------------------------------------------- -Variable AIC BIC Deviance --------------------------------------------- -Full Model 162.424 188.811 146.424 -prog 158.953 178.743 146.953 -socst 157.286 173.777 147.286 ---------------------------------------------") - - expect_output(print(blr_step_aic_backward(model)), x) - -}) - -test_that("print output from backward variable p elimination is as expected", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - x <- cat("Backward Elimination Method ---------------------------- - -Candidate Terms: - -1 . female1 -2 . read -3 . science -4 . math -5 . prog2 -6 . prog3 -7 . socst - -We are eliminating variables based on p value... - -Variables Removed: - -✖ prog3 -✖ prog2 -✖ socst - -No more variables satisfy the condition of p value = 0.3 - - -Final Model Output ------------------- - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 200 199 195 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 147 1 53 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8835 Somers' D 0.7669 -% Discordant 0.1165 Gamma 0.7669 -% Tied 0.0000 Tau-a 0.3003 -Pairs 7791 c 0.8835 ---------------------------------------------------------------- - - - - Elimination Summary ----------------------------------------------------- - Variable -Step Removed AIC BIC Deviance ----------------------------------------------------- - 1 prog3 160.7102 183.7984 146.7102 - 2 prog2 158.9527 178.7427 146.9527 - 3 socst 157.2856 173.7772 147.2856 -----------------------------------------------------") - - expect_output(print(blr_step_p_backward(model)), x) - + expect_equal(actual, expected) }) -test_that("output from backward variable elimination is as expected when details == TRUE", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - x <- cat("Backward Elimination Method ---------------------------- - -Candidate Terms: - -1 . female -2 . read -3 . science -4 . math -5 . prog -6 . socst - - Step 0: AIC = 162.4241 - honcomp ~ female + read + science + math + prog + socst - -------------------------------------------------- -Variable DF AIC BIC Deviance -------------------------------------------------- -prog 1 158.953 178.743 146.953 -socst 1 160.745 183.834 146.745 -read 1 163.394 186.482 149.394 -science 1 163.815 186.903 149.815 -female 1 169.570 192.658 155.570 -math 1 170.017 193.105 156.017 -------------------------------------------------- - - -✖ prog - - - Step 1 : AIC = 158.9527 - honcomp ~ female + read + science + math + socst - -------------------------------------------------- -Variable DF AIC BIC Deviance -------------------------------------------------- -socst 1 157.286 173.777 147.286 -science 1 159.941 176.432 149.941 -read 1 160.307 176.798 150.307 -female 1 166.114 182.606 156.114 -math 1 168.669 185.161 158.669 -------------------------------------------------- - -✖ socst - - - Step 2 : AIC = 157.2856 - honcomp ~ female + read + science + math - -------------------------------------------------- -Variable DF AIC BIC Deviance -------------------------------------------------- -science 1 158.420 171.613 150.420 -read 1 160.658 173.851 152.658 -female 1 164.988 178.181 156.988 -math 1 168.236 181.430 160.236 -------------------------------------------------- - -No more variables to be removed. - -Variables Removed: - -✖ prog -✖ socst - - -Final Model Output ------------------- - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 200 199 195 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 147 1 53 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8835 Somers' D 0.7669 -% Discordant 0.1165 Gamma 0.7669 -% Tied 0.0000 Tau-a 0.3003 -Pairs 7791 c 0.8835 ---------------------------------------------------------------- - - - - Backward Elimination Summary --------------------------------------------- -Variable AIC BIC Deviance --------------------------------------------- -Full Model 162.424 188.811 146.424 -prog 158.953 178.743 146.953 -socst 157.286 173.777 147.286 ---------------------------------------------") - - expect_output(print(blr_step_aic_backward(model, details = TRUE)), x) - -}) - -test_that("output from backward variable elimination p is as expected when details == TRUE", { - - model <- glm( - honcomp ~ female + read + science + math + prog + socst, - data = hsb2, family = binomial(link = "logit") - ) - - x <- cat("Backward Elimination Method ---------------------------- - -Candidate Terms: - -1 . female1 -2 . read -3 . science -4 . math -5 . prog2 -6 . prog3 -7 . socst - -We are eliminating variables based on p value... - -✖ prog3 - -Backward Elimination: Step 1 - - Variable prog3 Removed - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 200 199 193 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 147 1 53 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -14.7222 2.2246 -6.6180 0.0000 - female1 1 1.3547 0.4659 2.9075 0.0036 - read 1 0.0541 0.0311 1.7420 0.0815 - science 1 0.0605 0.0341 1.7729 0.0762 - math 1 0.1033 0.0357 2.8968 0.0038 - prog2 1 0.2382 0.4839 0.4922 0.6226 - socst 1 0.0135 0.0273 0.4953 0.6204 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8845 Somers' D 0.7690 -% Discordant 0.1155 Gamma 0.7690 -% Tied 0.0000 Tau-a 0.3011 -Pairs 7791 c 0.8845 ---------------------------------------------------------------- - - - -✖ prog2 - -Backward Elimination: Step 2 - - Variable prog2 Removed - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 200 199 194 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 147 1 53 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -14.8131 2.2101 -6.7024 0.0000 - female1 1 1.3351 0.4634 2.8813 0.0040 - read 1 0.0558 0.0309 1.8050 0.0711 - science 1 0.0561 0.0329 1.7036 0.0885 - math 1 0.1086 0.0342 3.1761 0.0015 - socst 1 0.0155 0.0270 0.5738 0.5661 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8822 Somers' D 0.7643 -% Discordant 0.1178 Gamma 0.7643 -% Tied 0.0000 Tau-a 0.2992 -Pairs 7791 c 0.8822 ---------------------------------------------------------------- - - - -✖ socst - -Backward Elimination: Step 3 - - Variable socst Removed - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 200 199 195 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 147 1 53 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8835 Somers' D 0.7669 -% Discordant 0.1165 Gamma 0.7669 -% Tied 0.0000 Tau-a 0.3003 -Pairs 7791 c 0.8835 ---------------------------------------------------------------- - - - - -No more variables satisfy the condition of p value = 0.3 - - -Variables Removed: - -✖ prog3 -✖ prog2 -✖ socst - - -Final Model Output ------------------- - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 200 199 195 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 147 1 53 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -14.5773 2.1568 -6.7589 0.0000 - female1 1 1.3622 0.4605 2.9580 0.0031 - read 1 0.0631 0.0281 2.2455 0.0247 - science 1 0.0569 0.0326 1.7429 0.0814 - math 1 0.1113 0.0338 3.2992 0.0010 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8835 Somers' D 0.7669 -% Discordant 0.1165 Gamma 0.7669 -% Tied 0.0000 Tau-a 0.3003 -Pairs 7791 c 0.8835 ---------------------------------------------------------------- - - - - Elimination Summary ----------------------------------------------------- - Variable -Step Removed AIC BIC Deviance ----------------------------------------------------- - 1 prog3 160.7102 183.7984 146.7102 - 2 prog2 158.9527 178.7427 146.9527 - 3 socst 157.2856 173.7772 147.2856 -----------------------------------------------------") - - expect_output(print(blr_step_p_backward(model, details = TRUE)), x) - -}) - - diff --git a/tests/testthat/test-bivariate-analysis.R b/tests/testthat/test-bivariate-analysis.R index be94a298..1b08feb4 100644 --- a/tests/testthat/test-bivariate-analysis.R +++ b/tests/testthat/test-bivariate-analysis.R @@ -1,24 +1,13 @@ -context("test-bivariate-analysis.R") - test_that("output from blr_bivariate_analysis is as expected", { k <- blr_bivariate_analysis(hsb2, honcomp, female, prog) - expect_equivalent(k$iv, c(0.1023, 0.4329)) - expect_equivalent(round(k$likelihood_ratio, 2), c(3.94, 16.15)) + expect_equal(k$iv, c(0.1023, 0.4329)) + expect_equal(round(k$likelihood_ratio, 2), c(3.94, 16.15)) }) test_that("blr_bivariate_analysis prints the correct output", { k <- blr_bivariate_analysis(hsb2, honcomp, female, prog) - - x <- cat(" Bivariate Analysis ---------------------------------------------------------------------- - Variable Information Value LR Chi Square LR DF LR p-value - --------------------------------------------------------------------- - female 0.10 3.9350 1 0.0473 - prog 0.43 16.1450 2 3e-04 - ---------------------------------------------------------------------") - - expect_output(print(k), x) + expect_snapshot(k) }) test_that("output from blr_segment is as expected", { @@ -27,23 +16,12 @@ test_that("output from blr_segment is as expected", { actual <- rev(k$segment_data[['1s%']])[1] expected <- c(0.22) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("blr_segment prints the correct output", { k <- blr_segment(hsb2, honcomp, race) - - x <- cat("Event By Attributes -------------------- - race 1s% - ------------------- - 1 0.01 - 2 0.02 - 3 0.01 - 4 0.22 - -------------------") - - expect_output(print(k), x) + expect_snapshot(k) }) test_that("output from blr_twoway_segment is as expected", { @@ -51,26 +29,12 @@ test_that("output from blr_twoway_segment is as expected", { k <- blr_segment_twoway(hsb2, honcomp, prog, race) actual <- unname(round(k$twoway_segment[, 4], 3)) expected <- c(0.035, 0.165, 0.020) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("blr_twoway_segment prints the correct output", { k <- blr_segment_twoway(hsb2, honcomp, prog, race) - - x <- cat( - " race ------------------------------------------ - prog 1 2 3 4 - ----------------------------------------- - 1 0.000 0.000 0.000 0.035 - ----------------------------------------- - 2 0.010 0.020 0.005 0.165 - ----------------------------------------- - 3 0.000 0.005 0.005 0.020 - -----------------------------------------" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) test_that("output from blr_segment_dist is as expected", { @@ -78,25 +42,12 @@ test_that("output from blr_segment_dist is as expected", { k <- blr_segment_dist(hsb2, honcomp, race) actual <- rev(k$dist_table[['1s%']])[1] expected <- c(0.22) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("blr_twoway_segment prints the correct output", { k <- blr_segment_dist(hsb2, honcomp, race) - - x <- cat( - " Event Segmentation -------------------------------------- - race n 1s n% 1s% - ------------------------------------- - 1 24 2 0.12 0.01 - 2 11 5 0.06 0.02 - 3 20 2 0.10 0.01 - 4 145 44 0.72 0.22 - -------------------------------------" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) @@ -109,106 +60,11 @@ test_that("output from blr_woe_iv is as expected", { test_that("blr_woe_iv prints the correct output", { k <- blr_woe_iv(hsb2, prog, honcomp) - - x <- cat( - " Weight of Evidence -------------------------------------------------------------------------- -levels count_0s count_1s dist_0s dist_1s woe iv -------------------------------------------------------------------------- - 1 38 7 0.26 0.13 0.67 0.08 - 2 65 40 0.44 0.75 -0.53 0.17 - 3 44 6 0.30 0.11 0.97 0.18 -------------------------------------------------------------------------- - - Information Value ------------------------------ -Variable Information Value ------------------------------ - prog 0.4329 ------------------------------") - - expect_output(print(k), x) + expect_snapshot(k) }) test_that("output from blr_woe_iv_stats is as expected", { - k <- blr_woe_iv_stats(hsb2, honcomp, prog, race, female, schtyp) - - x <- cat("Variable: prog - - Weight of Evidence -------------------------------------------------------------------------- -levels count_0s count_1s dist_0s dist_1s woe iv -------------------------------------------------------------------------- - 1 38 7 0.26 0.13 0.67 0.08 - 2 65 40 0.44 0.75 -0.53 0.17 - 3 44 6 0.30 0.11 0.97 0.18 -------------------------------------------------------------------------- - - Information Value ------------------------------ -Variable Information Value ------------------------------ - prog 0.4329 ------------------------------ - - -Variable: race - - Weight of Evidence -------------------------------------------------------------------------- -levels count_0s count_1s dist_0s dist_1s woe iv -------------------------------------------------------------------------- - 1 22 2 0.15 0.04 1.38 0.15 - 2 6 5 0.04 0.09 -0.84 0.04 - 3 18 2 0.12 0.04 1.18 0.10 - 4 101 44 0.69 0.83 -0.19 0.03 -------------------------------------------------------------------------- - - Information Value ------------------------------ -Variable Information Value ------------------------------ - race 0.326 ------------------------------ - - -Variable: female - - Weight of Evidence -------------------------------------------------------------------------- -levels count_0s count_1s dist_0s dist_1s woe iv -------------------------------------------------------------------------- - 0 73 18 0.50 0.34 0.38 0.06 - 1 74 35 0.50 0.66 -0.27 0.04 -------------------------------------------------------------------------- - - Information Value ------------------------------ -Variable Information Value ------------------------------ - female 0.1023 ------------------------------ - - -Variable: schtyp - - Weight of Evidence ------------------------------------------------------------------------- -levels count_0s count_1s dist_0s dist_1s woe iv ------------------------------------------------------------------------- - 1 123 45 0.84 0.85 -0.01 0.00 - 2 24 8 0.16 0.15 0.08 0.00 ------------------------------------------------------------------------- - - Information Value ------------------------------ -Variable Information Value ------------------------------ - schtyp 0.0012 ------------------------------") - - expect_output(print(k), x) - + expect_snapshot(k) }) diff --git a/tests/testthat/test-blr-gains-table.R b/tests/testthat/test-blr-gains-table.R index 61df9fc0..649da60c 100644 --- a/tests/testthat/test-blr-gains-table.R +++ b/tests/testthat/test-blr-gains-table.R @@ -1,5 +1,3 @@ -context("test-blr-gains-table.R") - model <- glm( honcomp ~ female + read + science, data = hsb2, family = binomial(link = "logit") @@ -12,7 +10,7 @@ test_that("output from blr_gains_table is as expected", { accu <- round(mean(gtable$gains_table$accuracy), 2) actual <- c(sens, spec, accu) expected <- c(80.94, 54.35, 61.40) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) diff --git a/tests/testthat/test-blr-lrtest.R b/tests/testthat/test-blr-lrtest.R index 5ade134a..c1074205 100644 --- a/tests/testthat/test-blr-lrtest.R +++ b/tests/testthat/test-blr-lrtest.R @@ -1,6 +1,4 @@ -context("test-blr-lrtest.R") - -test_that("blr_test_lr throws an error when the model is not an object of\n class glm", { +test_that("blr_test_lr throws an error when the model is not an object of class glm", { model1 <- glm( honcomp ~ 1, data = hsb2, diff --git a/tests/testthat/test-blr-pairs.R b/tests/testthat/test-blr-pairs.R index 56c9eb89..f3f7e36f 100644 --- a/tests/testthat/test-blr-pairs.R +++ b/tests/testthat/test-blr-pairs.R @@ -1,5 +1,3 @@ -context("test-blr-pairs.R") - test_that("output from blr_pairs is as expected", { model <- glm( honcomp ~ female + read + science, data = blorr::hsb2, diff --git a/tests/testthat/test-blr-plots.R b/tests/testthat/test-blr-plots.R index f5dfe85b..50bad2a7 100644 --- a/tests/testthat/test-blr-plots.R +++ b/tests/testthat/test-blr-plots.R @@ -1,5 +1,3 @@ -context("test-blr-plots.R") - model <- glm( honcomp ~ female + read + science, data = hsb2, family = binomial(link = "logit") diff --git a/tests/testthat/test-blr-regress.R b/tests/testthat/test-blr-regress.R index 6c7ce73b..b1fa951a 100644 --- a/tests/testthat/test-blr-regress.R +++ b/tests/testthat/test-blr-regress.R @@ -1,5 +1,3 @@ -context("test-blr-regress.R") - test_that("output from blr_regress is as expected", { model <- glm( honcomp ~ female + read + science, data = hsb2, @@ -8,54 +6,5 @@ test_that("output from blr_regress is as expected", { k <- blr_regress(model, odd_conf_limit = TRUE) - x <- cat( - "✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Computing odds ratio estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 200 199 196 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 147 1 53 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -12.7772 1.9755 -6.4677 0.0000 - female1 1 1.4825 0.4474 3.3139 9e-04 - read 1 0.1035 0.0258 4.0186 1e-04 - science 1 0.0948 0.0305 3.1129 0.0019 ------------------------------------------------------------------ - - Odds Ratio Estimates ---------------------------------------------------------- - Effects Estimate 95% Wald Conf. Limit ---------------------------------------------------------- - female1 4.4039 1.8955 11.0521 - read 1.1091 1.0569 1.1699 - science 1.0994 1.0377 1.1702 ---------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8561 Somers' D 0.7147 -% Discordant 0.1425 Gamma 0.7136 -% Tied 0.0014 Tau-a 0.2794 -Pairs 7791 c 0.8568 ----------------------------------------------------------------" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) diff --git a/tests/testthat/test-coll-diag.R b/tests/testthat/test-coll-diag.R index d1375d65..dc685960 100644 --- a/tests/testthat/test-coll-diag.R +++ b/tests/testthat/test-coll-diag.R @@ -1,5 +1,3 @@ -context("test-coll-diag.R") - test_that("output from blr_vif_tol is as expected", { model <- glm( honcomp ~ female + read + science, data = hsb2, @@ -9,7 +7,7 @@ test_that("output from blr_vif_tol is as expected", { actual <- round(blr_vif_tol(model)[['VIF']], 2) expected <- c(1.02, 1.66, 1.68) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from blr_eigen_cindex is as expected", { @@ -21,7 +19,7 @@ test_that("output from blr_eigen_cindex is as expected", { actual <- round(blr_eigen_cindex(model)[['Eigenvalue']], 2) expected <- c(3.57, 0.39, 0.02, 0.01) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("blr_coll_diag prints the correct output", { @@ -32,23 +30,5 @@ test_that("blr_coll_diag prints the correct output", { k <- blr_coll_diag(model) - x <- cat( - "Tolerance and Variance Inflation Factor ---------------------------------------- - Variable Tolerance VIF -1 female1 0.9824347 1.017879 -2 read 0.6021370 1.660752 -3 science 0.5939847 1.683545 - - -Eigenvalue and Condition Index ------------------------------- - Eigenvalue Condition Index intercept female1 read science -1 3.57391760 1.000000 3.500782e-06 2.232611e-05 0.0006577134 0.0009448623 -2 0.39409893 3.011408 5.155657e-06 8.559696e-04 0.0015266309 0.0025603607 -3 0.01888407 13.757025 1.632498e-03 4.397949e-05 0.1143698337 0.0545537252 -4 0.01309940 16.517583 5.619292e-05 1.312420e-05 0.2758987745 0.5468553525" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) diff --git a/tests/testthat/test-forward-aic.R b/tests/testthat/test-forward-aic.R new file mode 100644 index 00000000..eb51e549 --- /dev/null +++ b/tests/testthat/test-forward-aic.R @@ -0,0 +1,10 @@ +test_that("output from forward variable selection is as expected", { + + model <- glm( + honcomp ~ female + read + science, data = hsb2, + family = binomial(link = "logit") + ) + + expect_snapshot(blr_step_aic_forward(model)) + +}) diff --git a/tests/testthat/test-forward-selection.R b/tests/testthat/test-forward-selection.R index 4850d2e8..d783ee02 100644 --- a/tests/testthat/test-forward-selection.R +++ b/tests/testthat/test-forward-selection.R @@ -1,5 +1,3 @@ -context("test-forward-selection.R") - test_that("output from forward variable selection is as expected", { model <- glm( honcomp ~ female + read + science, data = hsb2, @@ -9,7 +7,7 @@ test_that("output from forward variable selection is as expected", { actual <- blr_step_aic_forward(model)$predictors expected <- c("read", "female", "science") - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from forward variable p selection is as expected", { @@ -21,335 +19,6 @@ test_that("output from forward variable p selection is as expected", { actual <- blr_step_p_forward(model)$predictors expected <- c("read", "female", "science") - expect_equivalent(actual, expected) -}) - - -test_that("output from forward variable selection is as expected", { - - model <- glm( - honcomp ~ female + read + science, data = hsb2, - family = binomial(link = "logit") - ) - - x <- cat("Forward Selection Method ------------------------- - -Candidate Terms: - -1 . female -2 . read -3 . science - - -Variables Entered: - -✔ read -✔ female -✔ science - - Selection Summary ---------------------------------------------------- -Step Variable AIC BIC Deviance ---------------------------------------------------- -1 read 183.063 189.660 179.063 -2 female 176.887 176.887 176.887 -3 science 168.236 168.236 168.236 ----------------------------------------------------") - - expect_output(print(blr_step_aic_forward(model)), x) - + expect_equal(actual, expected) }) -test_that("output from forward variable p selection is as expected", { - - model <- glm( - honcomp ~ female + read + science, data = hsb2, - family = binomial(link = "logit") - ) - - x <- cat("Forward Selection Method ---------------------------- - -Candidate Terms: - -1. female1 -2. read -3. science - -We are selecting variables based on p value... - -Variables Entered: - -✔ read -✔ science -✔ female1 - - -Final Model Output ------------------- - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 372 371 368 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 290 1 82 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -11.5804 1.3980 -8.2836 0.0000 - read 1 0.1000 0.0210 4.7651 0.0000 - science 1 0.0798 0.0246 3.2390 0.0012 - female1 1 0.9324 0.3126 2.9826 0.0029 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8259 Somers' D 0.6607 -% Discordant 0.1687 Gamma 0.6572 -% Tied 0.0054 Tau-a 0.2265 -Pairs 23780 c 0.8286 ---------------------------------------------------------------- - - - Selection Summary ----------------------------------------------------- - Variable -Step Entered AIC BIC Deviance ----------------------------------------------------- - 1 read 316.3831 324.2209 312.3831 - 2 science 310.5294 322.2861 304.5294 - 3 female1 303.0855 318.7611 295.0855 -----------------------------------------------------") - - expect_output(print(blr_step_p_forward(model)), x) - -}) - -test_that("output from forward variable selection is as expected", { - - model <- glm( - honcomp ~ female + read + science, data = hsb2, - family = binomial(link = "logit") - ) - - x <- cat("Forward Selection Method ---------------------------- - -Candidate Terms: - -1. female1 -2. read -3. science - -We are selecting variables based on p value... - - -Forward Selection: Step 1 - -✔ read - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 372 371 370 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 290 1 82 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -8.5704 0.9875 -8.6789 0.0000 - read 1 0.1340 0.0172 7.7741 0.0000 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.7771 Somers' D 0.6582 -% Discordant 0.1602 Gamma 0.6169 -% Tied 0.0627 Tau-a 0.2126 -Pairs 23780 c 0.8085 ---------------------------------------------------------------- - - - - -Forward Selection: Step 2 - -✔ science - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 372 371 369 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 290 1 82 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -10.1484 1.2142 -8.3581 0.0000 - read 1 0.0990 0.0207 4.7938 0.0000 - science 1 0.0643 0.0233 2.7592 0.0058 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8181 Somers' D 0.6510 -% Discordant 0.1729 Gamma 0.6452 -% Tied 0.0090 Tau-a 0.2223 -Pairs 23780 c 0.8226 ---------------------------------------------------------------- - - - - -Forward Selection: Step 3 - -✔ female1 - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 372 371 368 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 290 1 82 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -11.5804 1.3980 -8.2836 0.0000 - read 1 0.1000 0.0210 4.7651 0.0000 - science 1 0.0798 0.0246 3.2390 0.0012 - female1 1 0.9324 0.3126 2.9826 0.0029 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8259 Somers' D 0.6607 -% Discordant 0.1687 Gamma 0.6572 -% Tied 0.0054 Tau-a 0.2265 -Pairs 23780 c 0.8286 ---------------------------------------------------------------- - - - - - -Variables Entered: - -✔ read -✔ science -✔ female1 - - -Final Model Output ------------------- - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview ------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence ------------------------------------------------------------------------- - data honcomp 372 371 368 TRUE ------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 290 1 82 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------ - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------ -(Intercept) 1 -11.5804 1.3980 -8.2836 0.0000 - read 1 0.1000 0.0210 4.7651 0.0000 - science 1 0.0798 0.0246 3.2390 0.0012 - female1 1 0.9324 0.3126 2.9826 0.0029 ------------------------------------------------------------------ - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8259 Somers' D 0.6607 -% Discordant 0.1687 Gamma 0.6572 -% Tied 0.0054 Tau-a 0.2265 -Pairs 23780 c 0.8286 ---------------------------------------------------------------- - - - Selection Summary ----------------------------------------------------- - Variable -Step Entered AIC BIC Deviance ----------------------------------------------------- - 1 read 316.3831 324.2209 312.3831 - 2 science 310.5294 322.2861 304.5294 - 3 female1 303.0855 318.7611 295.0855 -----------------------------------------------------") - - expect_output(print(blr_step_aic_forward(model, details = TRUE)), x) - -}) - - diff --git a/tests/testthat/test-gini-index.R b/tests/testthat/test-gini-index.R index 0a132209..5731dfe8 100644 --- a/tests/testthat/test-gini-index.R +++ b/tests/testthat/test-gini-index.R @@ -1,5 +1,3 @@ -context("test-gini-index.R") - test_that("output from blr_gini_index is as expected", { model <- glm( honcomp ~ female + read + science, data = blorr::hsb2, diff --git a/tests/testthat/test-hosmer-lemeshow.R b/tests/testthat/test-hosmer-lemeshow.R index ac02adea..c7609ce6 100644 --- a/tests/testthat/test-hosmer-lemeshow.R +++ b/tests/testthat/test-hosmer-lemeshow.R @@ -1,5 +1,3 @@ -context("test-hosmer-lemeshow.R") - test_that("output from blr_hosmer_lemeshow_test is as expected", { model <- glm( honcomp ~ race + read + science, data = hsb2, @@ -19,31 +17,5 @@ test_that("hosmer lemeshow test prints the correct output", { k <- blr_test_hosmer_lemeshow(model) - x <- cat( - " Partition for the Hosmer & Lemeshow Test --------------------------------------------------------------- - def = 1 def = 0 - Group Total Observed Expected Observed Expected - -------------------------------------------------------------- - 1 20 0 0.16 20 19.84 - 2 20 0 0.53 20 19.47 - 3 20 2 0.99 18 19.01 - 4 20 1 1.64 19 18.36 - 5 21 3 2.72 18 18.28 - 6 19 3 4.05 16 14.95 - 7 20 7 6.50 13 13.50 - 8 20 10 8.90 10 11.10 - 9 20 13 11.49 7 8.51 - 10 20 14 16.02 6 3.98 - -------------------------------------------------------------- - - Goodness of Fit Test - ------------------------------ - Chi-Square DF Pr > ChiSq - ------------------------------ - 4.4998 8 0.8095 - ------------------------------" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) diff --git a/tests/testthat/test-linktest.R b/tests/testthat/test-linktest.R index 9b5ad244..c9b50db5 100644 --- a/tests/testthat/test-linktest.R +++ b/tests/testthat/test-linktest.R @@ -1,5 +1,3 @@ -context("test-linktest.R") - test_that("output from blr_linktest is as expected", { model <- glm( @@ -9,5 +7,5 @@ test_that("output from blr_linktest is as expected", { actual <- round(unname(blr_linktest(model)$coefficients[, 1]), 2) expected <- c(0.04, 0.94, -0.04) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) diff --git a/tests/testthat/test-model-fit-stats.R b/tests/testthat/test-model-fit-stats.R index 2e1fb8dc..57ea66c2 100644 --- a/tests/testthat/test-model-fit-stats.R +++ b/tests/testthat/test-model-fit-stats.R @@ -1,5 +1,3 @@ -context("test-model-fit-stats.R") - # regression model <- glm( honcomp ~ female + read + science, data = hsb2, @@ -89,26 +87,9 @@ test_that("output from blr_effron_rsq is as expected", { expect_equal(actual, expected) }) - - test_that("blr_model_fit_stats prints the correct output", { k <- blr_model_fit_stats(model) - - x <- cat( - " Model Fit Statistics ---------------------------------------------------------------------------------- - Log-Lik Intercept Only: -115.644 Log-Lik Full Model: -80.118 - Deviance(196): 160.236 LR(3): 71.052 - Prob > LR: 0.000 - MCFadden's R2 0.307 McFadden's Adj R2: 0.273 - ML (Cox-Snell) R2: 0.299 Cragg-Uhler(Nagelkerke) R2: 0.436 - McKelvey & Zavoina's R2: 0.518 Efron's R2: 0.330 - Count R2: 0.810 Adj Count R2: 0.283 - BIC: 181.430 AIC: 168.236 - ---------------------------------------------------------------------------------" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) test_that("blr_multi_model_fit_stats prints the correct output", { @@ -118,41 +99,11 @@ test_that("blr_multi_model_fit_stats prints the correct output", { ) k <- blr_multi_model_fit_stats(model, model1) - - x <- cat( - " Measures Model 1 Model 2 -1 Log-Lik Intercept Only -115.644 -115.644 - 2 Log-Lik Full Model: -80.118 -84.570 - 3 Deviance 160.236 169.141 - 4 LR 71.052 62.148 - 5 Prob > LR: 0.000 0.000 - 6 MCFadden's R2 0.307 0.269 - 7 McFadden's Adj R2: 0.273 0.225 - 8 ML (Cox-Snell) R2: 0.299 0.267 - 9 Cragg-Uhler(Nagelkerke) R2: 0.436 0.390 - 10 McKelvey & Zavoina's R2: 0.518 0.440 - 11 Efron's R2: 0.330 0.281 - 12 Count R2: 0.810 0.785 - 13 Adj Count R2: 0.283 0.189 - 14 AIC: 168.236 179.141 - 15 BIC: 181.430 195.632" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) test_that("blr_lr_test prints the correct output", { k <- blr_test_lr(model) - - x <- cat( - " Likelihood Ratio Test ------------------------------- - Chi-Square DF Pr > ChiSq - ------------------------------ - 71.0525 3 0.0000 - ------------------------------" - ) - - expect_output(print(k), x) + expect_snapshot(k) }) diff --git a/tests/testthat/test-model-validation.R b/tests/testthat/test-model-validation.R index ba49e603..d5a6279a 100644 --- a/tests/testthat/test-model-validation.R +++ b/tests/testthat/test-model-validation.R @@ -1,5 +1,3 @@ -context('test-blr-confusion-matrix') - model <- glm( honcomp ~ female + read + science, data = hsb2, family = binomial(link = "logit") @@ -8,36 +6,7 @@ model <- glm( test_that("prints the correct output", { k <- blr_confusion_matrix(model, cutoff = 0.4) - - x <- cat("Confusion Matrix and Statistics - - Reference -Prediction 0 1 - 0 125 16 - 1 22 37 - - - Accuracy : 0.8100 - No Information Rate : 0.7350 - - Kappa : 0.5293 - -McNemars's Test P-Value : 0.4173 - - Sensitivity : 0.6981 - Specificity : 0.8503 - Pos Pred Value : 0.6271 - Neg Pred Value : 0.8865 - Prevalence : 0.2650 - Detection Rate : 0.1850 - Detection Prevalence : 0.2950 - Balanced Accuracy : 0.7742 - Precision : 0.6271 - Recall : 0.6981 - - 'Positive' Class : 1") - - expect_output(print(k), x) + expect_snapshot(k) }) diff --git a/tests/testthat/test-stepwise-aic.R b/tests/testthat/test-stepwise-aic.R new file mode 100644 index 00000000..2a0c4fe6 --- /dev/null +++ b/tests/testthat/test-stepwise-aic.R @@ -0,0 +1,6 @@ +test_that("output from forward variable selection is as expected", { + + model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) + expect_snapshot(blr_step_aic_both(model)) + +}) diff --git a/tests/testthat/test-stepwise-selection.R b/tests/testthat/test-stepwise-selection.R index b75fbf6e..0c3c7d3d 100644 --- a/tests/testthat/test-stepwise-selection.R +++ b/tests/testthat/test-stepwise-selection.R @@ -1,12 +1,10 @@ -context("test-stepwise-selection.R") - test_that("output from stepwise variable selection is as expected", { model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) actual <- blr_step_aic_both(model)$predictors expected <- c("x6", "x1", "x3", "x2", "x6", "x5") - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from stepwise variable p selection is as expected", { @@ -15,484 +13,6 @@ test_that("output from stepwise variable p selection is as expected", { actual <- blr_step_p_both(model)$orders expected <- c("x1", "x2", "x3", "x6", "x5", "x6") - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) -test_that("print output from forward variable selection is as expected", { - - model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) - - x <- cat("Stepwise Selection Method -------------------------- - -Candidate Terms: - -1 . x1 -2 . x2 -3 . x3 -4 . x4 -5 . x5 -6 . x6 - - -Variables Entered/Removed: - -✔ x6 -✔ x1 -✔ x3 -✔ x2 -✖ x6 -✔ x5 - -No more variables to be added or removed. - - Stepwise Summary ------------------------------------------------------------ -Variable Method AIC BIC Deviance ------------------------------------------------------------ -x6 addition 18869.627 18885.434 18865.627 -x1 addition 18571.376 18595.087 18565.376 -x3 addition 18016.724 18048.338 18008.724 -x2 addition 16642.374 16681.891 16632.374 -x6 removal 16640.653 16672.267 16632.653 -x5 addition 16639.219 16678.736 16629.219 ------------------------------------------------------------") - - expect_output(print(blr_step_aic_both(model)), x) - -}) - -test_that("print output from forward variable selection is as expected", { - - model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) - - x <- cat("Stepwise Selection Method ---------------------------- - -Candidate Terms: - -1. x1 -2. x2 -3. x3 -4. x4 -5. x5 -6. x6 - -We are selecting variables based on p value... - -Variables Entered/Removed: - -✔ x6 -✔ x1 -✔ x3 -✔ x2 -✔ x5 -✖ x6 - -No more variables to be added/removed. - - -Final Model Output ------------------- - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19995 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.5228 0.0287 -53.1302 0.0000 - x1 1 1.0276 0.0212 48.4927 0.0000 - x3 1 1.0260 0.0213 48.2799 0.0000 - x2 1 0.9807 0.0209 46.9690 0.0000 - x5 1 0.0357 0.0192 1.8531 0.0639 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8911 Somers' D 0.7821 -% Discordant 0.1089 Gamma 0.7821 -% Tied 0.0000 Tau-a 0.3911 -Pairs 99998319 c 0.8911 ---------------------------------------------------------------- - - - Stepwise Selection Summary ----------------------------------------------------------------------- - Added/ -Step Variable Removed AIC BIC C(p) ----------------------------------------------------------------------- - 1 x6 addition 18869.627 18885.434 18865.6270 - 2 x1 addition 18571.376 18595.087 18565.3760 - 3 x3 addition 18016.724 18048.338 18008.7240 - 4 x2 addition 16642.374 16681.891 16632.3740 - 5 x5 addition 16640.883 16688.304 16628.8830 - 6 x6 removal 16639.219 16678.736 16629.2190 -----------------------------------------------------------------------") - - expect_output(print(blr_step_p_both(model)), x) - -}) - -test_that("print output from forward variable p selection is as expected", { - - model <- glm(y ~ ., data = stepwise, family = binomial(link = 'logit')) - - x <- cat("Stepwise Selection Method ---------------------------- - -Candidate Terms: - -1. x1 -2. x2 -3. x3 -4. x4 -5. x5 -6. x6 - -We are selecting variables based on p value... - - -Stepwise Selection: Step 1 - -✔ x6 - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19998 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.1331 0.0242 -46.8217 0.0000 - x6 1 0.7490 0.0107 69.8309 0.0000 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8558 Somers' D 0.7115 -% Discordant 0.1442 Gamma 0.7115 -% Tied 0.0000 Tau-a 0.3558 -Pairs 99998319 c 0.8558 ---------------------------------------------------------------- - - - - -Stepwise Selection: Step 2 - -✔ x1 - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19997 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.1836 0.0248 -47.8070 0.0000 - x6 1 0.6619 0.0116 56.9586 0.0000 - x1 1 0.3595 0.0210 17.0908 0.0000 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8610 Somers' D 0.7220 -% Discordant 0.1390 Gamma 0.7220 -% Tied 0.0000 Tau-a 0.3610 -Pairs 99998319 c 0.8610 ---------------------------------------------------------------- - - - - -Stepwise Selection: Step 3 - -✔ x3 - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19996 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.2730 0.0257 -49.4449 0.0000 - x6 1 0.4865 0.0135 35.9577 0.0000 - x1 1 0.5367 0.0229 23.4089 0.0000 - x3 1 0.5331 0.0232 22.9908 0.0000 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8704 Somers' D 0.7407 -% Discordant 0.1296 Gamma 0.7407 -% Tied 0.0000 Tau-a 0.3704 -Pairs 99998319 c 0.8704 ---------------------------------------------------------------- - - - - -Stepwise Selection: Step 4 - -✔ x2 - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19995 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.5229 0.0287 -53.1387 0.0000 - x6 1 -0.0102 0.0193 -0.5290 0.5968 - x1 1 1.0381 0.0287 36.1728 0.0000 - x3 1 1.0365 0.0290 35.7651 0.0000 - x2 1 0.9910 0.0285 34.7112 0.0000 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8910 Somers' D 0.7820 -% Discordant 0.1090 Gamma 0.7820 -% Tied 0.0000 Tau-a 0.3910 -Pairs 99998319 c 0.8910 ---------------------------------------------------------------- - - - - -Stepwise Selection: Step 5 - -✔ x5 - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19994 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.5228 0.0287 -53.1294 0.0000 - x6 1 -0.0112 0.0193 -0.5790 0.5626 - x1 1 1.0388 0.0287 36.1852 0.0000 - x3 1 1.0374 0.0290 35.7813 0.0000 - x2 1 0.9919 0.0286 34.7282 0.0000 - x5 1 0.0360 0.0193 1.8680 0.0618 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8911 Somers' D 0.7821 -% Discordant 0.1089 Gamma 0.7821 -% Tied 0.0000 Tau-a 0.3911 -Pairs 99998319 c 0.8911 ---------------------------------------------------------------- - - - - -Stepwise Selection: Step 6 - -✖ x6 - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19995 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.5228 0.0287 -53.1302 0.0000 - x1 1 1.0276 0.0212 48.4927 0.0000 - x3 1 1.0260 0.0213 48.2799 0.0000 - x2 1 0.9807 0.0209 46.9690 0.0000 - x5 1 0.0357 0.0192 1.8531 0.0639 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8911 Somers' D 0.7821 -% Discordant 0.1089 Gamma 0.7821 -% Tied 0.0000 Tau-a 0.3911 -Pairs 99998319 c 0.8911 ---------------------------------------------------------------- - - - - -No more variables to be added/removed. - - -Final Model Output ------------------- - -✔ Creating model overview. -✔ Creating response profile. -✔ Extracting maximum likelihood estimates. -✔ Estimating concordant and discordant pairs. - - Model Overview -------------------------------------------------------------------------- -Data Set Resp Var Obs. Df. Model Df. Residual Convergence -------------------------------------------------------------------------- - data y 20000 19999 19995 TRUE -------------------------------------------------------------------------- - - Response Summary --------------------------------------------------------- -Outcome Frequency Outcome Frequency --------------------------------------------------------- - 0 10041 1 9959 --------------------------------------------------------- - - Maximum Likelihood Estimates ------------------------------------------------------------------- - Parameter DF Estimate Std. Error z value Pr(>|z|) ------------------------------------------------------------------- -(Intercept) 1 -1.5228 0.0287 -53.1302 0.0000 - x1 1 1.0276 0.0212 48.4927 0.0000 - x3 1 1.0260 0.0213 48.2799 0.0000 - x2 1 0.9807 0.0209 46.9690 0.0000 - x5 1 0.0357 0.0192 1.8531 0.0639 ------------------------------------------------------------------- - - Association of Predicted Probabilities and Observed Responses ---------------------------------------------------------------- -% Concordant 0.8911 Somers' D 0.7821 -% Discordant 0.1089 Gamma 0.7821 -% Tied 0.0000 Tau-a 0.3911 -Pairs 99998319 c 0.8911 ---------------------------------------------------------------- - - - Stepwise Selection Summary ----------------------------------------------------------------------- - Added/ -Step Variable Removed AIC BIC C(p) ----------------------------------------------------------------------- - 1 x6 addition 18869.627 18885.434 18865.6270 - 2 x1 addition 18571.376 18595.087 18565.3760 - 3 x3 addition 18016.724 18048.338 18008.7240 - 4 x2 addition 16642.374 16681.891 16632.3740 - 5 x5 addition 16640.883 16688.304 16628.8830 - 6 x6 removal 16639.219 16678.736 16629.2190 -----------------------------------------------------------------------") - - expect_output(print(blr_step_p_both(model, details = TRUE)), x) - -}) diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index 6d4fbba2..8443c01c 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -1,5 +1,3 @@ -context("test-utils.R") - # regression model <- glm( honcomp ~ female + read + science, data = hsb2, @@ -52,57 +50,57 @@ test_that("output from resp_profile is as expected", { test_that("predictor_names returns names of the predictors", { actual <- predictor_names(model) expected <- c("(Intercept)", "female1", "read", "science") - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from model_df is as expected", { actual <- predictor_df(model) expected <- c(1, 1, 1, 1) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from predictor_est is as expected", { actual <- round(predictor_est(model), 2) expected <- c(-12.78, 1.48, 0.10, 0.09) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from predictor_se is as expected", { actual <- round(predictor_se(model), 2) expected <- c(1.98, 0.45, 0.03, 0.03) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from predictor_zval is as expected", { actual <- round(predictor_zval(model), 2) expected <- c(-6.47, 3.31, 4.02, 3.11) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from predictor_pval is as expected", { actual <- round(predictor_pval(model), 5) expected <- c(0.00000, 0.00092, 0.00006, 0.00185) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from odds_effect is as expected", { actual <- odds_effect(model) expected <- c("female1", "read", "science") - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from odds_point is as expected", { actual <- round(odds_point(model), 2) expected <- c(4.40, 1.11, 1.10) - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from mll is as expected", { actual <- round(mll(model), 4) expected <- 160.2364 - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) test_that("output from model_class is as expected", { @@ -120,5 +118,5 @@ test_that("output from model_d_f is as expected", { test_that("output from extract_ll is as expected", { actual <- round(extract_ll(model), 4) expected <- 160.2364 - expect_equivalent(actual, expected) + expect_equal(actual, expected) }) diff --git a/vignettes/introduction.Rmd b/vignettes/introduction.Rmd index cd9f8d82..f935c920 100644 --- a/vignettes/introduction.Rmd +++ b/vignettes/introduction.Rmd @@ -180,7 +180,7 @@ blr_regress(y ~ age + duration + previous + housing + default + Model fit statistics are available to assess how well the model fits the data and to compare two different models.The output includes likelihood ratio test, AIC, BIC and a host of pseudo r-squared measures. You can read more about -pseudo r-squared at https://stats.idre.ucla.edu/other/mult-pkg/faq/general/faq-what-are-pseudo-r-squareds/. +pseudo r-squared [here](https://stats.oarc.ucla.edu/other/mult-pkg/faq/general/faq-what-are-pseudo-r-squareds/). #### Single Model