Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
185 commits
Select commit Hold shift + click to select a range
1c5d871
feat: add predictive performance measures as pred_measure* family
Jul 2, 2026
bad8062
feat: update print method for new pred_measure* family
Jul 2, 2026
6d404e1
feat: deprecate loo functions in favor of new pred_measure family
Jul 2, 2026
f5854c2
tests: update tests for deprecated functions
Jul 2, 2026
c42c803
docs: add migration guide to loo package
Jul 2, 2026
7750200
docs: update documentation for new pred_measure functions and depreca…
Jul 2, 2026
1926429
chore: update DESCRIPTION, NAMESPACE, NEWS and _pkgdown
Jul 2, 2026
02ecbbb
tests: add test data
Jul 3, 2026
a24fee1
tests: add unit tests for pred_measure function family
Jul 3, 2026
3a670cf
fix: update elpd and fix typo in .compute_base_measure
Jul 3, 2026
439867e
fix:update measure names in .validate_control
Jul 3, 2026
883dda0
docs: add vignettes for new predictive preformance measure
Jul 3, 2026
755984d
docs: add/update cross-references to vignettes
Jul 3, 2026
b260a32
chore: add data fitting to CI and avoid committing large data files
Jul 3, 2026
082d7be
chore: add cli to Imports and lme4 to Suggests
Jul 3, 2026
e394c30
fix: minor fixes
Jul 3, 2026
e9f1a3a
chore: add developer-notes
Jul 3, 2026
cf0c79b
add print method of test_pred_measure
Jul 3, 2026
5cb9f10
chore: update developer-notes and add old-vs.-new API comparison
Jul 3, 2026
562b141
fix: small fixes to pass test checks
Jul 3, 2026
023add0
Merge branch 'loo-v3.0.0' into pred_measure
florence-bockting Jul 3, 2026
8346344
tests: update snapshots
Jul 4, 2026
e99aeac
tests: add snapshots for pred_measure_builtin
Jul 6, 2026
884df6e
refactor: add class loo to loo_pred_measure
Jul 6, 2026
b924ac5
docs: update pkg-info
Jul 7, 2026
89d5e9a
refactor: update loo_compare to work with loo_pred_measure
Jul 7, 2026
7ce2d50
refactor: update pred_measure API for integration with loo_compare()
Jul 7, 2026
7394ba3
tests: new tests for loo_compare with loo_pred_measure
Jul 7, 2026
494d24f
docs: update documentation and glossary
Jul 7, 2026
9611656
docs: update documentation
Jul 7, 2026
a3019e3
chore: update developer-notes
Jul 7, 2026
f64cf6c
refactor: rename revert_sign arg to higher_is_better
Jul 8, 2026
441f0ea
docs: update renaming arg to higher_is_better
Jul 8, 2026
b0015c7
tests: update renaming to higher_is_better
Jul 8, 2026
076e2c7
chore: update renaming higher_is_better argument
Jul 8, 2026
3e1bf93
Merge branch 'pred_measure' into integrate-loo_compare
florence-bockting Jul 8, 2026
06d6281
refactor: clean-up refactoring and adjust for renamed arg
Jul 8, 2026
b46ff58
fix: update missing argument and corresponding docs
Jul 8, 2026
f1fcaf0
chore: update NEWS.md
Jul 8, 2026
674746e
Merge branch 'loo-v3.0.0' into pred_measure
florence-bockting Jul 16, 2026
e17e46d
Merge branch 'pred_measure' into integrate-loo_compare
florence-bockting Jul 16, 2026
abc74b5
refactor: update computation of SE for loo_compare with pred_measure_loo
Aug 12, 2026
faa27c5
refactor: create model_compare and workout design
Aug 25, 2026
3e078aa
update model_compare() functionality
Aug 27, 2026
a1e66e5
Merge branch 'loo-v3.0.0' into pred_measure
florence-bockting Aug 28, 2026
0d1e072
Merge branch 'loo-v3.0.0' into pred_measure
florence-bockting Aug 28, 2026
8897e1f
Merge branch 'pred_measure' into integrate-loo_compare
florence-bockting Aug 28, 2026
1eb66de
refactor: split model_compare.R and drop duplicated loo_compare inter…
Aug 28, 2026
166dab6
fix: restore the simplify argument to print.compare.loo
Aug 28, 2026
c0c1fc0
review: update the model_compare function
Aug 28, 2026
c594818
update: deprecate loo_compare but maintain backwards comptability
Aug 28, 2026
aa30e54
review: code refactoring review
Aug 28, 2026
b1f0b32
docs: update function documentation to roxygen2 8.0.0
Aug 29, 2026
63c16a8
docs: update glossary to match loo_compare and model_compare
Aug 29, 2026
d874044
fix: throw deprecation warning for loo_compare only once per session.
Aug 29, 2026
9e930e3
fix: remove old 'estimates_only' label
Aug 29, 2026
4fe4b0d
refactor: avoid duplicate computation
Aug 29, 2026
88890b6
docs: add loo_compare and model_compare to seealso statement
Aug 29, 2026
51b3c9c
refactor: add warning for disagreeing measure name in attribute and list
Aug 29, 2026
81ae8eb
review: minor style corrections and doc adjustment
Aug 29, 2026
fed3433
review: removed dead code
Aug 29, 2026
585b77c
vignette: update tutorial on model comparison
Aug 29, 2026
3f63357
chore: update warning messages
Aug 29, 2026
5307f23
review: update function docs and inline small helper
Aug 29, 2026
b0f94cb
fix: computation of weights for (s)rps
Aug 30, 2026
7184cae
fix: refactor computation of ic and mlpd
Aug 30, 2026
91f251a
fix: computation of weights for (s)rps
Aug 30, 2026
757021e
tests: add tests for mlpd, ic, and updated weigts for (s)rps
Aug 30, 2026
f08afcc
fix: check equality of log_weights from loo and psis_object
Aug 30, 2026
806600b
fix: pass name of measures correctly
Aug 30, 2026
0c85ba8
review: add guards for potential silent failures
Aug 30, 2026
d0b52fa
fix: kfold diagnostics, dims on update, reuse stored log_weights
Aug 30, 2026
1b1d050
fix: bacc pointwise path, dims after 3-D conversion, duplicate filter
Aug 30, 2026
8c46b00
fix: error on group_ids until grouped summaries exist
Aug 30, 2026
e74df04
refactor: extract .lppd_from_inputs() from elpd, mlpd and ic
Aug 30, 2026
b3a7db7
refactor: extract .acc_pointwise() from acc and bacc
Aug 30, 2026
12133b8
refactor: extract .point_error_from_inputs() from mae and mse
Aug 30, 2026
bd67f6a
refactor: read the source from the attribute, reuse .measure_estimate…
Aug 30, 2026
ef914d8
refactor: print the Pareto k table with pareto_k_table()
Aug 30, 2026
f79c4f8
refactor: remove dead code and correct the .compute_measure() roxygen
Aug 30, 2026
4882727
fix: label rps as a loss and srps as a utility in .measure_spec
Aug 31, 2026
ffa1786
docs: correct the ic, mse/rmse/r2 and CRPS reference entries
Aug 31, 2026
fa95ff7
docs: correct the acc and bacc definitions in overview-measures
Aug 31, 2026
29072e6
docs: document the PWM estimator that the crps and scrps code uses
Aug 31, 2026
294f87a
docs: state that rps and srps take draws, not class probabilities
Aug 31, 2026
8a9a8e2
docs: correct the measure keywords and the weighted path in overview-…
Aug 31, 2026
6db2531
docs: fit the workflow vignette's models in the article
Aug 31, 2026
f0715be
docs: correct the pred-measure-workflow object and measure tables
Aug 31, 2026
7ffedf6
docs: state the Pareto-k threshold as sample-size dependent
Aug 31, 2026
4dd743c
docs: drop the devtools and dplyr dependencies from the articles
Aug 31, 2026
0a3ecbb
tests: shrink the pred_measure fixtures to fit the CRAN limit
Aug 31, 2026
919b29b
tests: fix the normalized-log-weights test reading a missing field
Aug 31, 2026
b5952b7
tests: drop two fixture fields that nothing reads
Aug 31, 2026
795cd4e
Merge branch 'pred_measure' into integrate-loo_compare
Aug 31, 2026
69346f3
tests: shrink the model-comparison fixture
Aug 31, 2026
e52ab8e
print: accept simplify on the pred_measure path
Aug 31, 2026
d55d9bf
model_compare: accept named models in dots
Aug 31, 2026
0f830e3
internal: share the k-fold K-mismatch warning
Aug 31, 2026
769b37a
internal: drop model_compare_checks.psis_loo_ss_list()
Aug 31, 2026
b80c946
internal: drop model_compare_matrix.psis_loo_ss_list()
Aug 31, 2026
ca8da41
docs: correct the Sivula et al. year in the glossary
Aug 31, 2026
47af38e
pred_measure: keep a renamed measure's own orientation
Aug 31, 2026
99d71a2
docs: remove draft scaffolding from the comparison article
Aug 31, 2026
0e07f63
docs: let the comparison article fit its own models
Aug 31, 2026
4317ce7
docs: point the custom-measure chunks at the new fits
Aug 31, 2026
0c1de0c
docs: rename the comparison article to model-comparison
Aug 31, 2026
c66e1e2
docs: correct the article path in the model_compare links
Aug 31, 2026
5f6bcb9
internal: drop the vignette fits from the data generator
Aug 31, 2026
6dbd05d
docs: give the two remaining articles their real vignette title
Aug 31, 2026
91bfdba
model_compare: return the default object for subsampled loo
Sep 1, 2026
6621d2d
model_compare: let simplify = FALSE follow measures
Sep 1, 2026
0944a95
model_compare: name the fold count and the test size
Sep 1, 2026
0140dc1
vignettes: update model-comparison tutorial with other pred_measure f…
Sep 1, 2026
67f4d12
refactor: allow attribute measure_se_diff for custom measures
Sep 9, 2026
e339f48
docs: update developer-notes with review comments from Jonah
Sep 9, 2026
4c5a1a8
refactor: add user facade custom_measure() and remove custom_se_fn pa…
Sep 16, 2026
791ed25
refactor: remove elpd as 'base measure'
Sep 17, 2026
dc49cd1
fix: update old function description and ensure correct Roxygen version
Sep 17, 2026
cb93257
docs: update vignette about measure overview
Sep 17, 2026
22d1422
docs: initial version of pred_measure workflow vignette
Sep 18, 2026
c1d75f8
Merge branch 'loo-v3.0.0' into pred_measure
florence-bockting Sep 18, 2026
0e7d193
Merge branch 'pred_measure' of https://github.com/stan-dev/loo into p…
Sep 18, 2026
aa7f286
Merge remote-tracking branch 'origin/pred_measure' into integrate-loo…
Sep 19, 2026
6971e13
docs: update developer-notes wrt custom_measure
Sep 21, 2026
8815998
fix: model_compare throws warning when kfold_pred_measure use differe…
Sep 21, 2026
eec2140
fix: pass moment_match loss into pred_measure
Sep 21, 2026
dcf5fde
fix: use separate digits for measures in print method
Sep 21, 2026
ba29be1
fix: update snapshots
Sep 21, 2026
c5af96b
refactor: remove the 'rank_by' argument for model_compare
Sep 25, 2026
9ffff9c
fix: check whether pothoc measures have been used and warn for measur…
Sep 25, 2026
dd2ac81
fix: remove diagnostic flags for measures other than elpd
Sep 28, 2026
e372858
docs: rebuild loo_pred_measure.Rd for the post-hoc correction note
Sep 28, 2026
36795c2
feat: mark and explain flipped measure signs in print
Sep 28, 2026
999cfa7
docs: move model_compare design notes to design-discussions
Sep 28, 2026
de54993
docs: shorten NEWS entries for model_compare
Sep 28, 2026
cd1085d
docs: update model_compare vignette
Sep 28, 2026
a18b16e
refactor: rename argument measure to measures
Sep 28, 2026
954bdb1
Merge remote-tracking branch 'origin/pred_measure' into integrate-loo…
Sep 28, 2026
6341145
docs: clean up vignette 'overview measures'
Sep 28, 2026
390eeb1
Merge branch 'pred_measure' into integrate-loo_compare
florence-bockting Sep 29, 2026
2a77502
Merge branch 'loo-v3.0.0' into pred_measure
florence-bockting Sep 29, 2026
fbe6e88
Merge branch 'pred_measure' into integrate-loo_compare
florence-bockting Sep 29, 2026
71b23c2
fix: remove children folder unrelated to PR
Sep 29, 2026
ee7b99b
tests: make the test fixtures smaller for CRAN
Sep 29, 2026
fd427d9
model_compare: rank by elpd, else by the first shared measure in alph…
Sep 29, 2026
f7a7b4d
model_compare: drop complexity columns by exact name, keep custom p_ …
Sep 29, 2026
a509447
fix: define missing fold in example of model_compare
Sep 29, 2026
102a76b
docs: remove measure-ordering code comment from example
Sep 29, 2026
d03261f
chore: update deprecation warning to not print internal function and …
Sep 29, 2026
18fd34b
print.compare.loo: warn when is given for 'loo' comparisons
Sep 30, 2026
7573b3d
docs: measures applies to all pred_measure comparisons
Sep 30, 2026
07d68c8
docs: change title of model-comparison.Rmd and change link in functio…
Sep 30, 2026
d958069
docs: update the description of model-compare.Rmd in 'See also' secti…
Sep 30, 2026
2af1cd1
docs: update EVAL parameter in vignette
Sep 30, 2026
1ac844b
docs: update vignette section to 'Basic usage'
Sep 30, 2026
fa986da
fix: point custom measure errors to custom_measre()
Sep 30, 2026
706bc0f
docs: point custom measure declarations to custom_measure()
Sep 30, 2026
88afda5
fix: name the ranking reference when more than four measures are comp…
Sep 30, 2026
0bd95d6
Merge branch 'pred_measure' into integrate-loo_compare
florence-bockting Sep 30, 2026
c9f72c6
fix: remove test_that from inner test
Oct 5, 2026
2041008
fix: remove attributes names pointing to older custom_measure design
Oct 5, 2026
f26eb02
Merge pull request #380 from stan-dev/integrate-loo_compare
florence-bockting Oct 5, 2026
1637ede
fix: keep element names when pred_measure() updates a result
Oct 7, 2026
c3c940e
fix: check log_weights size when mupred is a vector
Oct 7, 2026
3328f5c
fix: read measure_bacc() pointwise input on the stored scale
Oct 7, 2026
a70f40d
fix: check that y in measure_acc() and measure_bacc() matches the mup…
Oct 7, 2026
3764847
fix: accept a 3-D ylp in *_pred_measure()
Oct 7, 2026
438f54f
fix: check that predperf is a pred_measure object in pred_measure()
Oct 7, 2026
1ada0a3
fix: normalize measures once in do_pred_measure()
Oct 7, 2026
b427aa8
docs: name only valid measures in the pred_measure input docs
Oct 7, 2026
7002815
docs: state the full return contract of a custom measure
Oct 7, 2026
959c057
docs: refer to the measures argument by its name
Oct 7, 2026
ffae11e
docs: describe the matrix shape of a measure result
Oct 7, 2026
988d798
docs: show the return value on each measure help page
Oct 7, 2026
db2279c
docs: remove the unused measure_metric_params block
Oct 7, 2026
8c581a5
docs: name existing helpers in the .compute_measure() docs
Oct 7, 2026
749d421
docs: attach the .merge_matrix() block to its function
Oct 7, 2026
5481b19
fix: suggest a logical save_psis in the missing psis_object error
Oct 7, 2026
fea24ad
docs: move developer sections out of the migration guide
Oct 7, 2026
e28acd6
docs: rewrite the branch NEWS entries in the release format
Oct 7, 2026
e1dca92
update overview-measures vignette
Oct 7, 2026
3fc1580
update overview-measures vignette
Oct 7, 2026
d627dfd
docs: standardize referencing of vignettes (use always same names)
Oct 8, 2026
e05a938
docs: clean-up vignette
Oct 8, 2026
de81c46
docs: create consistent references to vignettes
Oct 8, 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
10 changes: 9 additions & 1 deletion .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vignettes/loo2-non-factorized_cache/*
.github/*
.vscode/*
^\.github$
^vignettes/online-only$
^vignettes/articles-online-only$

^CRAN-SUBMISSION$
^release-prep\.R$
Expand All @@ -27,3 +27,11 @@ vignettes/loo2-non-factorized_cache/*
^touchstone$
^.git-blame-ignore-revs
^notes-release.md
^notes$
^\.agents$
^agent$
^\.claude$
^\.refactor-review$
^internal-notes$
^scratch-files$
^skills-lock\.json$
3 changes: 2 additions & 1 deletion .github/workflows/pkgdown.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
local::.
any::bayesplot
any::BH
any::brms
paul-buerkner/brms
any::ggplot2
any::rmarkdown
any::Rcpp
Expand All @@ -52,6 +52,7 @@ jobs:
any::StanHeaders
any::knitr
any::withr
any::lme4
stan-dev/pkgdown-config

- name: Build site
Expand Down
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,17 @@ vignettes/loo2-non-factorizable_cache/*
vignettes/*.html
vignettes/*.pdf
inst/doc
*.html

revdep/*
tests/testthat/Rplots.pdf

cran-comments.md
CRAN-RELEASE
release-prep.R

# personal maintainer scratch (not shared)
internal-notes/
notes/loo_se.pdf
notes/loo-compare-se-diff.md
CRAN-SUBMISSION
2 changes: 2 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Depends:
R (>= 3.5)
Imports:
checkmate,
cli (>= 3.4.0),
matrixStats (>= 0.52),
parallel,
posterior (>= 1.7.0),
Expand All @@ -46,6 +47,7 @@ Suggests:
ggplot2,
graphics,
knitr,
lme4,
rmarkdown,
rstan,
rstanarm (>= 2.19.0),
Expand Down
28 changes: 27 additions & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ S3method(crps,numeric)
S3method(dim,importance_sampling)
S3method(dim,kfold)
S3method(dim,loo)
S3method(dim,pred_measure)
S3method(dim,psis_loo)
S3method(dim,waic)
S3method(elpd,array)
Expand All @@ -47,18 +48,22 @@ S3method(loo_moment_match,default)
S3method(loo_predictive_metric,matrix)
S3method(loo_scrps,matrix)
S3method(loo_subsample,"function")
S3method(model_compare,default)
S3method(model_compare,psis_loo_ss_list)
S3method(nobs,psis_loo_ss)
S3method(plot,loo)
S3method(plot,psis)
S3method(plot,psis_loo)
S3method(pointwise,loo)
S3method(print,compare.loo)
S3method(print,compare.loo_ss)
S3method(print,importance_sampling)
S3method(print,importance_sampling_loo)
S3method(print,kfold)
S3method(print,loo)
S3method(print,loo_pred_measure)
S3method(print,measure)
S3method(print,pareto_k_table)
S3method(print,pred_measure)
S3method(print,pseudobma_bb_weights)
S3method(print,pseudobma_weights)
S3method(print,psis)
Expand Down Expand Up @@ -102,12 +107,14 @@ export(.thin_draws)
export(E_loo)
export(compare)
export(crps)
export(custom_measure)
export(elpd)
export(example_loglik_array)
export(example_loglik_matrix)
export(extract_log_lik)
export(find_model_names)
export(gpdfit)
export(insample_pred_measure)
export(is.kfold)
export(is.loo)
export(is.psis)
Expand All @@ -116,6 +123,7 @@ export(is.sis)
export(is.tis)
export(is.waic)
export(kfold)
export(kfold_pred_measure)
export(kfold_split_grouped)
export(kfold_split_random)
export(kfold_split_stratified)
Expand All @@ -134,27 +142,45 @@ export(loo_model_weights)
export(loo_model_weights.default)
export(loo_moment_match)
export(loo_moment_match.default)
export(loo_pred_measure)
export(loo_predictive_metric)
export(loo_scrps)
export(loo_subsample)
export(loo_subsample.function)
export(mcse_loo)
export(measure_acc)
export(measure_bacc)
export(measure_brier)
export(measure_elpd)
export(measure_ic)
export(measure_mae)
export(measure_mlpd)
export(measure_mse)
export(measure_r2)
export(measure_rmse)
export(measure_rps)
export(measure_srps)
export(model_compare)
export(nlist)
export(obs_idx)
export(pareto_k_ids)
export(pareto_k_influence_values)
export(pareto_k_table)
export(pareto_k_values)
export(pointwise)
export(pred_measure)
export(print_dims)
export(pseudobma_weights)
export(psis)
export(psis_n_eff_values)
export(psislw)
export(ptw_log_pred_density)
export(relative_eff)
export(scrps)
export(sis)
export(stacking_weights)
export(supported_measures_list)
export(test_pred_measure)
export(tis)
export(waic)
export(waic.array)
Expand Down
20 changes: 20 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
# loo (development version)

* Add a predictive performance API by @florence-bockting in #363:
- new functions `insample_pred_measure()`, `loo_pred_measure()`,
`kfold_pred_measure()`, `test_pred_measure()`, and `pred_measure()`
- new built-in measures `measure_*()`, listed in `supported_measures_list`
* Deprecate `elpd()`, `crps()`, `scrps()`, `loo_crps()`, `loo_scrps()`, and
`loo_predictive_metric()`. Use `measure_*()` and `*_pred_measure()`. See
`vignette("migration-guide")`. By @florence-bockting in #363
* Add `model_compare()` by @florence-bockting in #380:
- compares models on each measure of `*_pred_measure()` results
- compares each measure against its own best model
- shows loss measures on the utility scale
- ranks models by `elpd`, else by the first shared measure (alphabetical)
- new `print()` argument `measures`
* Deprecate `loo_compare()`. Use `model_compare()`. Methods in other packages
(e.g. **brms**) still work. By @florence-bockting in #380
* Add `custom_measure()` to set the name, loss flag, and SE of the difference
for a custom measure by @florence-bockting in #380
* `loo_pred_measure()` warns when `loo_moment_match()` or `reloo()` changed the
`loo` object and the measure is not `elpd`, `mlpd`, or `ic`, by
@florence-bockting in #380
* Improve numerical stability in `loo()`, `psis()`, model weighting, subsampling,
and moment matching in #395
* Fix `loo_compare()` when used with subsampling: compute model comparison by
Expand Down
7 changes: 4 additions & 3 deletions R/compare.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#' Model comparison (deprecated, old version)
#'
#' **This function is deprecated**. Please use the new [loo_compare()] function
#' instead.
#' **This function is deprecated**. Please use the new [model_compare()] function
#' instead. See `vignette("migration-guide", package = "loo")` for details.
#' `compare()` and `R/compare.R` are scheduled for removal in a future release.
#'
#' @export
#' @param ... At least two objects returned by [loo()] (or [waic()]).
Expand Down Expand Up @@ -59,7 +60,7 @@
#' }
#'
compare <- function(..., x = list()) {
.Deprecated("loo_compare")
.Deprecated("model_compare")
dots <- list(...)
if (length(dots)) {
if (length(x)) {
Expand Down
24 changes: 21 additions & 3 deletions R/crps.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
#' Continuously ranked probability score
#' Continuously ranked probability score (deprecated)
#'
#' As of loo 3.0.0, `crps()`, `scrps()`, `loo_crps()`, and `loo_scrps()` are
#' **deprecated**. Please use [measure_rps()] and [measure_srps()] instead,
#' or [loo_pred_measure()] for leave-one-out predictive performance.
#' See `vignette("migration-guide", package = "loo")` for a full mapping table.
#'
#' @details
#' The new functions use a single matrix of posterior predictive draws
#' (`ypred`) and a PWM estimator. The deprecated functions require two
#' independent draw matrices (`x` and `x2`) and use a permutation-based
#' estimator. See [measure_rps()] for migration details.
#'
#' The `crps()` and `scrps()` functions and their `loo_*()` counterparts can be
#' used to compute the continuously ranked probability score (CRPS) and scaled
Expand Down Expand Up @@ -34,16 +45,19 @@
#' The former reports estimator and standard error and latter the pointwise
#' values. Following Bolin & Wallin (2023), a larger value is better.
#'
#' @seealso [measure_rps()], [measure_srps()], [loo_pred_measure()]
#'
#' @examples
#' \dontrun{
#' # An example using rstanarm
#' # Deprecated:
#' library(rstanarm)
#' data("kidiq")
#' fit <- stan_glm(kid_score ~ mom_hs + mom_iq, data = kidiq)
#' ypred1 <- posterior_predict(fit)
#' ypred2 <- posterior_predict(fit)
#' crps(ypred1, ypred2, y = fit$y)
#' loo_crps(ypred1, ypred2, y = fit$y, log_lik = log_lik(fit))
#' # ->
#' measure_rps(y = fit$y, ypred = ypred1)
#' }
#'
#' @references
Expand Down Expand Up @@ -80,6 +94,7 @@ loo_scrps <- function(x, ...) {
#' @rdname crps
#' @export
crps.matrix <- function(x, x2, y, ..., permutations = 1) {
.Deprecated("measure_rps")
validate_crps_input(x, x2, y)
repeats <- replicate(permutations, EXX_compute(x, x2), simplify = F)
EXX <- Reduce(`+`, repeats) / permutations
Expand Down Expand Up @@ -114,6 +129,7 @@ loo_crps.matrix <-
permutations = 1,
r_eff = 1,
cores = getOption("mc.cores", 1)) {
.Deprecated("loo_pred_measure")
validate_crps_input(x, x2, y, log_lik)
repeats <- replicate(permutations,
EXX_loo_compute(x, x2, log_lik, r_eff = r_eff, ...),
Expand All @@ -128,6 +144,7 @@ loo_crps.matrix <-
#' @rdname crps
#' @export
scrps.matrix <- function(x, x2, y, ..., permutations = 1) {
.Deprecated("measure_srps")
validate_crps_input(x, x2, y)
repeats <- replicate(permutations, EXX_compute(x, x2), simplify = F)
EXX <- Reduce(`+`, repeats) / permutations
Expand Down Expand Up @@ -156,6 +173,7 @@ loo_scrps.matrix <-
permutations = 1,
r_eff = 1,
cores = getOption("mc.cores", 1)) {
.Deprecated("loo_pred_measure")
validate_crps_input(x, x2, y, log_lik)
repeats <- replicate(permutations,
EXX_loo_compute(x, x2, log_lik, r_eff = r_eff, ...),
Expand Down
15 changes: 7 additions & 8 deletions R/diagnostics.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,15 @@
#' the MCMC draws from the posterior distribution to obtain more
#' reliable importance sampling estimates. This results in a smaller
#' shape parameter \eqn{k}. See [loo_moment_match()] and the
#' vignette *Avoiding model refits in leave-one-out cross-validation
#' with moment matching* for an example of this.
#' vignette *Avoiding model refits with moment matching* for an
#' example of this.
#'
#' * Sampling from a leave-one-out mixture distribution (see the
#' vignette *Mixture IS leave-one-out cross-validation for
#' high-dimensional Bayesian models*), directly from \eqn{p(\theta^s
#' | y_{-i})} for the problematic observations \eqn{i}, or using
#' \eqn{K}-fold cross-validation (see the vignette *Holdout
#' validation and K-fold cross-validation of Stan programs with the
#' loo package*) will generally be more stable.
#' vignette *Mixture IS leave-one-out cross-validation*),
#' directly from \eqn{p(\theta^s | y_{-i})} for the problematic
#' observations \eqn{i}, or using \eqn{K}-fold cross-validation
#' (see the vignette *Holdout validation and K-fold cross-validation*)
#' will generally be more stable.
#'
#' * Using a model that is more robust to anomalous observations will
#' generally make approximate LOO-CV more stable.
Expand Down
41 changes: 29 additions & 12 deletions R/elpd.R
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
#' Generic (expected) log-predictive density
#' Generic (expected) log-predictive density (deprecated)
#'
#' As of loo 3.0.0, `elpd()` is **deprecated**. Please use [measure_elpd()]
#' instead. For full predictive performance workflows, see
#' [insample_pred_measure()] and [loo_pred_measure()].
#' See `vignette("migration-guide", package = "loo")` for a full mapping table.
#'
#' @details
#' The return type differs: `elpd()` returns class `"elpd_generic"` with
#' `elpd` and `ic` in `pointwise`; `measure_elpd()` returns class `"measure"`.
#'
#' The `elpd()` methods for arrays and matrices can compute the expected log
#' pointwise predictive density for a new dataset or the log pointwise
#' predictive density of the observed data (an overestimate of the elpd).
#' The `elpd()` function is an S3 generic and methods are provided for
#' 3-D pointwise log-likelihood arrays and matrices.
#'
#' @export
#' @param x A log-likelihood array or matrix. The **Methods (by class)**
#' section, below, has detailed descriptions of how to specify the inputs for
#' each method.
#' @param ... Currently ignored.
#'
#' @details The `elpd()` function is an S3 generic and methods are provided for
#' 3-D pointwise log-likelihood arrays and matrices.
#'
#' @seealso The vignette *Holdout validation and K-fold cross-validation of Stan
#' programs with the loo package* for demonstrations of using the `elpd()`
#' methods.
#' @seealso [measure_elpd()], [insample_pred_measure()], [loo_pred_measure()],
#' and the vignette *Holdout validation and K-fold cross-validation*.
#'
#' @examples
#' # Calculate the lpd of the observed data
#' \dontrun{
#' # Deprecated:
#' LLarr <- example_loglik_array()
#' elpd(LLarr)
#' # ->
#' measure_elpd(LLarr)
#' }
#'
elpd <- function(x, ...) {
UseMethod("elpd")
Expand All @@ -31,22 +42,28 @@ elpd <- function(x, ...) {
#' @template array
#'
elpd.array <- function(x, ...) {
.Deprecated("measure_elpd")
ll <- llarray_to_matrix(x)
elpd.matrix(ll)
.elpd_matrix_impl(ll)
}

#' @export
#' @templateVar fn elpd
#' @template matrix
#'
elpd.matrix <- function(x, ...) {
pointwise <- pointwise_elpd_calcs(x)
elpd_object(pointwise, dim(x))
.Deprecated("measure_elpd")
.elpd_matrix_impl(x)
}



# internal ----------------------------------------------------------------
# used to avoid duplicated deprecation warning messages
.elpd_matrix_impl <- function(x) {
pointwise <- pointwise_elpd_calcs(x)
elpd_object(pointwise, dim(x))
}

pointwise_elpd_calcs <- function(ll){
elpd <- colLogSumExps(ll) - log(nrow(ll))
ic <- -2 * elpd
Expand Down
Loading
Loading