Skip to content

Commit

Permalink
lintr, styler, fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Mar 16, 2024
1 parent 7111028 commit 6d7ee1c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
3 changes: 1 addition & 2 deletions R/check_model.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,7 @@ check_model.model_fit <- function(x,
dat <- list()

dat$VIF <- .diag_vif(model, verbose = verbose)
dat$QQ <- switch(
residual_type,
dat$QQ <- switch(residual_type,
simulated = simulate_residuals(model, ...),
.diag_qq(model, model_info = model_info, verbose = verbose)
)
Expand Down
8 changes: 4 additions & 4 deletions R/check_normality.R
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ check_normality.merMod <- function(x, effects = c("fixed", "random"), ...) {
}
},
error = function(e) {
return(NULL)
NULL

Check warning on line 203 in R/check_normality.R

View check run for this annotation

Codecov / codecov/patch

R/check_normality.R#L203

Added line #L203 was not covered by tests
}
)

Expand Down Expand Up @@ -262,23 +262,23 @@ check_normality.BFBayesFactor <- check_normality.afex_aov
# helper ---------------------

.check_normality <- function(x, model, type = "residuals") {
ts <- .safe({
ts_result <- .safe({
if (length(x) >= 5000) {
suppressWarnings(stats::ks.test(x, y = "pnorm", alternative = "two.sided"))
} else {
stats::shapiro.test(x)
}
})

if (is.null(ts)) {
if (is.null(ts_result)) {
insight::print_color(
sprintf("`check_normality()` does not support models of class `%s`.\n", class(model)[1]),
"red"
)
return(NULL)
}

out <- ts$p.value
out <- ts_result$p.value
attr(out, "type") <- type

out
Expand Down
12 changes: 6 additions & 6 deletions R/check_zeroinflation.R
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ check_zeroinflation.default <- function(x, tolerance = 0.05, ...) {
}

# get predicted zero-counts
if (!is.null(theta)) {
pred.zero <- round(sum(stats::dnbinom(x = 0, size = theta, mu = mu)))
} else {
if (is.null(theta)) {
pred.zero <- round(sum(stats::dpois(x = 0, lambda = mu)))
} else {
pred.zero <- round(sum(stats::dnbinom(x = 0, size = theta, mu = mu)))
}

# proportion
Expand Down Expand Up @@ -156,10 +156,10 @@ print.check_zi <- function(x, ...) {
lower <- 1 - x$tolerance
upper <- 1 + x$tolerance

if (!is.null(x$p.value)) {
p_string <- paste0(" (", insight::format_p(x$p.value), ")")
} else {
if (is.null(x$p.value)) {
p_string <- ""

Check warning on line 160 in R/check_zeroinflation.R

View check run for this annotation

Codecov / codecov/patch

R/check_zeroinflation.R#L159-L160

Added lines #L159 - L160 were not covered by tests
} else {
p_string <- paste0(" (", insight::format_p(x$p.value), ")")

Check warning on line 162 in R/check_zeroinflation.R

View check run for this annotation

Codecov / codecov/patch

R/check_zeroinflation.R#L162

Added line #L162 was not covered by tests
}

if (x$ratio < lower) {
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-check_residuals.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ test_that("check_singularity, lme4", {
quine.nb1 <- MASS::glm.nb(x ~ mu)
set.seed(123)
result <- check_residuals(quine.nb1)
expect_equal(result, 0.000665414, tolerance = 1e-3)
expect_equal(result, 0.000665414, tolerance = 1e-3, ignore_attr = TRUE)
})

0 comments on commit 6d7ee1c

Please sign in to comment.