Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

glmmTMB shouldn't use qqhalfnormal #322

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion R/plot.check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@
#'
#' @return A ggplot2-object.
#'
#' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html).

Check warning on line 12 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_model.R,line=12,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

Check warning on line 12 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_model.R,line=12,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examplesIf require("performance") && require("patchwork")
#' model <- lm(qsec ~ drat + wt, data = mtcars)
#' plot(check_model(model))
#'
#' @export
plot.see_check_model <- function(x,

Check warning on line 19 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_model.R,line=19,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 78 to at most 40.

Check warning on line 19 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_model.R,line=19,col=1,[cyclocomp_linter] Reduce the cyclomatic complexity of this function from 78 to at most 40.
style = theme_lucid,
colors = NULL,
type = c("density", "discrete_dots", "discrete_interval", "discrete_both"),
Expand All @@ -39,8 +39,9 @@
model_info <- attr(x, "model_info")
overdisp_type <- attr(x, "overdisp_type")
plot_type <- attr(x, "type")
model_class <- attr(x, "model_class")

if (missing(type) && !is.null(plot_type) && plot_type %in% c("density", "discrete_dots", "discrete_interval", "discrete_both")) {

Check warning on line 44 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_model.R,line=44,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.

Check warning on line 44 in R/plot.check_model.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_model.R,line=44,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 131 characters.
type <- plot_type
} else {
type <- match.arg(type)
Expand Down Expand Up @@ -174,7 +175,8 @@
colors = colors,
dot_alpha_level = dot_alpha_level,
show_dots = TRUE, # qq-plots w/o dots makes no sense
model_info = model_info
model_info = model_info,
model_class = model_class
)
}

Expand Down
13 changes: 9 additions & 4 deletions R/plot.check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
#'
#' @return A ggplot2-object.
#'
#' @seealso See also the vignette about [`check_model()`](https://easystats.github.io/performance/articles/check_model.html).

Check warning on line 27 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_normality.R,line=27,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.

Check warning on line 27 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_normality.R,line=27,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 125 characters.
#'
#' @examplesIf require("performance")
#' m <<- lm(mpg ~ wt + cyl + gear + disp, data = mtcars)
Expand Down Expand Up @@ -70,9 +70,12 @@
} else {
if (type == "qq") { # nolint
model_info <- attributes(x)$model_info
if (inherits(model, c("lme", "lmerMod", "merMod", "glmmTMB", "afex_aov", "BFBayesFactor"))) {
if (inherits(model, c("lme", "lmerMod", "merMod", "afex_aov", "BFBayesFactor"))) {
res_ <- suppressMessages(sort(stats::residuals(model), na.last = NA))
dat <- stats::na.omit(data.frame(y = res_))
} else if (inherits(model, "glmmTMB")) {
res_ <- abs(stats::residuals(model, type = "deviance"))
dat <- stats::na.omit(data.frame(y = res_))
} else if (inherits(model, "glm")) {
res_ <- abs(stats::rstandard(model, type = "deviance"))
fitted_ <- stats::qnorm((stats::ppoints(length(res_)) + 1) / 2)[order(order(res_))]
Expand All @@ -90,7 +93,8 @@
detrend = detrend,
dot_alpha_level = dot_alpha,
model_info = model_info,
method = method
method = method,
model_class = class(model)[1]
)
} else if (type == "density") {
r <- suppressMessages(stats::residuals(model))
Expand Down Expand Up @@ -166,10 +170,11 @@
colors = unname(social_colors(c("green", "blue", "red"))),
dot_alpha_level = 0.8,
show_dots = TRUE,
model_info = NULL) {
model_info = NULL,
model_class = NULL) {
qhalfnorm <- function(p) stats::qnorm((p + 1) / 2)
# qq-halfnorm for GLM
if (isTRUE(model_info$is_binomial) || isTRUE(model_info$is_count)) {
if (!identical(model_class, "glmmTMB") && (isTRUE(model_info$is_binomial) || isTRUE(model_info$is_count))) {
gg_init <- ggplot2::ggplot(x, ggplot2::aes(x = .data$x, y = .data$y))
qq_stuff <- list(
ggplot2::geom_point(
Expand Down Expand Up @@ -235,7 +240,7 @@
)
},
ggplot2::geom_qq(
mapping = if (detrend) ggplot2::aes(y = ggplot2::after_stat(.data$sample) - ggplot2::after_stat(.data$theoretical)),

Check warning on line 243 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/plot.check_normality.R,line=243,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.

Check warning on line 243 in R/plot.check_normality.R

View workflow job for this annotation

GitHub Actions / lint / lint

file=R/plot.check_normality.R,line=243,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
shape = 16,
na.rm = TRUE,
stroke = 0,
Expand Down
Loading