loo_model_weights() rejects PSIS-LOO objects with equal observations but different posterior sample sizes
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 68/100
Direzione di ricerca
Inizia da loo_model_weights() e validate_psis_loo_list(), quindi confronta i relativi controlli delle dimensioni con loo_compare(). Riproduci l’esempio usando loo_full e loo_short e aggiungi la copertura per conteggi di osservazioni uguali con diverse dimensioni del campione a posteriori. Il lavoro è completato quando loo_model_weights() accetta questi oggetti mantenendo la validazione delle dimensioni delle osservazioni incompatibili.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Both objects contain pointwise LOO results for the same 32 observations in the same order. The only difference is the number of posterior draws: 1,000 versus 500 after merging chains.
loo_compare() accepts these objects, but loo_model_weights() rejects them because validate_psis_loo_list() requires both dimensions of the psis_loo objects to match.
My understanding is that stacking and pseudo-BMA operate on the pointwise elpd_loo vectors, so the posterior sample sizes need not be identical. Different sample sizes affect Monte Carlo precision but should not make the objects incompatible.
example
library(loo)
log_lik_full <- example_loglik_array()
# Keep the same chains and 32 observations, but use half the iterations.
log_lik_short <- log_lik_full[seq_len(dim(log_lik_full)[1] / 2),,, drop = FALSE]
loo_full <- loo(
log_lik_full,
r_eff = relative_eff(exp(log_lik_full))
)
loo_short <- loo(
log_lik_short,
r_eff = relative_eff(exp(log_lik_short))
)
dim(loo_full)
#> [1] 1000 32
dim(loo_short)
#> [1] 500 32
# Comparison works despite the different posterior sample sizes.
loo_compare(loo_full, loo_short)
# Model weights do not.
loo_model_weights(list(
full = loo_full,
short = loo_short
))
sessionInfo()
output
> library(loo)
This is loo version 2.10.1
- Online documentation and vignettes at mc-stan.org/loo
- As of v2.0.0 loo defaults to 1 core but we recommend using as many as possible. Use the 'cores' argument or set options(mc.cores = NUM_CORES) for an entire session.
- Windows 10 users: loo may be very slow if 'mc.cores' is set in your .Rprofile file (see https://github.com/stan-dev/loo/issues/94).
Warning message:
package ‘loo’ was built under R version 4.6.1
>
> log_lik_full <- example_loglik_array()
>
> # Keep the same chains and 32 observations, but use half the iterations.
> log_lik_short <- log_lik_full[seq_len(dim(log_lik_full)[1] / 2),,, drop = FALSE]
>
> loo_full <- loo(
+ log_lik_full,
+ r_eff = relative_eff(exp(log_lik_full))
+ )
>
> loo_short <- loo(
+ log_lik_short,
+ r_eff = relative_eff(exp(log_lik_short))
+ )
>
> dim(loo_full)
[1] 1000 32
> #> [1] 1000 32
>
> dim(loo_short)
[1] 500 32
> #> [1] 500 32
>
> # Comparison works despite the different posterior sample sizes.
> loo_compare(loo_full, loo_short)
model elpd_diff se_diff p_worse diag_diff diag_elpd
model2 0.0 0.0 NA
model1 0.0 0.1 0.70 N < 100
Diagnostic flags present.
See ?`loo-glossary` (sections `diag_diff` and `diag_elpd`)
or https://mc-stan.org/loo/reference/loo-glossary.html.
>
> # Model weights do not.
> loo_model_weights(list(
+ full = loo_full,
+ short = loo_short
+ ))
Error: Each object in the list must have the same dimensions.
> sessionInfo()
R version 4.6.0 (2026-04-24 ucrt)
Platform: x86_64-w64-mingw32/x64
Running under: Windows 11 x64 (build 26200)
Matrix products: default
LAPACK version 3.12.1
locale:
[1] LC_COLLATE=English_United States.utf8 LC_CTYPE=English_United States.utf8
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C
[5] LC_TIME=English_United States.utf8
time zone: Europe/Amsterdam
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] loo_2.10.1
loaded via a namespace (and not attached):
[1] vctrs_0.7.3 cli_3.6.6 knitr_1.51 rlang_1.2.0
[5] xfun_0.57 otel_0.2.0 generics_0.1.4 tensorA_0.36.2.1
[9] glue_1.8.1 backports_1.5.1 htmltools_0.5.9 distributional_0.7.0
[13] rmarkdown_2.31 evaluate_1.0.5 tibble_3.3.1 abind_1.4-8
[17] fastmap_1.2.0 yaml_2.3.12 lifecycle_1.0.5 compiler_4.6.0
[21] posterior_1.7.0 pkgconfig_2.0.3 rstudioapi_0.18.0 digest_0.6.39
[25] pillar_1.11.1 parallel_4.6.0 magrittr_2.0.5 checkmate_2.3.4
[29] tools_4.6.0 matrixStats_1.5.0
- Lingua principale
- R
- Stelle
- 157
- Fork
- 38
- Merge medio
- 4g 16h
- PR unite (30g)
- 2
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di stan-dev/loo
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Extend loo_plot_difference Aperta
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
-
Clean up issues Aperta
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
Tutte le issue di stan-dev/loo
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
briandconnelly/airnow#9 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
OHDSI/CohortConstructor#774 ·
-
pre-review R TeX Track: 5 (DSAIS)
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 60/100
openjournals/joss-reviews#11330 · 7 commenti ·
-
Release autosync 0.1.1 Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100