diff --git a/NEWS.md b/NEWS.md index f0026850..291db72b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,8 @@ # loo (development version) +* Update user messages in `print()` by @ishaan-arora-1, @florence-bockting in +#328. + # loo 2.10.1 * Revert behavior of internal `psis_smooth_tail()` function that led to several 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 6a3f2139..1f4030b8 100644 --- a/R/print.R +++ b/R/print.R @@ -141,40 +141,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" ) } @@ -191,11 +191,13 @@ 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", + "Subsampling loo uses 1) faster, more biased computation with ", length(x$loo_subsampling$elpd_loo_approx), - "total observations.\n" + " log-lik.\n", + "terms, and 2) slower, more accurate computation with ", + nobs(x), + " subsampled terms.\n", + sep = "" ) } 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/loo_subsampling_cases.md b/tests/testthat/_snaps/loo_subsampling_cases.md index 2dcdf0fb..677e4fa1 100644 --- a/tests/testthat/_snaps/loo_subsampling_cases.md +++ b/tests/testthat/_snaps/loo_subsampling_cases.md @@ -4,8 +4,8 @@ print(looss_1) Output - Computed from 4000 by 100 subsampled log-likelihood - values from 3020 total observations. + Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. + terms, and 2) slower, more accurate computation with 100 subsampled terms. Estimate SE subsampling SE elpd_loo -1968.5 15.6 0.3 @@ -24,8 +24,8 @@ print(looss_1b) Output - Computed from 4000 by 200 subsampled log-likelihood - values from 3020 total observations. + Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. + terms, and 2) slower, more accurate computation with 200 subsampled terms. Estimate SE subsampling SE elpd_loo -1968.3 15.6 0.2 @@ -44,7 +44,7 @@ print(aploo_1) Output - 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 @@ -64,8 +64,8 @@ print(looapss_1) Output - Computed from 2000 by 100 subsampled log-likelihood - values from 3020 total observations. + Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. + terms, and 2) slower, more accurate computation with 100 subsampled terms. Estimate SE subsampling SE elpd_loo -1968.2 15.6 0.4 @@ -85,8 +85,8 @@ print(looss_2) Output - Computed from 4000 by 100 subsampled log-likelihood - values from 3020 total observations. + Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. + terms, and 2) slower, more accurate computation with 100 subsampled terms. Estimate SE subsampling SE elpd_loo -1952.0 16.2 0.2 diff --git a/tests/testthat/_snaps/print_plot.md b/tests/testthat/_snaps/print_plot.md index e4df71da..5a7a6c34 100644 --- a/tests/testthat/_snaps/print_plot.md +++ b/tests/testthat/_snaps/print_plot.md @@ -4,7 +4,7 @@ print(waic1) Output - Computed from 1000 by 32 log-likelihood matrix. + Computed from 1000 posterior draws and 32 log-likelihood terms. Estimate SE elpd_waic -83.5 4.3 @@ -18,7 +18,7 @@ Code print(psis1) Output - Computed from 1000 by 32 log-weights matrix. + Computed from 1000 posterior draws and 32 log-weight terms. MCSE and ESS estimates assume independent draws (r_eff=1). All Pareto k estimates are good (k < 0.67). @@ -30,7 +30,7 @@ print(loo1) Output - Computed from 1000 by 32 log-likelihood matrix. + Computed from 1000 posterior draws and 32 log-likelihood terms. Estimate SE elpd_loo -83.6 4.3 @@ -49,7 +49,7 @@ print(loo1_r_eff) Output - Computed from 1000 by 32 log-likelihood matrix. + Computed from 1000 posterior draws and 32 log-likelihood terms. Estimate SE elpd_loo -83.6 4.3 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 b0e2560d..c39c5e81 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). @@ -17,7 +17,7 @@ print(loo_tis) Output - Computed from 1000 by 32 log-likelihood matrix using tis_loo . + Computed from 1000 posterior draws and 32 log-likelihood terms using tis_loo . Estimate SE elpd_loo -83.6 4.3 @@ -31,7 +31,7 @@ print(loo_sis) Output - Computed from 1000 by 32 log-likelihood matrix using sis_loo . + Computed from 1000 posterior draws and 32 log-likelihood terms using sis_loo . Estimate SE elpd_loo -83.6 4.3 diff --git a/tests/testthat/test_loo_subsampling_cases.R b/tests/testthat/test_loo_subsampling_cases.R index 6bd244c0..532d5830 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 terms" )) 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), "Subsampling loo uses 1) faster,") 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), "Subsampling loo uses 1) faster,") 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 terms" )) # Test conversion of objects @@ -369,11 +369,8 @@ test_that("Test the vignette", { loo_approximation_draws = 100 ) ) - expect_output( - print(looss_2), - "Computed from 4000 by 100 subsampled log-likelihood" - ) - expect_output(print(looss_2), "values from 3020 total observations.") + expect_output(print(looss_2), "Subsampling loo uses 1) faster,") + expect_output(print(looss_2), "Subsampling loo uses 1) faster,") expect_output( print(looss_2), "MCSE and ESS estimates assume independent draws" diff --git a/vignettes/loo2-large-data.Rmd b/vignettes/loo2-large-data.Rmd index 0dadaf7e..fbaa5827 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. +Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. +terms, and 2) slower, more accurate computation with 100 subsampled terms. Estimate SE subsampling SE elpd_loo -1968.5 15.6 0.3 @@ -235,13 +235,13 @@ loo_ss_1b <- r_eff = r_eff, draws = parameter_draws_1, data = stan_df_1 - ) + ) print(loo_ss_1b) ``` ``` -Computed from 4000 by 200 subsampled log-likelihood -values from 3020 total observations. +Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. +terms, and 2) slower, more accurate computation with 200 subsampled terms. 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. +Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. +terms, and 2) slower, more accurate computation with 100 subsampled terms. 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. +Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. +terms, and 2) slower, more accurate computation with 100 subsampled terms. 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. +Subsampling loo uses 1) faster, more biased computation with 3020 log-lik. +terms, and 2) slower, more accurate computation with 200 subsampled terms. 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