Skip to content

Commit

Permalink
Merge branch 'main' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Aug 25, 2024
2 parents f708a17 + 852c1d9 commit ee2b43f
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 11 deletions.
4 changes: 2 additions & 2 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.12.2.11
Version: 0.12.2.12
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down Expand Up @@ -160,4 +160,4 @@ Config/Needs/website:
r-lib/pkgdown,
easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/see
Remotes: easystats/see, easystats/insight
6 changes: 6 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

* `check_dag()`, to check DAGs for correct adjustment sets.

## Changes

* `check_heterogeneity_bias()` gets a `nested` argument. Furthermore, `by` can
specify more than one variable, meaning that nested or cross-classified
model designs can also be tested for heterogeneity bias.

# performance 0.12.2

Patch release, to ensure that _performance_ runs with older version of
Expand Down
34 changes: 28 additions & 6 deletions R/check_heterogeneity_bias.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,24 @@
#' that should be checked. If `x` is a mixed model object, this argument
#' will be ignored.
#' @param by Character vector (or formula) with the name of the variable that
#' indicates the group- or cluster-ID. If `x` is a model object, this
#' argument will be ignored.
#' indicates the group- or cluster-ID. For cross-classified or nested designs,
#' `by` can also identify two or more variables as group- or cluster-IDs. If
#' the data is nested and should be treated as such, set `nested = TRUE`. Else,
#' if `by` defines two or more variables and `nested = FALSE`, a cross-classified
#' design is assumed. If `x` is a model object, this argument will be ignored.
#'
#' For nested designs, `by` can be:
#' - a character vector with the name of the variable that indicates the
#' levels, ordered from *highest* level to *lowest* (e.g.
#' `by = c("L4", "L3", "L2")`.
#' - a character vector with variable names in the format `by = "L4/L3/L2"`,
#' where the levels are separated by `/`.
#'
#' See also section _De-meaning for cross-classified designs_ and
#' _De-meaning for nested designs_ below.
#' @param nested Logical, if `TRUE`, the data is treated as nested. If `FALSE`,
#' the data is treated as cross-classified. Only applies if `by` contains more
#' than one variable.
#' @param group Deprecated. Use `by` instead.
#'
#' @seealso
Expand All @@ -28,7 +44,7 @@
#' iris$ID <- sample(1:4, nrow(iris), replace = TRUE) # fake-ID
#' check_heterogeneity_bias(iris, select = c("Sepal.Length", "Petal.Length"), by = "ID")
#' @export
check_heterogeneity_bias <- function(x, select = NULL, by = NULL, group = NULL) {
check_heterogeneity_bias <- function(x, select = NULL, by = NULL, nested = FALSE, group = NULL) {
insight::check_if_installed("datawizard", minimum_version = "0.12.0")

## TODO: deprecate later
Expand All @@ -54,8 +70,14 @@ check_heterogeneity_bias <- function(x, select = NULL, by = NULL, group = NULL)
my_data <- x
}

unique_groups <- .n_unique(my_data[[by]])
combinations <- expand.grid(select, by)
# for nested designs?
if (nested) {
# separate level-indicators with "/", as supported by datawizard
by <- paste(by, collapse = "/")
}

# create all combinations that should be checked
combinations <- expand.grid(select, by[1])

result <- Map(function(predictor, id) {
# demean predictor
Expand All @@ -72,7 +94,7 @@ check_heterogeneity_bias <- function(x, select = NULL, by = NULL, group = NULL)
} else {
NULL
}
}, as.character(combinations[[1]]), as.character(combinations[[2]]))
}, as.character(combinations[[1]]), by)

out <- unlist(insight::compact_list(result), use.names = FALSE)

Expand Down
31 changes: 28 additions & 3 deletions man/check_heterogeneity_bias.Rd

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

0 comments on commit ee2b43f

Please sign in to comment.