Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: check_model() not implemented for models of class lm yet #630

Merged
merged 2 commits into from
Sep 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: performance
Title: Assessment of Regression Models Performance
Version: 0.10.5.4
Version: 0.10.5.5
Authors@R:
c(person(given = "Daniel",
family = "Lüdecke",
Expand Down
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
the previous method, which used `parallel::detectCores()`. Now you should
set the number of cores via `options(mc.cores = 4)`.

## Bug fixes

* Fixed issues is `check_model()` for models that used data sets with
variables of class `"haven_labelled"`.

# performance 0.10.5

## Changes to functions
Expand Down
8 changes: 4 additions & 4 deletions R/check_model_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@

# prepare data for random effects QQ plot ----------------------------------

.diag_reqq <- function(model, level = 0.95, model_info, verbose = TRUE) {

Check warning on line 88 in R/check_model_diagnostics.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model_diagnostics.R,line=88,col=45,[function_argument_linter] Arguments without defaults should come before arguments with defaults.
# check if we have mixed model
if (!model_info$is_mixed) {
return(NULL)
Expand Down Expand Up @@ -153,10 +153,10 @@
# prepare data for normality of residuals plot ----------------------------------

.diag_norm <- function(model, verbose = TRUE) {
r <- try(stats::residuals(model), silent = TRUE)
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]))

Check warning on line 159 in R/check_model_diagnostics.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model_diagnostics.R,line=159,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 157 characters.
return(NULL)
}

Expand All @@ -174,7 +174,7 @@

if (inherits(model, "lm", which = TRUE) == 1) {
cook_levels <- round(stats::qf(0.5, s$fstatistic[2], s$fstatistic[3]), 2)
} else if (!is.null(threshold)) {

Check warning on line 177 in R/check_model_diagnostics.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model_diagnostics.R,line=177,col=14,[if_not_else_linter] In a simple if/else statement, prefer `if (A) x else y` to the less-readable `if (!A) y else x`.
cook_levels <- threshold
} else {
cook_levels <- c(0.5, 1)
Expand All @@ -183,7 +183,7 @@
n_params <- tryCatch(model$rank, error = function(e) insight::n_parameters(model))

infl <- stats::influence(model, do.coef = FALSE)
resid <- insight::get_residuals(model)
resid <- as.numeric(insight::get_residuals(model))

std_resid <- tryCatch(stats::rstandard(model, infl), error = function(e) resid)

Expand Down Expand Up @@ -212,8 +212,8 @@
ncv <- tryCatch(
{
data.frame(
x = stats::fitted(model),
y = stats::residuals(model)
x = as.numeric(stats::fitted(model)),
y = as.numeric(stats::residuals(model))
)
},
error = function(e) {
Expand All @@ -223,7 +223,7 @@

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]))

Check warning on line 226 in R/check_model_diagnostics.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model_diagnostics.R,line=226,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 160 characters.
}
return(NULL)
}
Expand Down Expand Up @@ -264,7 +264,7 @@

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]))

Check warning on line 267 in R/check_model_diagnostics.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model_diagnostics.R,line=267,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 164 characters.
}
return(NULL)
}
Expand Down Expand Up @@ -327,7 +327,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)

Check warning on line 330 in R/check_model_diagnostics.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model_diagnostics.R,line=330,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
d$StdRes <- insight::get_residuals(model, type = "pearson")
}

Expand All @@ -343,7 +343,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)

Check warning on line 346 in R/check_model_diagnostics.R

View workflow job for this annotation

GitHub Actions / lint-changed-files / lint-changed-files

file=R/check_model_diagnostics.R,line=346,col=121,[line_length_linter] Lines should not be more than 120 characters. This line is 124 characters.
d$StdRes <- insight::get_residuals(model, type = "pearson")
}

Expand Down
Loading