From 23e76b2b073fbe1dd91a74478d039176a2dbe3fa Mon Sep 17 00:00:00 2001 From: fweber144 Date: Tue, 20 Oct 2020 12:54:26 +0200 Subject: [PATCH 1/5] ppc_loo_pit_qq(): On the y axis, use standard normal quantiles calculated from the PIT values instead of standardized PIT values. --- R/ppc-loo.R | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/R/ppc-loo.R b/R/ppc-loo.R index 43798ea3..40017eb0 100644 --- a/R/ppc-loo.R +++ b/R/ppc-loo.R @@ -42,11 +42,12 @@ #' PITs to the standard uniform distribution. Comparing to the uniform is not #' good for extreme probabilities close to 0 and 1, so it can sometimes be #' useful to set the `compare` argument to `"normal"`, which will -#' produce a Q-Q plot comparing standardized PIT values to the standard normal -#' distribution that can help see the (mis)calibration better for the extreme -#' values. However, in most cases we have found that the overlaid density plot -#' (`ppc_loo_pit_overlay()`) function will provided a clearer picture of -#' calibration problems that the Q-Q plot. +#' produce a Q-Q plot comparing standard normal quantiles calculated from the +#' PIT values to the theoretical standard normal quantiles. This can help see +#' the (mis)calibration better for the extreme values. However, in most cases +#' we have found that the overlaid density plot (`ppc_loo_pit_overlay()`) +#' function will provide a clearer picture of calibration problems than the +#' Q-Q plot. #' } #' \item{`ppc_loo_intervals()`, `ppc_loo_ribbon()`}{ #' Similar to [ppc_intervals()] and [ppc_ribbon()] but the intervals are for @@ -113,8 +114,9 @@ NULL #' @param compare For `ppc_loo_pit_qq()`, a string that can be either #' `"uniform"` or `"normal"`. If `"uniform"` (the default) the Q-Q plot #' compares computed PIT values to the standard uniform distribution. If -#' `compare="normal"`, the Q-Q plot compares standardized PIT values to the -#' standard normal distribution. +#' `compare="normal"`, the Q-Q plot compares standard normal quantiles +#' calculated from the PIT values to the theoretical standard normal +#' quantiles. #' @param trim Passed to [ggplot2::stat_density()]. #' @template args-density-controls ppc_loo_pit_overlay <- function(y, @@ -220,10 +222,10 @@ ppc_loo_pit_qq <- function(y, x_lab <- "Uniform" y_lab <- "LOO-PIT" } else { - pit <- as.vector(scale(pit)) + pit <- as.vector(stats::qnorm(pit)) theoretical <- stats::qnorm x_lab <- "Normal" - y_lab <- "LOO-PIT (standardized)" + y_lab <- "LOO-PIT (standard normal quantiles)" } ggplot(data.frame(p = pit)) + From 9599ba275fbd52c808bee6bbaf1e2ebc9318cd33 Mon Sep 17 00:00:00 2001 From: fweber144 Date: Tue, 20 Oct 2020 12:55:51 +0200 Subject: [PATCH 2/5] Move two unit tests for ppc_loo_pit_qq() to a more appropriate place. --- tests/testthat/test-ppc-loo.R | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/testthat/test-ppc-loo.R b/tests/testthat/test-ppc-loo.R index 827ebd56..bf8979f7 100644 --- a/tests/testthat/test-ppc-loo.R +++ b/tests/testthat/test-ppc-loo.R @@ -28,13 +28,13 @@ test_that("ppc_loo_pit gives deprecation warning but still works", { test_that("ppc_loo_pit_overlay returns ggplot object", { expect_gg(p1 <- ppc_loo_pit_overlay(y, yrep, lw, samples = 25)) - expect_gg(p2 <- ppc_loo_pit_qq(y, yrep, lw, compare = "normal")) - expect_equal(p2$labels$x, "Normal") }) test_that("ppc_loo_pit_qq returns ggplot object", { expect_gg(p1 <- ppc_loo_pit_qq(y, yrep, lw)) expect_equal(p1$labels$x, "Uniform") + expect_gg(p2 <- ppc_loo_pit_qq(y, yrep, lw, compare = "normal")) + expect_equal(p2$labels$x, "Normal") }) test_that("ppc_loo_pit functions work when pit specified instead of y,yrep,lw", { From 89e713ad27588a56b99ee491d15937e3292a882e Mon Sep 17 00:00:00 2001 From: fweber144 Date: Tue, 20 Oct 2020 12:57:47 +0200 Subject: [PATCH 3/5] Re-ran roxygen2 to update the documentation. --- man/PPC-loo.Rd | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/man/PPC-loo.Rd b/man/PPC-loo.Rd index 75f2f131..67f7b681 100644 --- a/man/PPC-loo.Rd +++ b/man/PPC-loo.Rd @@ -119,8 +119,9 @@ parameters. \code{n_dens} defaults to \code{1024}.} \item{compare}{For \code{ppc_loo_pit_qq()}, a string that can be either \code{"uniform"} or \code{"normal"}. If \code{"uniform"} (the default) the Q-Q plot compares computed PIT values to the standard uniform distribution. If -\code{compare="normal"}, the Q-Q plot compares standardized PIT values to the -standard normal distribution.} +\code{compare="normal"}, the Q-Q plot compares standard normal quantiles +calculated from the PIT values to the theoretical standard normal +quantiles.} \item{psis_object}{If using \strong{loo} version \verb{2.0.0} or greater, an object returned by the \code{psis()} function (or by the \code{loo()} function @@ -184,11 +185,12 @@ the miscalibration with a quantile-quantile (Q-Q) plot comparing the LOO PITs to the standard uniform distribution. Comparing to the uniform is not good for extreme probabilities close to 0 and 1, so it can sometimes be useful to set the \code{compare} argument to \code{"normal"}, which will -produce a Q-Q plot comparing standardized PIT values to the standard normal -distribution that can help see the (mis)calibration better for the extreme -values. However, in most cases we have found that the overlaid density plot -(\code{ppc_loo_pit_overlay()}) function will provided a clearer picture of -calibration problems that the Q-Q plot. +produce a Q-Q plot comparing standard normal quantiles calculated from the +PIT values to the theoretical standard normal quantiles. This can help see +the (mis)calibration better for the extreme values. However, in most cases +we have found that the overlaid density plot (\code{ppc_loo_pit_overlay()}) +function will provide a clearer picture of calibration problems than the +Q-Q plot. } \item{\code{ppc_loo_intervals()}, \code{ppc_loo_ribbon()}}{ Similar to \code{\link[=ppc_intervals]{ppc_intervals()}} and \code{\link[=ppc_ribbon]{ppc_ribbon()}} but the intervals are for From 6863e9a1160fb06cf79613f8a66aa208a0329b5e Mon Sep 17 00:00:00 2001 From: fweber144 Date: Tue, 20 Oct 2020 13:06:09 +0200 Subject: [PATCH 4/5] Updated NEWS.md --- NEWS.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/NEWS.md b/NEWS.md index 720d1d33..7bfc0168 100644 --- a/NEWS.md +++ b/NEWS.md @@ -8,6 +8,10 @@ * Items for next release go here --> +* On the y axis, `ppc_loo_pit_qq(..., compare = "normal")` now plots standard + normal quantiles calculated from the PIT values (instead of the standardized + PIT values). (#240, #, @fweber144) + * New plotting function `ppc_km_overlay()` for outcome variables that are right-censored. Empirical CCDF estimates of `yrep` are compared with the Kaplan-Meier estimate of `y`. (#233, #234, @fweber144) From e0fef80cb0ae649d23d7a2bcaf23e8290f9fc9fe Mon Sep 17 00:00:00 2001 From: fweber144 Date: Tue, 20 Oct 2020 13:22:46 +0200 Subject: [PATCH 5/5] NEWS.md: Fill in the correct PR number. --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 7bfc0168..038f7a53 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,7 +10,7 @@ * On the y axis, `ppc_loo_pit_qq(..., compare = "normal")` now plots standard normal quantiles calculated from the PIT values (instead of the standardized - PIT values). (#240, #, @fweber144) + PIT values). (#240, #243, @fweber144) * New plotting function `ppc_km_overlay()` for outcome variables that are right-censored. Empirical CCDF estimates of `yrep` are compared with the