Skip to content

Commit

Permalink
Merge branch 'main' into JOSE_paper
Browse files Browse the repository at this point in the history
  • Loading branch information
rempsyc authored Sep 27, 2023
2 parents 409ed4c + 45cf8d0 commit ead9910
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 17 deletions.
10 changes: 10 additions & 0 deletions .github/workflows/update-to-latest-easystats.yaml
Original file line number Diff line number Diff line change
@@ -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
8 changes: 4 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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",
Expand Down Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
27 changes: 20 additions & 7 deletions R/check_outliers.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand 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
#' }
Expand Down Expand Up @@ -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)")
)
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion R/logLik.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 6 additions & 5 deletions man/check_outliers.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/testthat/test-logLik.R
Original file line number Diff line number Diff line change
@@ -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)
})

0 comments on commit ead9910

Please sign in to comment.