Skip to content

Commit

Permalink
Merge branch 'main' into strengejacke/issue697
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke authored Oct 22, 2024
2 parents 7cd93a8 + 0aa3492 commit a8aa04d
Show file tree
Hide file tree
Showing 30 changed files with 198 additions and 191 deletions.
35 changes: 18 additions & 17 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.12.3.3
Version: 0.12.4.2
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
role = c("aut", "cre"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-8895-3206", Twitter = "@strengejacke")),
comment = c(ORCID = "0000-0002-8895-3206")),
person(given = "Dominique",
family = "Makowski",
role = c("aut", "ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-5375-9967", Twitter = "@Dom_Makowski")),
comment = c(ORCID = "0000-0001-5375-9967")),
person(given = "Mattan S.",
family = "Ben-Shachar",
role = c("aut", "ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0002-4287-4801", Twitter = "@mattansb")),
comment = c(ORCID = "0000-0002-4287-4801")),
person(given = "Indrajeet",
family = "Patil",
role = c("aut", "ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-1995-6531", Twitter = "@patilindrajeets")),
comment = c(ORCID = "0000-0003-1995-6531")),
person(given = "Philip",
family = "Waggoner",
role = c("aut", "ctb"),
Expand All @@ -32,12 +32,12 @@ Authors@R:
family = "Wiernik",
role = c("aut", "ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0001-9560-6336", Twitter = "@bmwiernik")),
comment = c(ORCID = "0000-0001-9560-6336")),
person(given = "Rémi",
family = "Thériault",
role = c("aut", "ctb"),
email = "[email protected]",
comment = c(ORCID = "0000-0003-4315-6788", Twitter = "@rempsyc")),
comment = c(ORCID = "0000-0003-4315-6788")),
person(given = "Vincent",
family = "Arel-Bundock",
email = "[email protected]",
Expand All @@ -48,9 +48,9 @@ Authors@R:
role = "rev"),
person(given = "gjo11",
role = "rev"),
person("Etienne",
"Bacher", ,
"[email protected]",
person(given = "Etienne",
family = "Bacher", ,
email = "[email protected]",
role = "ctb",
comment = c(ORCID = "0000-0002-9271-5075")),
person(given = "Joseph",
Expand All @@ -73,9 +73,9 @@ BugReports: https://github.com/easystats/performance/issues
Depends:
R (>= 3.6)
Imports:
bayestestR (>= 0.13.2),
insight (>= 0.20.2),
datawizard (>= 0.10.0),
bayestestR (>= 0.15.0),
insight (>= 0.20.5),
datawizard (>= 0.13.0),
stats,
utils
Suggests:
Expand All @@ -95,15 +95,15 @@ Suggests:
cplm,
dagitty,
dbscan,
DHARMa,
DHARMa (>= 0.4.7),
estimatr,
fixest,
flextable,
forecast,
ftExtra,
gamm4,
ggdag,
glmmTMB,
glmmTMB (>= 1.1.10),
graphics,
Hmisc,
httr2,
Expand All @@ -129,7 +129,7 @@ Suggests:
nonnest2,
ordinal,
parallel,
parameters (>= 0.21.6),
parameters (>= 0.22.0),
patchwork,
pscl,
psych,
Expand All @@ -142,7 +142,7 @@ Suggests:
rstanarm,
rstantools,
sandwich,
see (>= 0.8.2),
see (>= 0.9.0),
survey,
survival,
testthat (>= 3.2.1),
Expand All @@ -160,3 +160,4 @@ Config/Needs/website:
r-lib/pkgdown,
easystats/easystatstemplate
Config/rcmdcheck/ignore-inconsequential-notes: true
Remotes: easystats/insight
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,6 @@ export(check_multimodal)
export(check_normality)
export(check_outliers)
export(check_overdispersion)
export(check_posterior_predictions)
export(check_predictions)
export(check_residuals)
export(check_singularity)
Expand Down Expand Up @@ -602,7 +601,6 @@ export(performance_rmse)
export(performance_roc)
export(performance_rse)
export(performance_score)
export(posterior_predictive_check)
export(print_html)
export(print_md)
export(r2)
Expand Down
14 changes: 14 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
# performance 0.12.5

## Breaking changes

* Deprecated arguments and alias-function-names have been removed.

## Changes

* Increased accuracy for `check_convergence()` for *glmmTMB* models.

# performance 0.12.4

## Changes
Expand All @@ -7,6 +17,10 @@

* Minor revisions to the printed output of `check_dag()`.

## Bug fixes

* Fixed failing tests that broke due to changes in latest *glmmTMB* update.

# performance 0.12.3

## New functions
Expand Down
5 changes: 3 additions & 2 deletions R/check_convergence.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,10 @@ check_convergence.merMod <- function(x, tolerance = 0.001, ...) {


#' @export
check_convergence.glmmTMB <- function(x, ...) {
check_convergence.glmmTMB <- function(x, tolerance = 0.001, ...) {
# https://github.com/glmmTMB/glmmTMB/issues/275
isTRUE(x$sdr$pdHess)
# https://stackoverflow.com/q/79110546/2094622
isTRUE(all.equal(x$fit$convergence, 0, tolerance = tolerance)) && isTRUE(x$sdr$pdHess)
}


Expand Down
82 changes: 70 additions & 12 deletions R/check_dag.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,17 @@
#' @param latent A character vector with names of latent variables in the model.
#' @param effect Character string, indicating which effect to check. Can be
#' `"all"` (default), `"total"`, or `"direct"`.
#' @param coords A list with two elements, `x` and `y`, which both are named
#' vectors of numerics. The names correspond to the variable names in the DAG,
#' and the values for `x` and `y` indicate the x/y coordinates in the plot.
#' @param coords Coordinates of the variables when plotting the DAG. The
#' coordinates can be provided in three different ways:
#'
#' - a list with two elements, `x` and `y`, which both are named vectors of
#' numerics. The names correspond to the variable names in the DAG, and the
#' values for `x` and `y` indicate the x/y coordinates in the plot.
#' - a list with elements that correspond to the variables in the DAG. Each
#' element is a numeric vector of length two with x- and y-coordinate.
#' - a data frame with three columns: `x`, `y` and `name` (which contains the
#' variable names).
#'
#' See 'Examples'.
#' @param x An object of class `check_dag`, as returned by `check_dag()`.
#'
Expand Down Expand Up @@ -111,7 +119,7 @@
#' Interpreting Confounder and Modifier Coefficients. American Journal of
#' Epidemiology, 177(4), 292–298. \doi{10.1093/aje/kws412}
#'
#' @examplesIf require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE) && packageVersion("see") > "0.8.5"
#' @examplesIf require("ggdag", quietly = TRUE) && require("dagitty", quietly = TRUE) && require("see", quietly = TRUE)
#' # no adjustment needed
#' check_dag(
#' y ~ x + b,
Expand Down Expand Up @@ -171,6 +179,22 @@
#' )
#' plot(dag)
#'
#' # alternative way of providing the coordinates
#' dag <- check_dag(
#' score ~ exp + b + c,
#' exp ~ b,
#' outcome = "score",
#' exposure = "exp",
#' coords = list(
#' # x/y coordinates for each node
#' score = c(5, 3),
#' exp = c(4, 3),
#' b = c(3, 2),
#' c = c(3, 4)
#' )
#' )
#' plot(dag)
#'
#' # Objects returned by `check_dag()` can be used with "ggdag" or "dagitty"
#' ggdag::ggdag_status(dag)
#'
Expand Down Expand Up @@ -248,6 +272,9 @@ check_dag <- function(...,
adjusted <- all.vars(adjusted)
}

# process coords-argument
coords <- .process_coords(coords)

# convert to dag
dag_args <- c(formulas, list(
exposure = exposure,
Expand Down Expand Up @@ -285,15 +312,13 @@ check_dag <- function(...,
adjustment_set <- unlist(dagitty::adjustmentSets(dag, effect = x), use.names = FALSE)
adjustment_nodes <- unlist(dagitty::adjustedNodes(dag), use.names = FALSE)
minimal_adjustments <- as.list(dagitty::adjustmentSets(dag, effect = x))
collider <- adjustment_nodes[vapply(adjustment_nodes, ggdag::is_collider, logical(1), .dag = dag, downstream = FALSE)]
if (!length(collider)) {
collider <- adjustment_nodes[vapply(adjustment_nodes, ggdag::is_collider, logical(1), .dag = dag, downstream = FALSE)] # nolint
if (length(collider)) {
# if we *have* colliders, remove them from minimal adjustments
minimal_adjustments <- lapply(minimal_adjustments, setdiff, y = collider)
} else {
# if we don't have colliders, set to NULL
collider <- NULL
} else {
# if we *have* colliders, remove them from minimal adjustments
minimal_adjustments <- lapply(minimal_adjustments, function(ma) {
setdiff(ma, collider)
})
}
list(
# no adjustment needed when
Expand All @@ -303,7 +328,7 @@ check_dag <- function(...,
# incorrect adjustment when
# - required is NULL and current adjustment not NULL
# - OR we have a collider in current adjustments
incorrectly_adjusted = (is.null(adjustment_set) && !is.null(adjustment_nodes)) || (!is.null(collider) && collider %in% adjustment_nodes),
incorrectly_adjusted = (is.null(adjustment_set) && !is.null(adjustment_nodes)) || (!is.null(collider) && collider %in% adjustment_nodes), # nolint
current_adjustments = adjustment_nodes,
minimal_adjustments = minimal_adjustments,
collider = collider
Expand Down Expand Up @@ -340,6 +365,39 @@ check_dag <- function(...,
}


.process_coords <- function(coords) {
# check if the coords are not provided as list with x/y elements, but instead
# as list x/y coordinates for each element. This means, "coords" is provided as
#
# coords <- list(
# score = c(5, 3),
# exp = c(4, 3),
# b = c(3, 2),
# c = c(3, 4)
# )
#
# but we want
#
# coords = list(
# x = c(score = 5, exp = 4, b = 3, c = 3),
# y = c(score = 3, exp = 3, b = 2, c = 4)
# )
#
# we have to check that it's not a data frame and that it is a list -
# values like `ggdag::time_ordered_coords()` returns a function, not a list
if (!is.null(coords) && !is.data.frame(coords) && is.list(coords) && (length(coords) != 2 || !identical(names(coords), c("x", "y")))) { # nolint
# transform list into data frame, split x and y coordinates into columns
coords <- datawizard::rownames_as_column(
stats::setNames(as.data.frame(do.call(rbind, coords)), c("x", "y")),
"name"
)
# reorder
coords <- coords[c("x", "y", "name")]
}
coords
}


# methods --------------------------------------------------------------------

#' @rdname check_dag
Expand Down
11 changes: 2 additions & 9 deletions R/check_heterogeneity_bias.R
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
#' @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
#' For further details, read the vignette
Expand All @@ -39,20 +38,14 @@
#' Modeling of Time-Series Cross-Sectional and Panel Data. Political Science
#' Research and Methods, 3(1), 133–153.
#'
#' @examplesIf insight::check_if_installed("datawizard", minimum_version = "0.12.0", quietly = TRUE)
#' @examples
#' data(iris)
#' 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, nested = FALSE, group = NULL) {
check_heterogeneity_bias <- function(x, select = NULL, by = NULL, nested = FALSE) {
insight::check_if_installed("datawizard", minimum_version = "0.12.0")

## TODO: deprecate later
if (!is.null(group)) {
insight::format_warning("Argument `group` is deprecated and will be removed in a future release. Please use `by` instead.") # nolint
by <- group
}

if (insight::is_model(x)) {
by <- insight::find_random(x, split_nested = TRUE, flatten = TRUE)
if (is.null(by)) {
Expand Down
2 changes: 1 addition & 1 deletion R/check_model_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@
if (!is.na(match(faminfo$family, c("binomial", "poisson", "truncated_poisson")))) {
return(1)
}
betad <- model$fit$par["betad"]
betad <- model$fit$par["betadisp"]
switch(faminfo$family,
gaussian = exp(0.5 * betad),
Gamma = exp(-0.5 * betad),
Expand Down
20 changes: 0 additions & 20 deletions R/check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -423,26 +423,6 @@ pp_check.glmmTMB <-
#' S3method(bayesplot::pp_check, BFBayesFactor)



# aliases --------------------------

#' @rdname check_predictions
#' @export
posterior_predictive_check <- function(object, ...) {
.Deprecated("check_predictions()")
check_predictions(object, ...)
}

#' @rdname check_predictions
#' @export
check_posterior_predictions <- function(object, ...) {
.Deprecated("check_predictions()")
check_predictions(object, ...)
}




# methods -----------------------


Expand Down
Loading

0 comments on commit a8aa04d

Please sign in to comment.