Skip to content

Commit

Permalink
glmmTMB shouldn't use qqhalfnormal
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 5, 2024
1 parent 3e13fc2 commit 5c17618
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 3 additions & 1 deletion R/plot.check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ plot.see_check_model <- function(x,
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
Expand Down Expand Up @@ -174,7 +175,8 @@ plot.see_check_model <- function(x,
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 @@ -70,9 +70,12 @@ plot.see_check_normality <- function(x,
} 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 @@ plot.see_check_normality <- function(x,
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 @@ plot.see_check_normality <- function(x,
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

0 comments on commit 5c17618

Please sign in to comment.