Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Apr 9, 2021
1 parent 0e63920 commit 3ad52e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions R/check_heteroscedasticity.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,14 @@ check_heteroskedasticity <- check_heteroscedasticity
#' @export
check_heteroscedasticity.default <- function(x, ...) {
# only for linear models
if (!insight::model_info(x)$is_linear) {
stop("This Breusch-Pagan Test currently only works Gaussian models.")
info <- insight::model_info(x)
if (!info$is_linear) {
msg <- "This Breusch-Pagan Test currently only works Gaussian models."
if (info$is_count) {
paste0(msg, " You may check your model for overdispersion or zero-inflation instead (see 'check_overdispersion()' and 'check_zeroinflation()').")
}
message(msg)
return(NULL)
}

r <- .pearson_residuals(x)
Expand Down
13 changes: 13 additions & 0 deletions R/check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,15 @@ check_normality <- function(x, ...) {
}


#' @importFrom insight model_info
#' @export
check_normality.default <- function(x, ...) {
# valid model?
if (!insight::model_info(x)$is_linear) {
message("Checking normality of residuals is only useful an appropriate assumption for linear models.")
return(NULL)
}

# check for normality of residuals
p.val <- .check_normality(stats::rstandard(x), x)

Expand All @@ -73,6 +80,12 @@ check_normality.merMod <- function(x, effects = c("fixed", "random"), ...) {
effects <- match.arg(effects)
info <- insight::model_info(x)

# valid model?
if (!info$is_linear) {
message("Checking normality of residuals is only useful an appropriate assumption for linear models.")
return(NULL)
}

if (effects == "random") {
if (!requireNamespace("lme4", quietly = TRUE)) {
stop("Package 'lme4' required for this function to work. Please install it.", call. = FALSE)
Expand Down

0 comments on commit 3ad52e2

Please sign in to comment.