Skip to content

Commit

Permalink
Merge pull request #208 from rsquaredacademy/develop
Browse files Browse the repository at this point in the history
olsrr 0.6.0
  • Loading branch information
aravindhebbali authored Feb 12, 2024
2 parents 0b61e09 + f73abb8 commit 1a6b522
Show file tree
Hide file tree
Showing 81 changed files with 1,720 additions and 2,322 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
^debug\.log$
^\.github$
^CODE_OF_CONDUCT\.md$
^revdep$
76 changes: 21 additions & 55 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
# 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

Expand All @@ -22,63 +18,33 @@ jobs:
fail-fast: false
matrix:
config:
- {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: macOS-latest, r: 'release' }
- { os: windows-latest, r: 'release' }
- { 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: r-lib/actions/setup-r@v1
- uses: r-lib/actions/setup-pandoc@v2

- 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
43 changes: 13 additions & 30 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
@@ -1,48 +1,31 @@
# 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

jobs:
test-coverage:
runs-on: macOS-latest
runs-on: ubuntu-latest
env:
GITHUB_PAT: ${{ secrets.GITHUB_TOKEN }}

steps:
- uses: actions/checkout@v2

- uses: r-lib/actions/setup-r@v1

- 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
uses: actions/cache@v2
- uses: r-lib/actions/setup-r@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-
use-public-rspm: true

- name: Install dependencies
run: |
install.packages(c("remotes"))
remotes::install_deps(dependencies = TRUE)
remotes::install_cran("covr")
shell: Rscript {0}
- uses: r-lib/actions/setup-r-dependencies@v2
with:
extra-packages: any::covr
needs: coverage

- name: Test coverage
run: covr::codecov()
run: covr::codecov(quiet = FALSE)
shell: Rscript {0}
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ Imports:
gridExtra,
nortest,
stats,
utils
utils,
xplorerr
Suggests:
covr,
descriptr,
knitr,
rmarkdown,
testthat,
vdiffr,
xplorerr
vdiffr
License: MIT + file LICENSE
URL: https://olsrr.rsquaredacademy.com/, https://github.com/rsquaredacademy/olsrr
BugReports: https://github.com/rsquaredacademy/olsrr/issues
Encoding: UTF-8
LazyData: true
VignetteBuilder: knitr
RoxygenNote: 7.1.1
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Config/testthat/edition: 3
20 changes: 16 additions & 4 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,22 @@
# olsrr 0.5.3.9000
# olsrr 0.6.0

This is a minor release for bug fixes and other enhancements.

## New Features

- Force variables in/out in variable selection procedures
- Hierarchical selection
- Variable selection using r-squared and adjusted r-squared
- hierarchical selection can be enables when using `p` values as variable selection metric

## Enhancements

- force variables to be included or excluded from the model at all stages of variable selection
- Variable selection methods allow use of the following metrics:
- p value
- akaike information criterion (aic)
- schwarz bayesian criterion (sbc)
- sawa bayesian criterion (sbic)
- r-square
- adjusted r-square
- Choose threshold for determining influential observations in `ols_plot_dffits()`

## Bug Fixes

Expand Down
6 changes: 4 additions & 2 deletions R/ols-bartlett-test.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@
#'
#' @examples
#' # using grouping variable
#' library(descriptr)
#' ols_test_bartlett(mtcarz, 'mpg', group_var = 'cyl')
#' if (require("descriptr")) {
#' library(descriptr)
#' ols_test_bartlett(mtcarz, 'mpg', group_var = 'cyl')
#' }
#'
#' # using variables
#' ols_test_bartlett(hsb, 'read', 'write')
Expand Down
37 changes: 23 additions & 14 deletions R/ols-cooks-d-barplot.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@
#' fitted values of the model.
#'
#' @param model An object of class \code{lm}.
#' @param type An integer between 1 and 5 selecting one of the 6 methods for computing the threshold.
#' @param print_plot logical; if \code{TRUE}, prints the plot else returns a plot object.
#' @param type An integer between 1 and 5 selecting one of the 5 methods for
#' computing the threshold.
#' @param threshold Threshold for detecting outliers.
#' @param print_plot logical; if \code{TRUE}, prints the plot else returns a
#' plot object.
#'
#' @details
#' Cook's distance was introduced by American statistician R Dennis Cook in
Expand Down Expand Up @@ -51,6 +54,8 @@
#' @examples
#' model <- lm(mpg ~ disp + hp + wt, data = mtcars)
#' ols_plot_cooksd_bar(model)
#' ols_plot_cooksd_bar(model, type = 4)
#' ols_plot_cooksd_bar(model, threshold = 0.2)
#'
#' @importFrom stats cooks.distance
#' @importFrom ggplot2 geom_bar coord_flip ylim geom_hline geom_label
Expand All @@ -59,15 +64,19 @@
#'
#' @export
#'
ols_plot_cooksd_bar <- function(model, type = 1, print_plot = TRUE) {
ols_plot_cooksd_bar <- function(model, type = 1, threshold = NULL, print_plot = TRUE) {

check_model(model)

k <- ols_prep_cdplot_data(model, type)
d <- ols_prep_outlier_obs(k)
f <- ols_prep_cdplot_outliers(k)

if (is.null(threshold)) {
threshold <- k$ts
}

y_max <- max(k$maxx, k$ts)
y_max <- max(k$maxx, threshold)
y_lim <- y_max + (y_max * 0.1)

# geoms
Expand All @@ -76,33 +85,33 @@ ols_plot_cooksd_bar <- function(model, type = 1, print_plot = TRUE) {
geom_bar(width = 0.5, stat = "identity", aes(fill = fct_color)) +
geom_text(hjust = -0.2, nudge_x = 0.05, size = 2, na.rm = TRUE) +
geom_hline(yintercept = 0) +
geom_hline(yintercept = k$ts, colour = "red")
geom_hline(yintercept = threshold, colour = "red")

# annotations
p <-
p +
annotate("text", x = Inf, y = Inf, hjust = 1.2, vjust = 2,
family = "serif", fontface = "italic", colour = "darkred",
label = paste("Threshold:", round(k$ts, 3)))
label = paste("Threshold:", round(threshold, 3)))

# scales
p <-
p <-
p +
scale_fill_manual(values = c("blue", "red"))
scale_fill_manual(values = c("blue", "red"))

# guides
p <-
p <-
p +
labs(fill = "Observation") +
xlab("Observation") +
ylab("Cook's D") +
ggtitle("Cook's D Bar Plot") +
ylim(0, y_lim)
ylab("Cook's D") +
ggtitle("Cook's D Bar Plot") +
ylim(0, y_lim)

if (print_plot) {
suppressWarnings(print(p))
} else {
return(list(plot = p, outliers = f, threshold = k$ts))
return(list(plot = p, outliers = f, threshold = threshold))
}

}
}
17 changes: 12 additions & 5 deletions R/ols-cooks-d-chart.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#'
#' @param model An object of class \code{lm}.
#' @param type An integer between 1 and 5 selecting one of the 6 methods for computing the threshold.
#' @param threshold Threshold for detecting outliers.
#' @param print_plot logical; if \code{TRUE}, prints the plot else returns a plot object.
#'
#' @details
Expand Down Expand Up @@ -51,35 +52,41 @@
#' @examples
#' model <- lm(mpg ~ disp + hp + wt, data = mtcars)
#' ols_plot_cooksd_chart(model)
#' ols_plot_cooksd_chart(model, type = 4)
#' ols_plot_cooksd_chart(model, threshold = 0.2)
#'
#' @importFrom ggplot2 geom_linerange
#'
#' @seealso [ols_plot_cooksd_bar()]
#'
#' @export
#'
ols_plot_cooksd_chart <- function(model, type = 1, print_plot = TRUE) {
ols_plot_cooksd_chart <- function(model, type = 1, threshold = NULL, print_plot = TRUE) {

check_model(model)

k <- ols_prep_cdplot_data(model, type)
d <- ols_prep_outlier_obs(k)
f <- ols_prep_cdplot_outliers(k)

if (is.null(threshold)) {
threshold <- k$ts
}

p <-
ggplot(d, aes(x = obs, y = cd, label = txt, ymin = min(cd), ymax = cd)) +
geom_linerange(colour = "blue") +
geom_point(shape = 1, colour = "blue") +
geom_text(vjust = -1, size = 3, family = "serif", fontface = "italic",
colour = "darkred", na.rm = TRUE) +
geom_hline(yintercept = k$ts, colour = "red")
geom_hline(yintercept = threshold, colour = "red")

# annotations
p <-
p +
annotate("text", x = Inf, y = Inf, hjust = 1.2, vjust = 2,
family = "serif", fontface = "italic", colour = "darkred",
label = paste("Threshold:", round(k$ts, 3)))
label = paste("Threshold:", round(threshold, 3)))

# guides
p <-
Expand All @@ -92,7 +99,7 @@ ols_plot_cooksd_chart <- function(model, type = 1, print_plot = TRUE) {
if (print_plot) {
suppressWarnings(print(p))
} else {
return(list(plot = p, outliers = f, threshold = k$ts))
return(list(plot = p, outliers = f, threshold = threshold))
}

}
}
2 changes: 0 additions & 2 deletions R/ols-launch-app.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
#' @export
#'
ols_launch_app <- function() {

check_suggests('xplorerr')
xplorerr::app_linear_regression()
}

Loading

0 comments on commit 1a6b522

Please sign in to comment.