Skip to content

Commit

Permalink
add approx argument
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Jun 13, 2024
1 parent 126b768 commit bfd86fa
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion 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.0.1
Version: 0.12.0.2
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
7 changes: 6 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@

* `icc()` and `r2_nakagawa()` get a `null_model` argument. This can be useful
when computing R2 or ICC for mixed models, where the internal computation of
the null model fails.
the null model fails, or when you already have fit the null model and want
to save time.

* `icc()` and `r2_nakagawa()` get a `approximation` argument indicating the
approximation method for the distribution-specific (residual) variance. See
Nakagawa et al. 2017 for details.

# performance 0.12.0

Expand Down
18 changes: 14 additions & 4 deletions R/icc.R
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@
#' However, these intervals are rather inaccurate and often too narrow. It is
#' recommended to calculate bootstrapped confidence intervals for mixed models.
#' @param verbose Toggle warnings and messages.
#' @param null_model Optional, a null model to compute the random effect variances.
#' Should only be used if calculation of r-squared or ICC fails when `null_model`
#' is not specified.
#' @param null_model Optional, a null model to compute the random effect variances,
#' which is passed to [`insight::get_variance()`]. Usually only required if
#' calculation of r-squared or ICC fails when `null_model` is not specified. If
#' calculating the null model takes longer and you already have fit the null
#' model, you can pass it here, too, to speed up the process.
#' @param ... Arguments passed down to `lme4::bootMer()` or `boot::boot()`
#' for bootstrapped ICC or R2.
#'
Expand Down Expand Up @@ -173,6 +175,7 @@ icc <- function(model,
iterations = 100,
ci_method = NULL,
null_model = NULL,
approximation = "lognormal",
verbose = TRUE,
...) {
# special handling for smicd::semLme()
Expand Down Expand Up @@ -201,7 +204,12 @@ icc <- function(model,
}

# calculate random effect variances
vars <- .compute_random_vars(model, tolerance, null_model = null_model)
vars <- .compute_random_vars(
model,
tolerance = tolerance,
null_model = null_model,
approximation = approximation
)

# return if ICC couldn't be computed
if (is.null(vars) || all(is.na(vars))) {
Expand Down Expand Up @@ -535,13 +543,15 @@ print.icc_decomposed <- function(x, digits = 2, ...) {
name_fun = "icc()",
name_full = "ICC",
null_model = null_model,
approximation = "lognormal",
verbose = TRUE) {
vars <- tryCatch(
insight::get_variance(model,
name_fun = name_fun,
name_full = name_full,
tolerance = tolerance,
null_model = null_model,
approximation = approximation,
verbose = verbose
),
error = function(e) {
Expand Down
2 changes: 2 additions & 0 deletions R/r2_nakagawa.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ r2_nakagawa <- function(model,
iterations = 100,
ci_method = NULL,
null_model = NULL,
approximation = "lognormal",
verbose = TRUE,
...) {
# calculate random effect variances
Expand All @@ -66,6 +67,7 @@ r2_nakagawa <- function(model,
tolerance,
components = c("var.fixed", "var.residual"),
null_model = null_model,
approximation = approximation,
name_fun = "r2()",
name_full = "r-squared"
)
Expand Down
13 changes: 10 additions & 3 deletions man/icc.Rd

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

13 changes: 10 additions & 3 deletions man/r2_nakagawa.Rd

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

0 comments on commit bfd86fa

Please sign in to comment.