Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
858fc76
Add alt text to the figures of the vignettes
avehtari Nov 15, 2026
afb333b
Describe the shape of the two GMPD plots in their alt text
avehtari Nov 15, 2026
a9da1f1
Name the axes in the alt texts and keep their result claims to the vi…
avehtari Nov 15, 2026
0f46593
Merge remote-tracking branch 'origin/master' into vignette-main-loo
avehtari Nov 16, 2026
7a6da7a
Use cv_varsel() with LOO CV and validated search in the main vignette
avehtari Nov 16, 2026
a8bb2c4
Correct the vignette text after review and point the vsel methods to …
avehtari Nov 16, 2026
eafc005
Merge remote-tracking branch 'origin/master' into vignette-latent-loo
avehtari Nov 16, 2026
9ae6a6f
Use forward search and LOO CV with validated search in the latent-pro…
avehtari Nov 16, 2026
3fe0272
Describe the Poisson example of the latent vignette with both search …
avehtari Nov 16, 2026
5575dae
Correct the latent vignette text after review
avehtari Nov 16, 2026
9a46d7b
Shorten the Troubleshooting sentence on the latent Poisson example
avehtari Nov 16, 2026
a507618
Edit projpred vignette
avehtari Nov 16, 2026
bbb2c04
Merge branch 'vignette-latent-loo' into vignette-main-loo
avehtari Nov 16, 2026
901d851
Use the formula y ~ . for the reference model of the main vignette
avehtari Nov 16, 2026
53293ec
Explain the submodels above the reference model, and use y ~ . in the…
avehtari Nov 16, 2026
6fb251b
Use the workers of future.mirai in the parallel examples of the laten…
avehtari Nov 16, 2026
fb7c1ce
Use the workers of future.mirai in the parallel examples of the main …
avehtari Nov 16, 2026
289b5a2
Describe the ranking proportions without exact percentages
avehtari Nov 17, 2026
3b303dd
Describe the plots of the latent vignette in the alt texts without ex…
avehtari Nov 17, 2026
d55ab8c
Remove the commented-out projection parallelization from the main vig…
avehtari Nov 17, 2026
8a9d09d
Do not present L1 search as a reason for the latent projection
avehtari Nov 17, 2026
abd1f5c
Remove the early message about an NA dispersion of a latent reference…
avehtari Nov 17, 2026
6dce828
Remove the vignette notes on the NA dispersion message
avehtari Nov 17, 2026
19ee476
Skip the latent_ilink message for families whose linkinv gives the mean
avehtari Nov 17, 2026
b56c658
Remove the vignette notes on the latent_ilink message where it no lon…
avehtari Nov 17, 2026
2172423
Add a NEWS item for the fewer messages of latent reference models
avehtari Nov 17, 2026
c6b3f9c
Add more mean-parameterized families to the latent_ilink check, and t…
avehtari Nov 17, 2026
a17cd82
Test the NA dispersion message also with the brms Poisson fit of the …
avehtari Nov 17, 2026
ef0bcf6
Use a Poisson fit without observation weights in the NA dispersion test
avehtari Nov 17, 2026
46e9d5f
Leave out the sigma column of as.matrix() for a latent projection wit…
avehtari Nov 17, 2026
b20ac29
Check the reference model dispersion for the sigma column, and test a…
avehtari Nov 17, 2026
4ef6c63
Use one simulated dataset and cv_varsel() in the Poisson and negative…
avehtari Nov 17, 2026
be984bd
Remove the pointer to the L1 issue of the old Poisson example
avehtari Nov 17, 2026
ea8f4be
Plot the results of the traditional projection in the Poisson example
avehtari Nov 17, 2026
e149c5f
Move the plot theme setting of the main vignette
avehtari Nov 17, 2026
f43fa6f
Update the troubleshooting text on the multilevel projections for lme…
avehtari Nov 17, 2026
23844a0
Warn about multilevel binomial and Poisson models only with lme4 < 2.1-1
avehtari Nov 17, 2026
f16fd7c
Shorten the Troubleshooting section of the main vignette
avehtari Nov 17, 2026
c8c6cc9
Restore the warnings of init_refmodel() for multilevel binomial and P…
avehtari Nov 17, 2026
b55d493
Merge remote-tracking branch 'origin/master' into vignette-main-loo
avehtari Nov 17, 2026
49755b6
Limit the augmented-data troubleshooting text to the cumulative and c…
avehtari Nov 17, 2026
141f243
Add the PR number to the NEWS item
avehtari Nov 18, 2026
9c8537b
Explain the multilevel issue of the binomial and augmented-data proje…
avehtari Nov 18, 2026
7ec6566
Shorten the parallelization paragraph of the main vignette
avehtari Nov 18, 2026
2265326
Merge branch 'master' into vignette-main-loo
avehtari Nov 18, 2026
39be270
Merge remote-tracking branch 'origin/master' into vignette-main-loo
avehtari Nov 19, 2026
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
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ If you read this from a place other than <https://mc-stan.org/projpred/news/inde
* The parallel LOO and K-fold CV of `cv_varsel()` send the reference models without their fits to the workers, so the workers do not load **brms** or **rstanarm** and need less memory. (GitHub: #629)
* The parallel workers now get the objects of the global environment that functions of a custom reference model use (found from the code, with the **globals** package). Global option `projpred.export_to_workers` can name more objects; `FALSE` turns this off. (GitHub: #629)
* Improved error message for a binomial model with more than one trial per observation. Latent projection now stops for the brms families `beta_binomial()`, `zero_inflated_binomial()` and `zero_inflated_beta_binomial()`. (GitHub: #530, #624)
* With `latent = TRUE`, no message about an `NA` dispersion, and no `latent_ilink` message for families whose inverse link gives the mean (e.g., negative binomial, Weibull). Without a dispersion, `as.matrix()` of a projection has no `sigma` column. (GitHub: #656)

## Bug fixes and maintenance

Expand Down
2 changes: 1 addition & 1 deletion R/cv_varsel.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' is explained in section "Note" below) and by running the evaluation part on
#' the corresponding test set of each CV fold. A special method is
#' [cv_varsel.vsel()] because it re-uses the search results from an earlier
#' [cv_varsel()] (or [varsel()]) run, as illustrated in the main vignette.
#' [cv_varsel()] (or [varsel()]) run (see section "Speed" of the main vignette).
#'
#' @inheritParams varsel
#' @param cv_method The CV method, either `"LOO"` or `"kfold"`. In the `"LOO"`
Expand Down
11 changes: 10 additions & 1 deletion R/extend_family.R
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ extend_family <- function(family,
return(ilpreds)
}
} else {
if (family$family_oscale != "poisson") {
if (!family$family_oscale %in% fams_linkinv_mean()) {
message("Defining `latent_ilink` as a function which calls ",
"`family$linkinv`, but there is no guarantee that this ",
"will work for all families. If relying on ",
Expand Down Expand Up @@ -934,3 +934,12 @@ has_dispersion <- function(family) {
has_family_extras <- function(family) {
return(isTRUE(family$is_extended))
}

# Names of the original response families (rstanarm, brms and stats) whose
# `linkinv` gives the mean of the response, so that the latent projection's
# internal default for `latent_ilink` is correct for them without a message:
fams_linkinv_mean <- function() {
return(c("poisson", "neg_binomial_2", "negbinomial", "negbinomial2",
"geometric", "Gamma", "gamma", "inverse.gaussian", "Beta",
"weibull", "exponential", "frechet", "skew_normal", "exgaussian"))
}
11 changes: 10 additions & 1 deletion R/methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -2560,6 +2560,10 @@ get_subparams.mmblogit <- function(x, ...) {
#' reference model parameters. For a submodel with smooth and group-level
#' terms (GAMM), the projected draws cannot be extracted yet (error).
#'
#' For the latent projection, column `sigma` contains the projected latent
#' dispersion. If `<refmodel>$dis` consists of only `NA`s (see argument `dis`
#' of [init_refmodel()]), there is no column `sigma`.
#'
#' @return An \eqn{S_{\mathrm{prj}} \times Q}{S_prj x Q} matrix of projected
#' draws, with \eqn{S_{\mathrm{prj}}}{S_prj} denoting the number of projected
#' draws and \eqn{Q} the number of parameters. If `allow_nonconst_wdraws_prj`
Expand Down Expand Up @@ -2630,7 +2634,12 @@ as.matrix.projection <- function(x, nm_scheme = NULL,
}
stopifnot(nm_scheme %in% c("rstanarm", "brms"))
res <- do.call(rbind, lapply(x$outdmin, get_subparams, nm_scheme = nm_scheme))
if (x$refmodel$family$family == "gaussian") res <- cbind(res, sigma = x$dis)
# If `<refmodel>$dis` is all `NA` (latent projection), there is no `sigma`
# column:
if (x$refmodel$family$family == "gaussian" &&
!(x$refmodel$family$for_latent && all(is.na(x$refmodel$dis)))) {
res <- cbind(res, sigma = x$dis)
}
if (!x[["const_wdraws_prj"]]) {
attr(res, "wdraws_prj") <- x[["wdraws_prj"]]
}
Expand Down
3 changes: 0 additions & 3 deletions R/projpred-package.R
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,6 @@
#' meaning of these global options, see their occurrences in the codebase. With
#' the exception of `projpred.warn_allrandom_dis`, these global options are
#' currently used in the unit tests to deactivate these messages and warnings.
#' Global option `projpred.warn_instable_projections` is also used (invisibly)
#' in the latent vignette to suppress the corresponding warnings while
#' illustrating the underlying issue (instable projections).
#' * `projpred.additional_checks`: A single logical value indicating whether to
#' run some additional checks that are not necessary to be run when users call
#' the corresponding \pkg{projpred} functions. Currently, these checks are
Expand Down
9 changes: 0 additions & 9 deletions R/refmodel.R
Original file line number Diff line number Diff line change
Expand Up @@ -1789,15 +1789,6 @@ init_refmodel <- function(object, data, formula, family, ref_predfun = NULL,
} else {
dis <- rep(NA, ndraws)
}
if (all(is.na(dis))) {
message(
"Since `<refmodel>$dis` will consist of only `NA`s, downstream ",
"analyses based on this reference model object won't be able to use ",
"log predictive density (LPD) values on latent scale. Furthermore, ",
"proj_predict() won't be able to draw from the latent Gaussian ",
"distribution."
)
}
} else if (!has_dispersion(family)) {
dis <- rep(NA, ndraws)
} else {
Expand Down
2 changes: 1 addition & 1 deletion R/varsel.R
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#' (number of predictor terms). The evaluation part determines the predictive
#' performance of the submodels along the predictor ranking. A special method is
#' [varsel.vsel()] which re-uses the search results from an earlier
#' [varsel()] (or [cv_varsel()]) run, as illustrated in the main vignette.
#' [varsel()] (or [cv_varsel()]) run (see section "Speed" of the main vignette).
#'
#' @param object An object of class `refmodel` (returned by [get_refmodel()] or
#' [init_refmodel()]) or an object that can be passed to argument `object` of
Expand Down
4 changes: 4 additions & 0 deletions man/as.matrix.projection.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions man/as_draws_matrix.projection.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cv_varsel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions man/internal-global-options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/varsel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 27 additions & 0 deletions tests/testthat/test_extend_family.R
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,30 @@ test_that(paste(
fixed = TRUE, info = tstsetup)
}
})

test_that(paste(
"extend_family() with `latent = TRUE` gives the `latent_ilink` message only",
"for families whose `linkinv` does not give the mean"
), {
fam_tst <- function(fam_nm, link, linkinv) {
structure(list(family = fam_nm, link = link, linkinv = linkinv),
class = "family")
}
fams_mean <- list(
neg_binomial_2 = fam_tst("neg_binomial_2", "log", exp),
negbinomial = fam_tst("negbinomial", "log", exp),
Gamma = Gamma(link = "log"),
weibull = fam_tst("weibull", "log", exp)
)
for (fam_nm in names(fams_mean)) {
expect_no_message(
extend_family(fams_mean[[fam_nm]], latent = TRUE),
message = "latent_ilink"
)
}
expect_message(
extend_family(fam_tst("lognormal", "identity", identity), latent = TRUE),
"latent_ilink",
info = "lognormal"
)
})
31 changes: 31 additions & 0 deletions tests/testthat/test_latent.R
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,34 @@ test_that(paste(
}
}
})

test_that(paste(
"get_refmodel() with `latent = TRUE` and without `dis` gives no message",
"about the `NA` dispersion, and as.matrix.projection() has no `sigma` column"
), {
skip_if_not_installed("rstanarm")
set.seed(4521)
dat <- data.frame(y = rpois(30, 2), x1 = rnorm(30), x2 = rnorm(30))
fit <- suppressWarnings(rstanarm::stan_glm(
y ~ x1 + x2, family = poisson(), data = dat, chains = 1, iter = 200,
refresh = 0, seed = 7412
))
expect_no_message(
refm <- get_refmodel(fit, latent = TRUE),
message = "will consist of only `NA`s"
)
expect_true(all(is.na(refm$dis)))
# Without a latent dispersion, as.matrix() has no `sigma` column:
prj <- project(refm, predictor_terms = "x1", ndraws = 20, verbose = 0)
expect_false("sigma" %in% colnames(as.matrix(prj)))
expect_false(
"sigma" %in% posterior::variables(posterior::as_draws_matrix(prj))
)
# With a latent dispersion, it has one:
refm_dis <- suppressMessages(
get_refmodel(fit, latent = TRUE, dis = rep(1, length(refm$dis)))
)
prj_dis <- project(refm_dis, predictor_terms = "x1", ndraws = 20,
verbose = 0)
expect_true("sigma" %in% colnames(as.matrix(prj_dis)))
})
Loading
Loading