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 diff --git a/DESCRIPTION b/DESCRIPTION index fa29f37d4..3b95351d9 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.4 Authors@R: c(person(given = "Daniel", family = "Lüdecke", @@ -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 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 diff --git a/R/check_outliers.R b/R/check_outliers.R index c1af3bb1f..e98e037c0 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 @@ -299,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") @@ -315,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 #' } @@ -506,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)") ) @@ -1764,7 +1764,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 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/man/check_outliers.Rd b/man/check_outliers.Rd index e3c218b7a..c19d4ecb0 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 @@ -290,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") @@ -306,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{ 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) +})