diff --git a/R/check_model_diagnostics.R b/R/check_model_diagnostics.R index c6f91a655..6e398efa8 100644 --- a/R/check_model_diagnostics.R +++ b/R/check_model_diagnostics.R @@ -85,9 +85,9 @@ # prepare data for random effects QQ plot ---------------------------------- -.diag_reqq <- function(model, level = 0.95, model_info, verbose = TRUE) { +.diag_reqq <- function(model, level = 0.95, model_info = NULL, verbose = TRUE) { # check if we have mixed model - if (!model_info$is_mixed) { + if (is.null(model_info) || !model_info$is_mixed) { return(NULL) } @@ -156,7 +156,10 @@ r <- try(as.numeric(stats::residuals(model)), silent = TRUE) if (inherits(r, "try-error")) { - insight::format_alert(sprintf("Non-normality of residuals could not be computed. Cannot extract residuals from objects of class '%s'.", class(model)[1])) + insight::format_alert(sprintf( + "Non-normality of residuals could not be computed. Cannot extract residuals from objects of class '%s'.", + class(model)[1] + )) return(NULL) } @@ -223,7 +226,10 @@ if (is.null(ncv)) { if (verbose) { - insight::format_alert(sprintf("Non-constant error variance could not be computed. Cannot extract residuals from objects of class '%s'.", class(model)[1])) + insight::format_alert(sprintf( + "Non-constant error variance could not be computed. Cannot extract residuals from objects of class '%s'.", + class(model)[1] + )) } return(NULL) } @@ -264,7 +270,10 @@ if (is.null(r)) { if (verbose) { - insight::format_alert(sprintf("Homogeneity of variance could not be computed. Cannot extract residual variance from objects of class '%s'.", class(model)[1])) + insight::format_alert(sprintf( + "Homogeneity of variance could not be computed. Cannot extract residual variance from objects of class '%s'.", + class(model)[1] + )) } return(NULL) } @@ -327,7 +336,7 @@ } d$Prob <- stats::predict(model, type = ptype) d$Disp <- insight::get_sigma(model) - d$V <- d$Predicted * (1 + d$Predicted / d$Disp) * (1 - d$Prob) * (1 + d$Predicted * (1 + d$Predicted / d$Disp) * d$Prob) + d$V <- d$Predicted * (1 + d$Predicted / d$Disp) * (1 - d$Prob) * (1 + d$Predicted * (1 + d$Predicted / d$Disp) * d$Prob) # nolint d$StdRes <- insight::get_residuals(model, type = "pearson") } @@ -343,7 +352,7 @@ } d$Prob <- stats::predict(model, type = ptype) d$Disp <- stats::predict(model, type = "disp") - d$V <- d$Predicted * (1 + d$Predicted / d$Disp) * (1 - d$Prob) * (1 + d$Predicted * (1 + d$Predicted / d$Disp) * d$Prob) + d$V <- d$Predicted * (1 + d$Predicted / d$Disp) * (1 - d$Prob) * (1 + d$Predicted * (1 + d$Predicted / d$Disp) * d$Prob) # nolint d$StdRes <- insight::get_residuals(model, type = "pearson") }