Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Oct 29, 2023
1 parent e41c59a commit 3fbf629
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
30 changes: 16 additions & 14 deletions R/check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -197,10 +197,10 @@ pp_check.lm <- function(object,
out <- .check_re_formula(out, object, iterations, re_formula, verbose, ...)

# save information about model
if (!is.null(model_info)) {
minfo <- model_info
} else {
if (is.null(model_info)) {
minfo <- insight::model_info(object)
} else {
minfo <- model_info
}

# glmmTMB returns column matrix for bernoulli
Expand All @@ -215,9 +215,10 @@ pp_check.lm <- function(object,
}

if (is.null(out)) {
insight::format_error(
sprintf("Could not simulate responses. Maybe there is no `simulate()` for objects of class `%s`?", class(object)[1])
)
insight::format_error(sprintf(
"Could not simulate responses. Maybe there is no `simulate()` for objects of class `%s`?",
class(object)[1]
))
}

# get response data, and response term, to check for transformations
Expand Down Expand Up @@ -274,9 +275,10 @@ pp_check.glm <- function(object,
out <- .check_re_formula(out, object, iterations, re_formula, verbose, ...)

if (is.null(out)) {
insight::format_error(
sprintf("Could not simulate responses. Maybe there is no `simulate()` for objects of class `%s`?", class(object)[1])
)
insight::format_error(sprintf(
"Could not simulate responses. Maybe there is no `simulate()` for objects of class `%s`?",
class(object)[1]
))
}

# get response data, and response term
Expand All @@ -288,10 +290,10 @@ pp_check.glm <- function(object,
out$y <- response[, 1] / rowSums(response, na.rm = TRUE)

# safe information about model
if (!is.null(model_info)) {
minfo <- model_info
} else {
if (is.null(model_info)) {
minfo <- insight::model_info(object)
} else {
minfo <- model_info
}

attr(out, "check_range") <- check_range
Expand Down Expand Up @@ -363,14 +365,14 @@ print.performance_pp_check <- function(x, verbose = TRUE, ...) {
if (is.numeric(original)) {
if (min(replicated) > min(original)) {
insight::print_color(
insight::format_message("Warning: Minimum value of original data is not included in the replicated data.", "Model may not capture the variation of the data."),
insight::format_message("Warning: Minimum value of original data is not included in the replicated data.", "Model may not capture the variation of the data."), # nolint
"red"
)
}

if (max(replicated) < max(original)) {
insight::print_color(
insight::format_message("Warning: Maximum value of original data is not included in the replicated data.", "Model may not capture the variation of the data."),
insight::format_message("Warning: Maximum value of original data is not included in the replicated data.", "Model may not capture the variation of the data."), # nolint
"red"
)
}
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-check_predictions.R
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,6 @@ test_that("check_predictions, glm, binomial", {
set.seed(1)
out4 <- check_predictions(mod4)


dput(head(out4$sim_1))
expect_equal(head(out1$sim_1), c(1, 0.9, 0.9, 0.8, 1, 0.8), tolerance = 1e-4)
expect_false(attributes(out1)$model_info$is_bernoulli)
expect_equal(head(out2$sim_1), c(1, 0.9, 0.9, 0.8, 1, 0.8), tolerance = 1e-4)
Expand Down

0 comments on commit 3fbf629

Please sign in to comment.