Skip to content

Commit

Permalink
Plotting normality of residuals: Scaling issues / differences
Browse files Browse the repository at this point in the history
Fixes #335
  • Loading branch information
strengejacke committed Jun 9, 2024
1 parent 3687f60 commit c2a8582
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions R/plot.check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ plot.see_check_normality <- function(x,
)
)
y_lab <- "|Std. Deviance Residuals|"
} else if (requireNamespace("qqplotr", quietly = TRUE)) {
} else if (!requireNamespace("qqplotr", quietly = TRUE)) {
gg_init <- ggplot2::ggplot(x, ggplot2::aes(sample = .data$y))
qq_stuff <- list(
qqplotr::stat_qq_band(
Expand Down Expand Up @@ -276,6 +276,10 @@ plot.see_check_normality <- function(x,
} else {
insight::format_alert("For confidence bands, please install `qqplotr`.")

# to scale the detrended qq plot
N <- length(x$y)
SD <- stats::sd(x$y) * sqrt((N - 1) / N)

gg_init <- ggplot2::ggplot(x, ggplot2::aes(sample = .data$y))

qq_stuff <- list(
Expand All @@ -294,7 +298,10 @@ plot.see_check_normality <- function(x,
)
},
ggplot2::geom_qq(
mapping = if (detrend) ggplot2::aes(y = ggplot2::after_stat(.data$sample) - ggplot2::after_stat(.data$theoretical)),
mapping = if (detrend) ggplot2::aes(
x = ggplot2::after_stat(.data$theoretical * SD),
y = ggplot2::after_stat(.data$sample - .data$theoretical * SD)
),
shape = 16,
na.rm = TRUE,
stroke = 0,
Expand Down

0 comments on commit c2a8582

Please sign in to comment.