diff --git a/NEWS.md b/NEWS.md index 6f182376..abb6e481 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # loo (development version) +* Clarify print output to say "posterior draws" and "log-likelihood terms" instead of the ambiguous "X by Y matrix" format (#198) + # loo 2.9.0 * Avoid under and overflows in stacking by @avehtari in #273 diff --git a/R/elpd.R b/R/elpd.R index 20724e71..b6736fb4 100644 --- a/R/elpd.R +++ b/R/elpd.R @@ -67,9 +67,9 @@ elpd_object <- function(pointwise, dims) { } #' @export print_dims.elpd_generic <- function(x, ...) { + dims <- dim(x) cat( - "Computed from", - paste(dim(x), collapse = " by "), - "log-likelihood matrix using the generic elpd function\n" + "Computed from", dims[1], "posterior draws and", + dims[2], "log-likelihood terms using the generic elpd function.\n" ) } diff --git a/R/print.R b/R/print.R index f05834d6..096bb4a5 100644 --- a/R/print.R +++ b/R/print.R @@ -119,40 +119,40 @@ print_dims <- function(x, ...) UseMethod("print_dims") #' @rdname print_dims #' @export print_dims.importance_sampling <- function(x, ...) { + dims <- dim(x) cat( - "Computed from", - paste(dim(x), collapse = " by "), - "log-weights matrix.\n" + "Computed from", dims[1], "posterior draws and", + dims[2], "log-weight terms.\n" ) } #' @rdname print_dims #' @export print_dims.psis_loo <- function(x, ...) { + dims <- dim(x) cat( - "Computed from", - paste(dim(x), collapse = " by "), - "log-likelihood matrix.\n" + "Computed from", dims[1], "posterior draws and", + dims[2], "log-likelihood terms.\n" ) } #' @rdname print_dims #' @export print_dims.importance_sampling_loo <- function(x, ...) { + dims <- dim(x) cat( - "Computed from", - paste(dim(x), collapse = " by "), - "log-likelihood matrix using", class(x)[1], ".\n" + "Computed from", dims[1], "posterior draws and", + dims[2], "log-likelihood terms using", class(x)[1], ".\n" ) } #' @rdname print_dims #' @export print_dims.waic <- function(x, ...) { + dims <- dim(x) cat( - "Computed from", - paste(dim(x), collapse = " by "), - "log-likelihood matrix.\n" + "Computed from", dims[1], "posterior draws and", + dims[2], "log-likelihood terms.\n" ) } @@ -169,9 +169,8 @@ print_dims.kfold <- function(x, ...) { #' @export print_dims.psis_loo_ss <- function(x, ...) { cat( - "Computed from", - paste(c(dim(x)[1], nobs(x)) , collapse = " by "), - "subsampled log-likelihood\nvalues from", + "Computed from", dim(x)[1], "posterior draws and", + nobs(x), "subsampled log-likelihood\nterms from", length(x$loo_subsampling$elpd_loo_approx), "total observations.\n" ) diff --git a/tests/testthat/_snaps/loo_moment_matching.md b/tests/testthat/_snaps/loo_moment_matching.md index e34c5d48..a227a3aa 100644 --- a/tests/testthat/_snaps/loo_moment_matching.md +++ b/tests/testthat/_snaps/loo_moment_matching.md @@ -13,7 +13,7 @@ Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. Output - Computed from 4000 by 30 log-likelihood matrix. + Computed from 4000 posterior draws and 30 log-likelihood terms. Estimate SE elpd_loo -74.0 18.8 diff --git a/tests/testthat/_snaps/psis.md b/tests/testthat/_snaps/psis.md index 9f2deaf3..d902046d 100644 --- a/tests/testthat/_snaps/psis.md +++ b/tests/testthat/_snaps/psis.md @@ -4787,7 +4787,7 @@ Message Replacing NAs in `r_eff` with 1s Output - Computed from 1000 by 32 log-weights matrix. + Computed from 1000 posterior draws and 32 log-weight terms. MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]). All Pareto k estimates are good (k < 0.67). @@ -4803,7 +4803,7 @@ Warning: Some Pareto k diagnostic values are too high. See help('pareto-k-diagnostic') for details. Output - Computed from 10 by 32 log-weights matrix. + Computed from 10 posterior draws and 32 log-weight terms. MCSE and ESS estimates assume independent draws (r_eff=1). Pareto k diagnostic values: Count Pct. Min. ESS diff --git a/tests/testthat/_snaps/tisis.md b/tests/testthat/_snaps/tisis.md index 57cf7e30..1f20897f 100644 --- a/tests/testthat/_snaps/tisis.md +++ b/tests/testthat/_snaps/tisis.md @@ -5,7 +5,7 @@ Message Replacing NAs in `r_eff` with 1s Output - Computed from 1000 by 32 log-weights matrix. + Computed from 1000 posterior draws and 32 log-weight terms. MCSE and ESS estimates assume MCMC draws (r_eff in [0.6, 1.0]). All Pareto k estimates are good (k < 0.67). diff --git a/tests/testthat/test_loo_subsampling_cases.R b/tests/testthat/test_loo_subsampling_cases.R index 1f53192b..61fb5691 100644 --- a/tests/testthat/test_loo_subsampling_cases.R +++ b/tests/testthat/test_loo_subsampling_cases.R @@ -171,17 +171,17 @@ test_that("Test loo_subsampling and loo_approx with radon data", { )) expect_failure(expect_output( print(full_loo), - "subsampled log-likelihood\nvalues" + "subsampled log-likelihood\nterms" )) expect_failure(expect_output( print(loo_ss), "Posterior approximation correction used\\." )) - expect_output(print(loo_ss), "subsampled log-likelihood\nvalues") + expect_output(print(loo_ss), "subsampled log-likelihood\nterms") expect_output(print(loo_ap_ss), "Posterior approximation correction used\\.") - expect_output(print(loo_ap_ss), "subsampled log-likelihood\nvalues") + expect_output(print(loo_ap_ss), "subsampled log-likelihood\nterms") expect_output( print(loo_ap_ss_full), @@ -189,7 +189,7 @@ test_that("Test loo_subsampling and loo_approx with radon data", { ) expect_failure(expect_output( print(loo_ap_ss_full), - "subsampled log-likelihood\nvalues" + "subsampled log-likelihood\nterms" )) # Test conversion of objects @@ -344,9 +344,9 @@ test_that("Test the vignette", { ) expect_output( print(looss_1), - "Computed from 4000 by 100 subsampled log-likelihood" + "Computed from 4000 posterior draws and 100 subsampled log-likelihood" ) - expect_output(print(looss_1), "values from 3020 total observations.") + expect_output(print(looss_1), "terms from 3020 total observations.") expect_output( print(looss_1), "MCSE and ESS estimates assume independent draws" @@ -366,9 +366,9 @@ test_that("Test the vignette", { ) expect_output( print(looss_1b), - "Computed from 4000 by 200 subsampled log-likelihood" + "Computed from 4000 posterior draws and 200 subsampled log-likelihood" ) - expect_output(print(looss_1b), "values from 3020 total observations.") + expect_output(print(looss_1b), "terms from 3020 total observations.") expect_output( print(looss_1b), "MCSE and ESS estimates assume independent draws" @@ -391,9 +391,9 @@ test_that("Test the vignette", { ) expect_output( print(looss_2), - "Computed from 4000 by 100 subsampled log-likelihood" + "Computed from 4000 posterior draws and 100 subsampled log-likelihood" ) - expect_output(print(looss_2), "values from 3020 total observations.") + expect_output(print(looss_2), "terms from 3020 total observations.") expect_output( print(looss_2), "MCSE and ESS estimates assume independent draws" @@ -415,7 +415,7 @@ test_that("Test the vignette", { ) expect_output( print(aploo_1), - "Computed from 2000 by 3020 log-likelihood matrix" + "Computed from 2000 posterior draws and 3020 log-likelihood terms" ) expect_output( print(aploo_1), @@ -441,13 +441,13 @@ test_that("Test the vignette", { ) expect_output( print(looapss_1), - "Computed from 2000 by 100 subsampled log-likelihood" + "Computed from 2000 posterior draws and 100 subsampled log-likelihood" ) expect_output( print(looapss_1), "MCSE and ESS estimates assume independent draws" ) - expect_output(print(looapss_1), "values from 3020 total observations.") + expect_output(print(looapss_1), "terms from 3020 total observations.") expect_output(print(looapss_1), "elpd_loo -1968.2 15.6 0.4") expect_output(print(looapss_1), "p_loo 2.9 0.1 0.5") expect_output(print(looapss_1), "All Pareto k estimates are good") @@ -474,13 +474,13 @@ test_that("Test the vignette", { ) expect_output( print(looss_2), - "Computed from 4000 by 100 subsampled log-likelihood" + "Computed from 4000 posterior draws and 100 subsampled log-likelihood" ) expect_output( print(looss_2), "MCSE and ESS estimates assume independent draws" ) - expect_output(print(looss_2), "values from 3020 total observations.") + expect_output(print(looss_2), "terms from 3020 total observations.") expect_output(print(looss_2), "elpd_loo -1952.0 16.2 0.2") expect_output(print(looss_2), "p_loo 2.6 0.1 0.3") diff --git a/tests/testthat/test_print_plot.R b/tests/testthat/test_print_plot.R index f69ed6f0..ea0ec03b 100644 --- a/tests/testthat/test_print_plot.R +++ b/tests/testthat/test_print_plot.R @@ -41,16 +41,16 @@ test_that("plot methods throw appropriate errors/warnings", { lldim_msg <- paste0( "Computed from ", prod(dim(LLarr)[1:2]), - " by ", + " posterior draws and ", dim(LLarr)[3], - " log-likelihood matrix" + " log-likelihood terms" ) lwdim_msg <- paste0( "Computed from ", prod(dim(LLarr)[1:2]), - " by ", + " posterior draws and ", dim(LLarr)[3], - " log-weights matrix" + " log-weight terms" ) test_that("print.waic output is ok", { diff --git a/vignettes/loo2-large-data.Rmd b/vignettes/loo2-large-data.Rmd index 0dadaf7e..ff801817 100644 --- a/vignettes/loo2-large-data.Rmd +++ b/vignettes/loo2-large-data.Rmd @@ -188,8 +188,8 @@ print(loo_ss_1) ``` ``` -Computed from 4000 by 100 subsampled log-likelihood -values from 3020 total observations. +Computed from 4000 posterior draws and 100 subsampled log-likelihood +terms from 3020 total observations. Estimate SE subsampling SE elpd_loo -1968.5 15.6 0.3 @@ -240,8 +240,8 @@ print(loo_ss_1b) ``` ``` -Computed from 4000 by 200 subsampled log-likelihood -values from 3020 total observations. +Computed from 4000 posterior draws and 200 subsampled log-likelihood +terms from 3020 total observations. Estimate SE subsampling SE elpd_loo -1968.3 15.6 0.2 @@ -285,8 +285,8 @@ print(loo_ss_1c) ``` -Computed from 4000 by 100 subsampled log-likelihood -values from 3020 total observations. +Computed from 4000 posterior draws and 100 subsampled log-likelihood +terms from 3020 total observations. Estimate SE subsampling SE elpd_loo -1968.9 15.4 0.5 @@ -339,7 +339,7 @@ print(loo_ap_1) The function creates a class, `psis_loo_ap` that inherits from `psis_loo, loo`. ``` -Computed from 2000 by 3020 log-likelihood matrix +Computed from 2000 posterior draws and 3020 log-likelihood terms Estimate SE elpd_loo -1968.4 15.6 @@ -375,8 +375,8 @@ print(loo_ap_ss_1) ``` ``` -Computed from 2000 by 100 subsampled log-likelihood -values from 3020 total observations. +Computed from 2000 posterior draws and 100 subsampled log-likelihood +terms from 3020 total observations. Estimate SE subsampling SE elpd_loo -1968.2 15.6 0.4 @@ -455,8 +455,8 @@ print(loo_ss_2) ``` ``` -Computed from 4000 by 100 subsampled log-likelihood -values from 3020 total observations. +Computed from 4000 posterior draws and 100 subsampled log-likelihood +terms from 3020 total observations. Estimate SE subsampling SE elpd_loo -1952.0 16.2 0.2 diff --git a/vignettes/loo2-with-rstan.Rmd b/vignettes/loo2-with-rstan.Rmd index 23ddf364..9c1fcd05 100644 --- a/vignettes/loo2-with-rstan.Rmd +++ b/vignettes/loo2-with-rstan.Rmd @@ -140,7 +140,7 @@ print(loo_1) ``` ``` -Computed from 4000 by 3020 log-likelihood matrix +Computed from 4000 posterior draws and 3020 log-likelihood terms Estimate SE elpd_loo -1968.5 15.6 @@ -182,7 +182,7 @@ print(loo_2) ``` ``` -Computed from 4000 by 3020 log-likelihood matrix +Computed from 4000 posterior draws and 3020 log-likelihood terms Estimate SE elpd_loo -1952.3 16.2