Skip to content

Commit

Permalink
Harnonize arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Nov 24, 2024
1 parent 71ca921 commit f94c5b1
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 58 deletions.
80 changes: 40 additions & 40 deletions R/check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
#' get hints about possible problems.
#'
#' @param x A model object.
#' @param dot_size,line_size Size of line and dot-geoms.
#' @param base_size,title_size,axis_title_size Base font size for axis and plot titles.
#' @param size_dot,size_line Size of line and dot-geoms.
#' @param base_size,size_title,size_axis_title Base font size for axis and plot titles.
#' @param panel Logical, if `TRUE`, plots are arranged as panels; else,
#' single plots for each diagnostic are returned.
#' @param check Character vector, indicating which checks for should be performed
Expand All @@ -23,7 +23,7 @@
#' `"linearity"`, and checks for non-constant variance, i.e. for
#' heteroscedasticity, as well as the linear relationship. By default, all
#' possible checks are performed and plotted.
#' @param alpha,dot_alpha The alpha level of the confidence bands and dot-geoms.
#' @param alpha,alpha_dot The alpha level of the confidence bands and dot-geoms.
#' Scalar from 0 to 1.
#' @param colors Character vector with color codes (hex-format). Must be of
#' length 3. First color is usually used for reference lines, second color
Expand Down Expand Up @@ -196,13 +196,13 @@ check_model.default <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
Expand Down Expand Up @@ -277,14 +277,14 @@ check_model.default <- function(x,
}

attr(assumptions_data, "panel") <- panel
attr(assumptions_data, "dot_size") <- dot_size
attr(assumptions_data, "line_size") <- line_size
attr(assumptions_data, "dot_size") <- size_dot
attr(assumptions_data, "line_size") <- size_line
attr(assumptions_data, "base_size") <- base_size
attr(assumptions_data, "axis_title_size") <- axis_title_size
attr(assumptions_data, "title_size") <- title_size
attr(assumptions_data, "axis_title_size") <- size_axis_title
attr(assumptions_data, "title_size") <- size_title
attr(assumptions_data, "check") <- check
attr(assumptions_data, "alpha") <- alpha
attr(assumptions_data, "dot_alpha") <- dot_alpha
attr(assumptions_data, "dot_alpha") <- alpha_dot
attr(assumptions_data, "show_dots") <- isTRUE(show_dots)
attr(assumptions_data, "detrend") <- detrend
attr(assumptions_data, "colors") <- colors
Expand Down Expand Up @@ -328,28 +328,28 @@ check_model.stanreg <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
...) {
check_model(bayestestR::bayesian_as_frequentist(x),
dot_size = dot_size,
line_size = line_size,
size_dot = size_dot,
size_line = size_line,
panel = panel,
check = check,
alpha = alpha,
dot_alpha = dot_alpha,
alpha_dot = alpha_dot,
colors = colors,
theme = theme,
base_size = base_size,
axis_title_size = axis_title_size,
size_axis_title = size_axis_title,
detrend = detrend,
show_dots = show_dots,
bandwidth = bandwidth,
Expand All @@ -374,26 +374,26 @@ check_model.model_fit <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
...) {
check_model(
x$fit,
dot_size = dot_size,
line_size = line_size,
size_dot = size_dot,
size_line = size_line,
panel = panel,
check = check,
alpha = alpha,
axis_title_size = axis_title_size,
dot_alpha = dot_alpha,
size_axis_title = size_axis_title,
alpha_dot = alpha_dot,
colors = colors,
theme = theme,
base_size = base_size,
Expand All @@ -417,26 +417,26 @@ check_model.performance_simres <- function(x,
type = "density",
residual_type = NULL,
show_dots = NULL,
dot_size = 2,
line_size = 0.8,
title_size = 12,
axis_title_size = base_size,
size_dot = 2,
size_line = 0.8,
size_title = 12,
size_axis_title = base_size,
base_size = 10,
alpha = 0.2,
dot_alpha = 0.8,
alpha_dot = 0.8,
colors = c("#3aaf85", "#1b6ca8", "#cd201f"),
theme = "see::theme_lucid",
verbose = FALSE,
...) {
check_model(
x$fittedModel,
dot_size = dot_size,
line_size = line_size,
size_dot = size_dot,
size_line = size_line,
panel = panel,
check = check,
alpha = alpha,
dot_alpha = dot_alpha,
axis_title_size = axis_title_size,
alpha_dot = alpha_dot,
size_axis_title = size_axis_title,
colors = colors,
theme = theme,
base_size = base_size,
Expand Down
16 changes: 8 additions & 8 deletions man/check_model.Rd

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

12 changes: 6 additions & 6 deletions vignettes/check_model_practical.Rmd
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: "How to arrive at the best model fit"
output:
output:
rmarkdown::html_vignette:
toc: true
tags: [r, performance]
vignette: >
\usepackage[utf8]{inputenc}
%\VignetteIndexEntry{How to arrive at the best model fit}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
editor_options:
chunk_output_type: console
---

Expand Down Expand Up @@ -82,7 +82,7 @@ In *performance*, we can conduct a comprehensive visual inspection of our model
For now, we want to focus on the _posterior predictive checks_, _dispersion and zero-inflation_ as well as the Q-Q plot (_uniformity of residuals_).

```{r fig.height=12, fig.width=10}
check_model(model1, dot_size = 1.2)
check_model(model1, size_dot = 1.2)
```

Note that unlike `plot()`, which is a base R function to create diagnostic plots, `check_model()` relies on *simulated residuals* for the Q-Q plot, which is more accurate for non-Gaussian models. See [this vignette](https://easystats.github.io/performance/articles/simulate_residuals.html) and the documentation of `simulate_residuals()` for further details.
Expand All @@ -108,7 +108,7 @@ model2 <- glmmTMB::glmmTMB(
family = poisson,
data = glmmTMB::Salamanders
)
check_model(model2, dot_size = 1.2)
check_model(model2, size_dot = 1.2)
```

Looking at the above plots, the zero-inflation seems to be addressed properly (see especially _posterior predictive checks_ and _uniformity of residuals_, the Q-Q plot). However, the overdispersion still could be present. We can check for these problems using `check_overdispersion()` and `check_zeroinflation()` again.
Expand All @@ -132,7 +132,7 @@ model3 <- glmmTMB::glmmTMB(
family = glmmTMB::nbinom1,
data = glmmTMB::Salamanders
)
check_model(model3, dot_size = 1.2)
check_model(model3, size_dot = 1.2)
```

Now we see that the plot showing _misspecified dispersion and zero-inflation_ suggests that the overdispersion is better addressed than before. Let us check again:
Expand Down Expand Up @@ -195,7 +195,7 @@ model4 <- glmmTMB::glmmTMB(
family = glmmTMB::nbinom2,
data = glmmTMB::Salamanders
)
check_model(model4, dot_size = 1.2)
check_model(model4, size_dot = 1.2)
check_overdispersion(model4)
Expand Down
8 changes: 4 additions & 4 deletions vignettes/simulate_residuals.Rmd
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
---
title: "Checking simulated residuals"
output:
output:
rmarkdown::html_vignette:
toc: true
tags: [r, performance]
vignette: >
\usepackage[utf8]{inputenc}
%\VignetteIndexEntry{Checking simulated residuals}
%\VignetteEngine{knitr::rmarkdown}
editor_options:
editor_options:
chunk_output_type: console
---

Expand Down Expand Up @@ -93,10 +93,10 @@ check_outliers(simulated_residuals)

The above three functions internally call `simulate_residuals()` for more complex models automatically, so you don't need to call `simulate_residuals()` yourself. Simulated residuals are usually more reliable than the standard residuals, especially for complex models.

Finally, you can even perform a visual check for the entire model, either by passing the model object directly, or the object returned from `simulate_residuals()`.
Finally, you can even perform a visual check for the entire model, either by passing the model object directly, or the object returned from `simulate_residuals()`.

```{r fig.height=12, fig.width=10}
check_model(simulated_residuals, dot_size = 1.5)
check_model(simulated_residuals, size_dot = 1.5)
```

The `check_model()` function is the main reason we don't want to prematurely extract the residuals in `simulate_residuals()`, because if we do then the simulated residual won't contain the model fit (`fittedModel` in the output below), so we won't be able to do all of the checks we would want to do using the model (e.g., posterior predictive checks).
Expand Down

0 comments on commit f94c5b1

Please sign in to comment.