Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
strengejacke committed Feb 26, 2022
1 parent be7e149 commit 916ebd1
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
* `test_performance()` now calls `test_lrt()` or `test_wald()` instead of
`test_vuong()` when package *CompQuadForm* is missing.

* `check_collinearity()` better supports GAM models.

## Bug fixes

* `model_performance()` for models from *lme4* did not report AICc when
Expand Down
10 changes: 8 additions & 2 deletions R/check_collinearity.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ check_collinearity.zerocount <- function(x,
assign <- .term_assignments(x, component, verbose = verbose)

# any assignment found?
if (is.null(assign)) {
if (is.null(assign) || all(is.na(assign))) {
if (verbose) {
warning(insight::format_message(sprintf("Could not extract model terms for the %s component of the model.", component), call. = FALSE))
}
Expand Down Expand Up @@ -442,8 +442,14 @@ check_collinearity.zerocount <- function(x,
}
}))

if (insight::is_gam_model(x)) {
model_params <- as.vector(unlist(unlist(insight::find_parameters(x)[c(component, "smooth_terms")])))
} else {
model_params <- insight::find_parameters(x)[[component]]
}

as.numeric(names(parms)[match(
insight::clean_names(insight::find_parameters(x)[[component]]),
insight::clean_names(model_params),
parms
)])
}
Expand Down
4 changes: 3 additions & 1 deletion R/check_model_diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


.diag_qq <- function(model) {
if (inherits(model, c("lme", "lmerMod", "merMod", "glmmTMB"))) {
if (inherits(model, c("lme", "lmerMod", "merMod", "glmmTMB", "gam"))) {
res_ <- sort(stats::residuals(model), na.last = NA)
} else if (inherits(model, "glm")) {
res_ <- sort(stats::rstandard(model, type = "pearson"), na.last = NA)
Expand Down Expand Up @@ -213,6 +213,8 @@
{
if (inherits(model, "merMod")) {
stats::residuals(model, scaled = TRUE)
} else if (inherits(model, "gam")) {
stats::residuals(model, type = "scaled.pearson")
} else if (inherits(model, c("glmmTMB", "MixMod"))) {
sigma <- if (faminfo$is_mixed) {
sqrt(insight::get_variance_residual(model))
Expand Down

0 comments on commit 916ebd1

Please sign in to comment.