Skip to content
Open
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ If you read this from a place other than <https://mc-stan.org/projpred/news/inde

## Bug fixes and maintenance

* Filter the warning "non-integer response values in a poisson model" of lme4 (>= 2.1-1), which every projection onto a Poisson submodel with group-level terms would give. (GitHub: #585)
* With `options(projpred.PQL = TRUE)`, remove the warnings that every projection gave: the "iteration" messages of `MASS::glmmPQL()`, the warnings about non-integer Poisson responses, and "Unrecognized submodel fit" in the convergence check. (GitHub: #585)
* Tests: Add tests that run on CRAN for the submodel fitters from lme4, MASS, gamm4, ordinal and mclogit. (GitHub: #585)


# projpred 2.11.0

Expand Down
35 changes: 29 additions & 6 deletions R/divergence_minimizers.R
Original file line number Diff line number Diff line change
Expand Up @@ -158,17 +158,29 @@ divmin <- function(
}
mssgs_warns_capts <- lapply(outdmin, "[[", "mssgs_warns_capt")
outdmin <- lapply(outdmin, "[[", "soutdmin")
mssgs_warns_capts <- lapply(mssgs_warns_capts, function(mssgs_warns_capt) {
# Filter out some warnings.
mssgs_warns_capt <- grep("Warning in [^:]*:$",
mssgs_warns_capt, value = TRUE, invert = TRUE)
return(mssgs_warns_capt)
})
mssgs_warns_capts <- lapply(mssgs_warns_capts, filter_mssgs_warns)
warn_prj_drawwise(mssgs_warns_capts, throw_warn = throw_warn_sdivmin)
check_conv(outdmin, lengths(mssgs_warns_capts), do_check = do_check_conv)
return(outdmin)
}

# Removes the lines of the captured messages and warnings of a submodel fit
# (see capt_mssgs_warns()) that do not indicate a problem of the projection.
filter_mssgs_warns <- function(mssgs_warns_capt) {
# Header lines of warnings:
mssgs_warns_capt <- grep("Warning in [^:]*:$",
mssgs_warns_capt, value = TRUE, invert = TRUE)
# lme4 (>= 2.1-1) warns about non-integer Poisson responses, but the
# projection always has such responses:
mssgs_warns_capt <- grep("non-integer response values in a poisson model$",
mssgs_warns_capt, value = TRUE, invert = TRUE)
# For the same reason, stats::dpois() warns about each non-integer Poisson
# response (for example, in the stats::glm() start fit of MASS::glmmPQL()):
mssgs_warns_capt <- grep("^Warning in dpois\\(.*\\) : non-integer x = ",
mssgs_warns_capt, value = TRUE, invert = TRUE)
return(mssgs_warns_capt)
}

# Use projpred's own implementation to fit non-multilevel non-additive
# submodels:
fit_glm_ridge_callback <- function(formula, data,
Expand Down Expand Up @@ -352,6 +364,11 @@ fit_glmer_callback <- function(formula, projpred_formula_no_random,
names(dot_args),
methods::formalArgs(MASS::glmmPQL)
)]
# Without this, the "iteration" messages of MASS::glmmPQL() would be
# captured as messages of the submodel fitter:
if (is.null(dot_args[["verbose"]])) {
dot_args$verbose <- FALSE
}
# Strip parentheses from group-level terms:
random_trms <- labels(terms(projpred_random))
random_fmls <- lapply(random_trms, function(random_trm) {
Expand Down Expand Up @@ -1127,6 +1144,12 @@ check_conv_s <- function(fit_s) {
# convergence. For now, all we can check is the GLMM part from element
# `fit_s$mer`:
return(check_conv_s(fit_s$mer))
} else if (inherits(fit_s, "glmmPQL")) {
# MASS::glmmPQL() stores no convergence information: nlme::lme() throws an
# error if it does not converge (with the default `returnObject = FALSE`),
# but the end of the PQL iterations at `niter` is not recorded. So we need
# to return `TRUE` here:
return(TRUE)
} else if (inherits(fit_s, c("lmerMod", "glmerMod"))) {
# The following was inferred from the source code of lme4::checkConv() and
# lme4::.prt.warn() (see also `?lme4::mkMerMod`).
Expand Down
Loading
Loading