Skip to content

Commit c05ee00

Browse files
authored
Harmonizing argument names for check_* functions (#886)
1 parent dbd7dff commit c05ee00

14 files changed

Lines changed: 251 additions & 162 deletions

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Type: Package
22
Package: performance
33
Title: Assessment of Regression Models Performance
4-
Version: 0.15.3.6
4+
Version: 0.15.3.7
55
Authors@R:
66
c(person(given = "Daniel",
77
family = "Lüdecke",

NEWS.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,17 @@
66
`RMSR` (Root Mean Square Residual) instead of `RMSA`. The `RMSR_corrected`
77
column (previously `RMSA_corrected`) is also renamed accordingly.
88

9+
* The first argument in `check_model()`, `check_predictions()` and
10+
`check_convergence()` was renamed to `model`.
11+
912
## Changes
1013

1114
* `check_model()` now limits the number of data points for models with many
1215
observations, to reduce the time for rendering the plot via the `maximum_dots`
1316
argument.
1417

1518
* `check_model()` can now show or hide confidence intervals using the `show_ci`
16-
argument. For models with only categorical predictors, cnmfidence intervals
19+
argument. For models with only categorical predictors, confidence intervals
1720
are not shown by default.
1821

1922
## Bug fixes

R/check_convergence.R

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
#' @description `check_convergence()` provides an alternative convergence
55
#' test for `merMod`-objects.
66
#'
7-
#' @param x A `merMod` or `glmmTMB`-object.
7+
#' @param model A `merMod` or `glmmTMB`-object.
88
#' @param tolerance Indicates up to which value the convergence result is
99
#' accepted. The smaller `tolerance` is, the stricter the test will be.
10+
#' @param x Deprecated, please use `model` instead.
1011
#' @param ... Currently not used.
1112
#'
1213
#' @return `TRUE` if convergence is fine and `FALSE` if convergence
@@ -50,8 +51,16 @@
5051
#' check_convergence(model)
5152
#' }
5253
#' @export
53-
check_convergence <- function(x, tolerance = 0.001, ...) {
54-
out <- .safe(insight::is_converged(x, tolerance = tolerance, ...))
54+
check_convergence <- function(model = NULL, tolerance = 0.001, x = NULL, ...) {
55+
## TODO remove deprecation warning later
56+
if (!is.null(x) && is.null(model)) {
57+
insight::format_warning(
58+
"Argument `x` is deprecated; please use `model` instead."
59+
)
60+
model <- x
61+
}
62+
.is_model_valid(model)
63+
out <- .safe(insight::is_converged(model, tolerance = tolerance, ...))
5564
if (is.null(out)) {
5665
insight::format_alert("Could not compute convergence information.")
5766
out <- NA

R/check_model.R

Lines changed: 57 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#' If `check_model()` doesn't work as expected, try setting `verbose = TRUE` to
1010
#' get hints about possible problems.
1111
#'
12-
#' @param x A model object.
12+
#' @param model A model object.
1313
#' @param size_dot,size_line Size of line and dot-geoms.
1414
#' @param base_size,size_title,size_axis_title Base font size for axis and plot titles.
1515
#' @param panel Logical, if `TRUE`, plots are arranged as panels; else,
@@ -56,6 +56,8 @@
5656
#' @param verbose If `FALSE` (default), suppress most warning messages.
5757
#' @param ... Arguments passed down to the individual check functions, especially
5858
#' to `check_predictions()` and `binned_residuals()`.
59+
#' @param x Deprecated, please use `model` instead.
60+
#'
5961
#' @inheritParams check_predictions
6062
#'
6163
#' @return The data frame that is used for plotting.
@@ -191,7 +193,7 @@
191193
#' check_model(m, panel = FALSE)
192194
#' }
193195
#' @export
194-
check_model <- function(x, ...) {
196+
check_model <- function(model = NULL, ...) {
195197
UseMethod("check_model")
196198
}
197199

@@ -201,7 +203,7 @@ check_model <- function(x, ...) {
201203
#' @rdname check_model
202204
#' @export
203205
check_model.default <- function(
204-
x,
206+
model = NULL,
205207
panel = TRUE,
206208
check = "all",
207209
detrend = TRUE,
@@ -221,14 +223,23 @@ check_model.default <- function(
221223
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
222224
theme = see::theme_lucid(),
223225
verbose = FALSE,
226+
x = NULL,
224227
...
225228
) {
229+
## TODO remove deprecation warning later
230+
if (!is.null(x) && is.null(model)) {
231+
insight::format_warning(
232+
"Argument `x` is deprecated; please use `model` instead."
233+
)
234+
model <- x
235+
}
236+
226237
# check model formula
227238
if (verbose) {
228-
insight::formula_ok(x)
239+
insight::formula_ok(model)
229240
}
230241

231-
minfo <- insight::model_info(x, verbose = FALSE)
242+
minfo <- insight::model_info(model, verbose = FALSE)
232243

233244
# set default for residual_type
234245
if (is.null(residual_type)) {
@@ -250,10 +261,10 @@ check_model.default <- function(
250261

251262
assumptions_data <- tryCatch(
252263
if (minfo$is_bayesian) {
253-
suppressWarnings(.check_assumptions_stan(x, ...))
264+
suppressWarnings(.check_assumptions_stan(model, ...))
254265
} else if (minfo$is_linear) {
255266
suppressWarnings(.check_assumptions_linear(
256-
x,
267+
model,
257268
minfo,
258269
check,
259270
residual_type,
@@ -262,7 +273,7 @@ check_model.default <- function(
262273
))
263274
} else {
264275
suppressWarnings(.check_assumptions_glm(
265-
x,
276+
model,
266277
minfo,
267278
check,
268279
residual_type,
@@ -283,7 +294,7 @@ check_model.default <- function(
283294
paste("`check_model()` returned following error:", cleaned_string),
284295
paste0(
285296
"\nIf the error message does not help identifying your problem, another reason why `check_model()` failed might be that models of class `",
286-
class(x)[1],
297+
class(model)[1],
287298
"` are not yet supported."
288299
) # nolint
289300
)
@@ -293,7 +304,7 @@ check_model.default <- function(
293304
if (is.null(assumptions_data$QQ) && residual_type == "simulated") {
294305
insight::format_alert(paste0(
295306
"Cannot simulate residuals for models of class `",
296-
class(x)[1],
307+
class(model)[1],
297308
"`. Please try `check_model(..., residual_type = \"normal\")` instead."
298309
))
299310
}
@@ -309,7 +320,7 @@ check_model.default <- function(
309320
}
310321

311322
# set default for show_dots, based on "model size"
312-
n <- .safe(insight::n_obs(x))
323+
n <- .safe(insight::n_obs(model))
313324
if (is.null(show_dots)) {
314325
show_dots <- is.null(n) || n <= 1e5
315326
}
@@ -322,7 +333,7 @@ check_model.default <- function(
322333
}
323334

324335
# if we have only categorical predictors, we don't show CI by default
325-
parameter_types <- .safe(parameters::parameters_type(x))
336+
parameter_types <- .safe(parameters::parameters_type(model))
326337
if (
327338
!is.null(parameter_types) && all(parameter_types$Type %in% c("intercept", "factor"))
328339
) {
@@ -350,7 +361,7 @@ check_model.default <- function(
350361
attr(assumptions_data, "bandwidth") <- bandwidth
351362
attr(assumptions_data, "type") <- type
352363
attr(assumptions_data, "maximum_dots") <- maximum_dots
353-
attr(assumptions_data, "model_class") <- class(x)[1]
364+
attr(assumptions_data, "model_class") <- class(model)[1]
354365
assumptions_data
355366
}
356367

@@ -377,7 +388,7 @@ plot.check_model <- function(x, ...) {
377388

378389
#' @export
379390
check_model.stanreg <- function(
380-
x,
391+
model = NULL,
381392
panel = TRUE,
382393
check = "all",
383394
detrend = TRUE,
@@ -397,10 +408,19 @@ check_model.stanreg <- function(
397408
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
398409
theme = see::theme_lucid(),
399410
verbose = FALSE,
411+
x = NULL,
400412
...
401413
) {
414+
## TODO remove deprecation warning later
415+
if (!is.null(x) && is.null(model)) {
416+
insight::format_warning(
417+
"Argument `x` is deprecated; please use `model` instead."
418+
)
419+
model <- x
420+
}
421+
402422
check_model(
403-
bayestestR::bayesian_as_frequentist(x),
423+
model = .safe(bayestestR::bayesian_as_frequentist(model)),
404424
size_dot = size_dot,
405425
size_line = size_line,
406426
panel = panel,
@@ -430,7 +450,7 @@ check_model.brmsfit <- check_model.stanreg
430450

431451
#' @export
432452
check_model.model_fit <- function(
433-
x,
453+
model = NULL,
434454
panel = TRUE,
435455
check = "all",
436456
detrend = TRUE,
@@ -450,10 +470,19 @@ check_model.model_fit <- function(
450470
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
451471
theme = see::theme_lucid(),
452472
verbose = FALSE,
473+
x = NULL,
453474
...
454475
) {
476+
## TODO remove deprecation warning later
477+
if (!is.null(x) && is.null(model)) {
478+
insight::format_warning(
479+
"Argument `x` is deprecated; please use `model` instead."
480+
)
481+
model <- x
482+
}
483+
455484
check_model(
456-
x$fit,
485+
model$fit,
457486
size_dot = size_dot,
458487
size_line = size_line,
459488
panel = panel,
@@ -479,7 +508,7 @@ check_model.model_fit <- function(
479508

480509
#' @export
481510
check_model.performance_simres <- function(
482-
x,
511+
model = NULL,
483512
panel = TRUE,
484513
check = "all",
485514
detrend = TRUE,
@@ -499,10 +528,19 @@ check_model.performance_simres <- function(
499528
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
500529
theme = see::theme_lucid(),
501530
verbose = FALSE,
531+
x = NULL,
502532
...
503533
) {
534+
## TODO remove deprecation warning later
535+
if (!is.null(x) && is.null(model)) {
536+
insight::format_warning(
537+
"Argument `x` is deprecated; please use `model` instead."
538+
)
539+
model <- x
540+
}
541+
504542
check_model(
505-
x$fittedModel,
543+
model$fittedModel,
506544
size_dot = size_dot,
507545
size_line = size_line,
508546
panel = panel,

0 commit comments

Comments
 (0)