From b4ba7467ad67350db6deba5f609179e6fa0f3d28 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 24 Sep 2023 18:22:53 +0200 Subject: [PATCH 01/10] close #524 --- R/check_outliers.R | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/R/check_outliers.R b/R/check_outliers.R index c1af3bb1f..519ab64e0 100644 --- a/R/check_outliers.R +++ b/R/check_outliers.R @@ -167,7 +167,9 @@ #' value for outliers classification. Refer to the help-file of #' [ICSOutlier::ics.outlier()] to get more details about this procedure. #' Note that `method = "ics"` requires both **ICS** and **ICSOutlier** -#' to be installed, and that it takes some time to compute the results. +#' to be installed, and that it takes some time to compute the results. You +#' can speed up computation time using parallel computing. Set the number of +#' cores to use with `options(mc.cores = 4)` (for example). #' #' - **OPTICS**: #' The Ordering Points To Identify the Clustering Structure (OPTICS) algorithm @@ -1764,7 +1766,20 @@ check_outliers.metabin <- check_outliers.metagen n_cores <- if (!requireNamespace("parallel", quietly = TRUE)) { NULL } else { - max(1L, parallel::detectCores() - 2L, na.rm = TRUE) + getOption("mc.cores", 1L) + } + + # tell user about n-cores option + if (is.null(n_cores)) { + insight::format_alert( + "Package `parallel` is not installed. `check_outliers()` will run on a single core.", + "Install package `parallel` and set, for example, `options(mc.cores = 4)` to run on multiple cores." + ) + } else if (n_cores == 1) { + insight::format_alert( + "Package `parallel` is installed, but `check_outliers()` will run on a single core.", + "To use multiple cores, set `options(mc.cores = 4)` (for example)." + ) } # Run algorithm From 692860a5702b47245d02bb051a170a5651462f24 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 24 Sep 2023 18:23:22 +0200 Subject: [PATCH 02/10] rd --- man/check_outliers.Rd | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/man/check_outliers.Rd b/man/check_outliers.Rd index e3c218b7a..bb95fadf8 100644 --- a/man/check_outliers.Rd +++ b/man/check_outliers.Rd @@ -195,7 +195,9 @@ of 0.025 (corresponding to the 2.5\\% most extreme observations) as a cut-off value for outliers classification. Refer to the help-file of \code{\link[ICSOutlier:ics.outlier]{ICSOutlier::ics.outlier()}} to get more details about this procedure. Note that \code{method = "ics"} requires both \strong{ICS} and \strong{ICSOutlier} -to be installed, and that it takes some time to compute the results. +to be installed, and that it takes some time to compute the results. You +can speed up computation time using parallel computing. Set the number of +cores to use with \code{options(mc.cores = 4)} (for example). \item \strong{OPTICS}: The Ordering Points To Identify the Clustering Structure (OPTICS) algorithm (Ankerst et al., 1999) is using similar concepts to DBSCAN (an unsupervised From 7f4719ab8f9662599c495157f4dede249a84dcd2 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 24 Sep 2023 18:25:07 +0200 Subject: [PATCH 03/10] news, dev --- DESCRIPTION | 2 +- NEWS.md | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index fa29f37d4..4853a45d3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.10.5.2 +Version: 0.10.5.3 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/NEWS.md b/NEWS.md index 857924e29..40e57d346 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,12 @@ # performance (development version) +## Changes to functions + +* `check_outliers()` for method `"ics"` now detects number of available cores + for parallel computing via the `"mc.cores"` option. This is more robust than + the previous method, which used `parallel::detectCores()`. Now you should + set the number of cores via `options(mc.cores = 4)`. + # performance 0.10.5 ## Changes to functions From 462e8aef4757f628a154c2752ac914b2f7d1be06 Mon Sep 17 00:00:00 2001 From: Daniel Date: Sun, 24 Sep 2023 18:59:59 +0200 Subject: [PATCH 04/10] docs --- R/check_outliers.R | 8 +++----- man/check_outliers.Rd | 7 +++---- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/R/check_outliers.R b/R/check_outliers.R index 519ab64e0..e98e037c0 100644 --- a/R/check_outliers.R +++ b/R/check_outliers.R @@ -301,6 +301,7 @@ #' group_iris <- datawizard::data_group(iris, "Species") #' check_outliers(group_iris) #' +#' @examplesIf require("see") && require("bigutilsr") && require("loo") && require("MASS") && require("ICSOutlier") && require("ICS") && require("dbscan") #' \donttest{ #' # You can also run all the methods #' check_outliers(data, method = "all") @@ -317,10 +318,7 @@ #' model <- lm(disp ~ mpg + hp, data = mt2) #' #' outliers_list <- check_outliers(model) -#' -#' if (require("see")) { -#' plot(outliers_list) -#' } +#' plot(outliers_list) #' #' insight::get_data(model)[outliers_list, ] # Show outliers data #' } @@ -508,7 +506,7 @@ check_outliers.default <- function(x, num.df <- outlier_count$all[!names(outlier_count$all) %in% c("Row", ID)] if (isTRUE(nrow(num.df) > 0)) { - num.df <- datawizard::change_code( + num.df <- datawizard::recode_values( num.df, recode = list(`2` = "(Multivariate)") ) diff --git a/man/check_outliers.Rd b/man/check_outliers.Rd index bb95fadf8..c19d4ecb0 100644 --- a/man/check_outliers.Rd +++ b/man/check_outliers.Rd @@ -292,6 +292,7 @@ filtered_data <- data[outliers_info$Outlier < 0.1, ] group_iris <- datawizard::data_group(iris, "Species") check_outliers(group_iris) +\dontshow{if (require("see") && require("bigutilsr") && require("loo") && require("MASS") && require("ICSOutlier") && require("ICS") && require("dbscan")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ # You can also run all the methods check_outliers(data, method = "all") @@ -308,13 +309,11 @@ mt2 <- rbind(mt1, data.frame( model <- lm(disp ~ mpg + hp, data = mt2) outliers_list <- check_outliers(model) - -if (require("see")) { - plot(outliers_list) -} +plot(outliers_list) insight::get_data(model)[outliers_list, ] # Show outliers data } +\dontshow{\}) # examplesIf} } \references{ \itemize{ From ddaebc76bce529c9b926bcc144c0cc045c4dd928 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Sep 2023 15:08:20 +0200 Subject: [PATCH 05/10] Recursion in `logLik.plm()` that slows down computations: (#623) Co-authored-by: Indrajeet Patil --- R/logLik.R | 2 +- tests/testthat/test-logLik.R | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/testthat/test-logLik.R diff --git a/R/logLik.R b/R/logLik.R index 90c12930b..5c42f41a5 100644 --- a/R/logLik.R +++ b/R/logLik.R @@ -55,7 +55,7 @@ logLik.plm <- function(object, ...) { attr(val, "nall") <- N0 attr(val, "nobs") <- N - attr(val, "df") <- insight::get_df(object, type = "model") + attr(val, "df") <- insight::n_parameters(object) + 1L class(val) <- "logLik" val diff --git a/tests/testthat/test-logLik.R b/tests/testthat/test-logLik.R new file mode 100644 index 000000000..2691f1d3c --- /dev/null +++ b/tests/testthat/test-logLik.R @@ -0,0 +1,27 @@ +test_that("logLik", { + skip_if_not_installed("plm") + skip_if_not_installed("withr") + + withr::local_options(list(expressions = 25)) + set.seed(1) + nnn <- 100 + ddta <- data.frame( + x1 = rnorm(nnn), + x2 = rnorm(nnn), + id = rep_len(1:(nnn / 10), nnn), + year = rep_len(1:11, nnn) + ) + ddta$y <- ddta$x1 * 0.5 - ddta$x2 * 0.5 + rnorm(nnn) + + m1 <- lm(y ~ x1 + x2, data = ddta) + l1 <- logLik(m1) + + m2 <- plm( + y ~ x1 + x2, + data = ddta, + model = "pooling", + index = c("id", "year") + ) + l2 <- logLik(m2) + expect_equal(l1, l2, tolerance = 1e-3, ignore_attr = TRUE) +}) From aca7e9964cba8a6625fe22e0c3b3a6eb00308e5a Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 27 Sep 2023 19:32:24 +0530 Subject: [PATCH 06/10] Experiment with autobump deps PR workflow (#624) --- .../workflows/update-to-latest-easystats.yml | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 .github/workflows/update-to-latest-easystats.yml diff --git a/.github/workflows/update-to-latest-easystats.yml b/.github/workflows/update-to-latest-easystats.yml new file mode 100644 index 000000000..90f6f3fc3 --- /dev/null +++ b/.github/workflows/update-to-latest-easystats.yml @@ -0,0 +1,54 @@ +name: update-to-latest-easystats + +on: + push: + branches: [main, master] + pull_request: + branches: [main, master] + +# Run on a schedule (once a month) +# schedule: +# - cron: "0 0 1 * *" + +jobs: + update-to-latest-easystats: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up R + uses: r-lib/actions/setup-r@v2 + + - uses: r-lib/actions/setup-r-dependencies@v2 + with: + dependencies: '"hard"' + extra-packages: | + any::usethis + + - name: Update DESCRIPTION file + id: update_description + run: | + usethis::use_latest_dependencies() + shell: Rscript {0} + + - name: Check for changes in DESCRIPTION + id: check_description + run: | + git status + git add --all + + - name: Create pull request + #if: ${{ steps.update_description.outputs.changed }} + uses: peter-evans/create-pull-request@v5 + with: + token: ${{ secrets.GITHUB_TOKEN }} + base: main + branch: desc-${{ github.ref_name }}-${{ github.job }} + branch-suffix: timestamp + delete-branch: true + title: "Update `DESCRIPTION` to use latest 'easystats' dependencies" + body: "Automatically updated the `DESCRIPTION` file using `usethis::use_latest_dependencies()`." + labels: "auto-update" + add-paths: | + DESCRIPTION From 4870b8c166338a6424b90acd34b0f2b85c486af6 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 27 Sep 2023 19:32:36 +0530 Subject: [PATCH 07/10] Update `DESCRIPTION` to use latest 'easystats' dependencies (#625) Co-authored-by: IndrajeetPatil --- DESCRIPTION | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 4853a45d3..302314eb1 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -69,9 +69,9 @@ BugReports: https://github.com/easystats/performance/issues Depends: R (>= 3.6) Imports: - bayestestR (>= 0.13.0), - insight (>= 0.19.4), - datawizard (>= 0.7.0), + bayestestR (>= 0.13.1), + insight (>= 0.19.5), + datawizard (>= 0.9.0), methods, stats, utils From a5647f900f91773f387353ac4d856b3f0221c63b Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 27 Sep 2023 16:20:55 +0200 Subject: [PATCH 08/10] bump version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 302314eb1..3b95351d9 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.10.5.3 +Version: 0.10.5.4 Authors@R: c(person(given = "Daniel", family = "Lüdecke", From 3be01281a236ca945a71118d14dfa026739c25be Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 27 Sep 2023 16:31:37 +0200 Subject: [PATCH 09/10] expt over [skip ci] --- .../workflows/update-to-latest-easystats.yml | 54 ------------------- 1 file changed, 54 deletions(-) delete mode 100644 .github/workflows/update-to-latest-easystats.yml diff --git a/.github/workflows/update-to-latest-easystats.yml b/.github/workflows/update-to-latest-easystats.yml deleted file mode 100644 index 90f6f3fc3..000000000 --- a/.github/workflows/update-to-latest-easystats.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: update-to-latest-easystats - -on: - push: - branches: [main, master] - pull_request: - branches: [main, master] - -# Run on a schedule (once a month) -# schedule: -# - cron: "0 0 1 * *" - -jobs: - update-to-latest-easystats: - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Set up R - uses: r-lib/actions/setup-r@v2 - - - uses: r-lib/actions/setup-r-dependencies@v2 - with: - dependencies: '"hard"' - extra-packages: | - any::usethis - - - name: Update DESCRIPTION file - id: update_description - run: | - usethis::use_latest_dependencies() - shell: Rscript {0} - - - name: Check for changes in DESCRIPTION - id: check_description - run: | - git status - git add --all - - - name: Create pull request - #if: ${{ steps.update_description.outputs.changed }} - uses: peter-evans/create-pull-request@v5 - with: - token: ${{ secrets.GITHUB_TOKEN }} - base: main - branch: desc-${{ github.ref_name }}-${{ github.job }} - branch-suffix: timestamp - delete-branch: true - title: "Update `DESCRIPTION` to use latest 'easystats' dependencies" - body: "Automatically updated the `DESCRIPTION` file using `usethis::use_latest_dependencies()`." - labels: "auto-update" - add-paths: | - DESCRIPTION From 45cf8d0861ec0f9b84d18c4a5eecce66b6e0818d Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Wed, 27 Sep 2023 16:54:56 +0200 Subject: [PATCH 10/10] Create update-to-latest-easystats.yaml --- .github/workflows/update-to-latest-easystats.yaml | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 .github/workflows/update-to-latest-easystats.yaml diff --git a/.github/workflows/update-to-latest-easystats.yaml b/.github/workflows/update-to-latest-easystats.yaml new file mode 100644 index 000000000..7718d763a --- /dev/null +++ b/.github/workflows/update-to-latest-easystats.yaml @@ -0,0 +1,10 @@ +on: + schedule: + # Check for dependency updates once a month + - cron: "0 0 1 * *" + +name: update-to-latest-easystats + +jobs: + update-to-latest-easystats: + uses: easystats/workflows/.github/workflows/update-to-latest-easystats.yaml@main