From 5b99a2317153f9c66567690f796961c0217b8976 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Mar 2024 08:23:10 +0100 Subject: [PATCH 1/3] More args for font size in check_model --- DESCRIPTION | 2 +- R/check_model.R | 80 +++++++++++++++++++++++++--------------------- man/check_model.Rd | 57 +++++++++++++++++---------------- 3 files changed, 74 insertions(+), 65 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 7ff8da559..5998603cd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: performance Title: Assessment of Regression Models Performance -Version: 0.11.0.1 +Version: 0.11.0.2 Authors@R: c(person(given = "Daniel", family = "Lüdecke", diff --git a/R/check_model.R b/R/check_model.R index d075fe5cb..d68c4a82e 100644 --- a/R/check_model.R +++ b/R/check_model.R @@ -9,7 +9,7 @@ #' #' @param x A model object. #' @param dot_size,line_size Size of line and dot-geoms. -#' @param base_size Base font size for plots. +#' @param base_size,axis_title_size 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 @@ -184,20 +184,21 @@ check_model <- function(x, ...) { #' @rdname check_model #' @export check_model.default <- function(x, - dot_size = 2, - line_size = 0.8, panel = TRUE, check = "all", - alpha = 0.2, - dot_alpha = 0.8, - colors = c("#3aaf85", "#1b6ca8", "#cd201f"), - theme = "see::theme_lucid", - base_size = 10, detrend = TRUE, - show_dots = NULL, bandwidth = "nrd", type = "density", residual_type = NULL, + show_dots = NULL, + dot_size = 2, + line_size = 0.8, + axis_title_size = base_size * 0.8, + base_size = 10, + alpha = 0.2, + dot_alpha = 0.8, + colors = c("#3aaf85", "#1b6ca8", "#cd201f"), + theme = "see::theme_lucid", verbose = FALSE, ...) { # check model formula @@ -264,6 +265,7 @@ check_model.default <- function(x, attr(assumptions_data, "dot_size") <- dot_size attr(assumptions_data, "line_size") <- line_size attr(assumptions_data, "base_size") <- base_size + attr(assumptions_data, "axis_title_size") <- axis_title_size attr(assumptions_data, "check") <- check attr(assumptions_data, "alpha") <- alpha attr(assumptions_data, "dot_alpha") <- dot_alpha @@ -303,21 +305,22 @@ plot.check_model <- function(x, ...) { #' @export check_model.stanreg <- function(x, - dot_size = 2, - line_size = 0.8, panel = TRUE, check = "all", - alpha = 0.2, - dot_alpha = 0.8, - colors = c("#3aaf85", "#1b6ca8", "#cd201f"), - theme = "see::theme_lucid", - base_size = 10, detrend = TRUE, - show_dots = NULL, bandwidth = "nrd", type = "density", residual_type = NULL, - verbose = TRUE, + show_dots = NULL, + dot_size = 2, + line_size = 0.8, + axis_title_size = base_size * 0.8, + base_size = 10, + alpha = 0.2, + dot_alpha = 0.8, + colors = c("#3aaf85", "#1b6ca8", "#cd201f"), + theme = "see::theme_lucid", + verbose = FALSE, ...) { check_model(bayestestR::bayesian_as_frequentist(x), dot_size = dot_size, @@ -329,6 +332,7 @@ check_model.stanreg <- function(x, colors = colors, theme = theme, base_size = base_size, + axis_title_size = axis_title_size, detrend = detrend, show_dots = show_dots, bandwidth = bandwidth, @@ -346,21 +350,22 @@ check_model.brmsfit <- check_model.stanreg #' @export check_model.model_fit <- function(x, - dot_size = 2, - line_size = 0.8, panel = TRUE, check = "all", - alpha = 0.2, - dot_alpha = 0.8, - colors = c("#3aaf85", "#1b6ca8", "#cd201f"), - theme = "see::theme_lucid", - base_size = 10, detrend = TRUE, - show_dots = NULL, bandwidth = "nrd", type = "density", residual_type = NULL, - verbose = TRUE, + show_dots = NULL, + dot_size = 2, + line_size = 0.8, + axis_title_size = base_size * 0.8, + base_size = 10, + alpha = 0.2, + dot_alpha = 0.8, + colors = c("#3aaf85", "#1b6ca8", "#cd201f"), + theme = "see::theme_lucid", + verbose = FALSE, ...) { check_model( x$fit, @@ -369,6 +374,7 @@ check_model.model_fit <- function(x, panel = panel, check = check, alpha = alpha, + axis_title_size = axis_title_size, dot_alpha = dot_alpha, colors = colors, theme = theme, @@ -386,21 +392,22 @@ check_model.model_fit <- function(x, #' @export check_model.performance_simres <- function(x, - dot_size = 2, - line_size = 0.8, panel = TRUE, check = "all", - alpha = 0.2, - dot_alpha = 0.8, - colors = c("#3aaf85", "#1b6ca8", "#cd201f"), - theme = "see::theme_lucid", - base_size = 10, detrend = TRUE, - show_dots = NULL, bandwidth = "nrd", type = "density", residual_type = NULL, - verbose = TRUE, + show_dots = NULL, + dot_size = 2, + line_size = 0.8, + axis_title_size = base_size * 0.8, + base_size = 10, + alpha = 0.2, + dot_alpha = 0.8, + colors = c("#3aaf85", "#1b6ca8", "#cd201f"), + theme = "see::theme_lucid", + verbose = FALSE, ...) { check_model( x$fittedModel, @@ -410,6 +417,7 @@ check_model.performance_simres <- function(x, check = check, alpha = alpha, dot_alpha = dot_alpha, + axis_title_size = axis_title_size, colors = colors, theme = theme, base_size = base_size, diff --git a/man/check_model.Rd b/man/check_model.Rd index 3c90b67b9..0ca3f2d7d 100644 --- a/man/check_model.Rd +++ b/man/check_model.Rd @@ -9,20 +9,21 @@ check_model(x, ...) \method{check_model}{default}( x, - dot_size = 2, - line_size = 0.8, panel = TRUE, check = "all", - alpha = 0.2, - dot_alpha = 0.8, - colors = c("#3aaf85", "#1b6ca8", "#cd201f"), - theme = "see::theme_lucid", - base_size = 10, detrend = TRUE, - show_dots = NULL, bandwidth = "nrd", type = "density", residual_type = NULL, + show_dots = NULL, + dot_size = 2, + line_size = 0.8, + axis_title_size = base_size * 0.8, + base_size = 10, + alpha = 0.2, + dot_alpha = 0.8, + colors = c("#3aaf85", "#1b6ca8", "#cd201f"), + theme = "see::theme_lucid", verbose = FALSE, ... ) @@ -33,8 +34,6 @@ check_model(x, ...) \item{...}{Arguments passed down to the individual check functions, especially to \code{check_predictions()} and \code{binned_residuals()}.} -\item{dot_size, line_size}{Size of line and dot-geoms.} - \item{panel}{Logical, if \code{TRUE}, plots are arranged as panels; else, single plots for each diagnostic are returned.} @@ -48,29 +47,11 @@ effects and only available for mixed models. \code{"ncv"} is an alias for heteroscedasticity, as well as the linear relationship. By default, all possible checks are performed and plotted.} -\item{alpha, dot_alpha}{The alpha level of the confidence bands and dot-geoms. -Scalar from 0 to 1.} - -\item{colors}{Character vector with color codes (hex-format). Must be of -length 3. First color is usually used for reference lines, second color -for dots, and third color for outliers or extreme values.} - -\item{theme}{String, indicating the name of the plot-theme. Must be in the -format \code{"package::theme_name"} (e.g. \code{"ggplot2::theme_minimal"}).} - -\item{base_size}{Base font size for plots.} - \item{detrend}{Logical. Should Q-Q/P-P plots be detrended? Defaults to \code{TRUE} for linear models or when \code{residual_type = "normal"}. Defaults to \code{FALSE} for QQ plots based on simulated residuals (i.e. when \code{residual_type = "simulated"}).} -\item{show_dots}{Logical, if \code{TRUE}, will show data points in the plot. Set -to \code{FALSE} for models with many observations, if generating the plot is too -time-consuming. By default, \code{show_dots = NULL}. In this case \code{check_model()} -tries to guess whether performance will be poor due to a very large model -and thus automatically shows or hides dots.} - \item{bandwidth}{A character string indicating the smoothing bandwidth to be used. Unlike \code{stats::density()}, which used \code{"nrd0"} as default, the default used here is \code{"nrd"} (which seems to give more plausible results @@ -91,6 +72,26 @@ the model. Setting \code{residual_type = "normal"} for non-Gaussian models will use a half-normal Q-Q plot of the absolute value of the standardized deviance residuals.} +\item{show_dots}{Logical, if \code{TRUE}, will show data points in the plot. Set +to \code{FALSE} for models with many observations, if generating the plot is too +time-consuming. By default, \code{show_dots = NULL}. In this case \code{check_model()} +tries to guess whether performance will be poor due to a very large model +and thus automatically shows or hides dots.} + +\item{dot_size, line_size}{Size of line and dot-geoms.} + +\item{base_size, axis_title_size}{Base font size for axis and plot titles.} + +\item{alpha, dot_alpha}{The alpha level of the confidence bands and dot-geoms. +Scalar from 0 to 1.} + +\item{colors}{Character vector with color codes (hex-format). Must be of +length 3. First color is usually used for reference lines, second color +for dots, and third color for outliers or extreme values.} + +\item{theme}{String, indicating the name of the plot-theme. Must be in the +format \code{"package::theme_name"} (e.g. \code{"ggplot2::theme_minimal"}).} + \item{verbose}{If \code{FALSE} (default), suppress most warning messages.} } \value{ From d7d92ba23dbb35b089912e2e28246b9fa4ee7da8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Mar 2024 12:02:07 +0100 Subject: [PATCH 2/3] args --- R/check_model.R | 6 ++++-- man/check_model.Rd | 5 +++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/R/check_model.R b/R/check_model.R index d68c4a82e..b6076ab3b 100644 --- a/R/check_model.R +++ b/R/check_model.R @@ -9,7 +9,7 @@ #' #' @param x A model object. #' @param dot_size,line_size Size of line and dot-geoms. -#' @param base_size,axis_title_size Base font size for axis and plot titles. +#' @param base_size,title_size,axis_title_size 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 @@ -193,7 +193,8 @@ check_model.default <- function(x, show_dots = NULL, dot_size = 2, line_size = 0.8, - axis_title_size = base_size * 0.8, + title_size = 12, + axis_title_size = base_size, base_size = 10, alpha = 0.2, dot_alpha = 0.8, @@ -266,6 +267,7 @@ check_model.default <- function(x, attr(assumptions_data, "line_size") <- line_size 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, "check") <- check attr(assumptions_data, "alpha") <- alpha attr(assumptions_data, "dot_alpha") <- dot_alpha diff --git a/man/check_model.Rd b/man/check_model.Rd index 0ca3f2d7d..bb4898df8 100644 --- a/man/check_model.Rd +++ b/man/check_model.Rd @@ -18,7 +18,8 @@ check_model(x, ...) show_dots = NULL, dot_size = 2, line_size = 0.8, - axis_title_size = base_size * 0.8, + title_size = 12, + axis_title_size = base_size, base_size = 10, alpha = 0.2, dot_alpha = 0.8, @@ -80,7 +81,7 @@ and thus automatically shows or hides dots.} \item{dot_size, line_size}{Size of line and dot-geoms.} -\item{base_size, axis_title_size}{Base font size for axis and plot titles.} +\item{base_size, title_size, axis_title_size}{Base font size for axis and plot titles.} \item{alpha, dot_alpha}{The alpha level of the confidence bands and dot-geoms. Scalar from 0 to 1.} From 2ce0af8c89600816db8215c1868b6b0cb063d651 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 27 Mar 2024 12:03:18 +0100 Subject: [PATCH 3/3] minor --- R/check_model.R | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/R/check_model.R b/R/check_model.R index b6076ab3b..d9d54682a 100644 --- a/R/check_model.R +++ b/R/check_model.R @@ -316,7 +316,8 @@ check_model.stanreg <- function(x, show_dots = NULL, dot_size = 2, line_size = 0.8, - axis_title_size = base_size * 0.8, + title_size = 12, + axis_title_size = base_size, base_size = 10, alpha = 0.2, dot_alpha = 0.8, @@ -361,7 +362,8 @@ check_model.model_fit <- function(x, show_dots = NULL, dot_size = 2, line_size = 0.8, - axis_title_size = base_size * 0.8, + title_size = 12, + axis_title_size = base_size, base_size = 10, alpha = 0.2, dot_alpha = 0.8, @@ -403,7 +405,8 @@ check_model.performance_simres <- function(x, show_dots = NULL, dot_size = 2, line_size = 0.8, - axis_title_size = base_size * 0.8, + title_size = 12, + axis_title_size = base_size, base_size = 10, alpha = 0.2, dot_alpha = 0.8,