Skip to content

Commit 036f7c5

Browse files
authored
Merge pull request #243 from fweber144/y_loo_pit_qq
Fix y axis for ppc_loo_pit_qq() with 'compare = "normal"'
2 parents 5500d2e + e0fef80 commit 036f7c5

File tree

4 files changed

+26
-18
lines changed

4 files changed

+26
-18
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
* Items for next release go here
99
-->
1010

11+
* On the y axis, `ppc_loo_pit_qq(..., compare = "normal")` now plots standard
12+
normal quantiles calculated from the PIT values (instead of the standardized
13+
PIT values). (#240, #243, @fweber144)
14+
1115
* New plotting function `ppc_km_overlay()` for outcome variables that are
1216
right-censored. Empirical CCDF estimates of `yrep` are compared with the
1317
Kaplan-Meier estimate of `y`. (#233, #234, @fweber144)

R/ppc-loo.R

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,12 @@
4242
#' PITs to the standard uniform distribution. Comparing to the uniform is not
4343
#' good for extreme probabilities close to 0 and 1, so it can sometimes be
4444
#' useful to set the `compare` argument to `"normal"`, which will
45-
#' produce a Q-Q plot comparing standardized PIT values to the standard normal
46-
#' distribution that can help see the (mis)calibration better for the extreme
47-
#' values. However, in most cases we have found that the overlaid density plot
48-
#' (`ppc_loo_pit_overlay()`) function will provided a clearer picture of
49-
#' calibration problems that the Q-Q plot.
45+
#' produce a Q-Q plot comparing standard normal quantiles calculated from the
46+
#' PIT values to the theoretical standard normal quantiles. This can help see
47+
#' the (mis)calibration better for the extreme values. However, in most cases
48+
#' we have found that the overlaid density plot (`ppc_loo_pit_overlay()`)
49+
#' function will provide a clearer picture of calibration problems than the
50+
#' Q-Q plot.
5051
#' }
5152
#' \item{`ppc_loo_intervals()`, `ppc_loo_ribbon()`}{
5253
#' Similar to [ppc_intervals()] and [ppc_ribbon()] but the intervals are for
@@ -113,8 +114,9 @@ NULL
113114
#' @param compare For `ppc_loo_pit_qq()`, a string that can be either
114115
#' `"uniform"` or `"normal"`. If `"uniform"` (the default) the Q-Q plot
115116
#' compares computed PIT values to the standard uniform distribution. If
116-
#' `compare="normal"`, the Q-Q plot compares standardized PIT values to the
117-
#' standard normal distribution.
117+
#' `compare="normal"`, the Q-Q plot compares standard normal quantiles
118+
#' calculated from the PIT values to the theoretical standard normal
119+
#' quantiles.
118120
#' @param trim Passed to [ggplot2::stat_density()].
119121
#' @template args-density-controls
120122
ppc_loo_pit_overlay <- function(y,
@@ -220,10 +222,10 @@ ppc_loo_pit_qq <- function(y,
220222
x_lab <- "Uniform"
221223
y_lab <- "LOO-PIT"
222224
} else {
223-
pit <- as.vector(scale(pit))
225+
pit <- as.vector(stats::qnorm(pit))
224226
theoretical <- stats::qnorm
225227
x_lab <- "Normal"
226-
y_lab <- "LOO-PIT (standardized)"
228+
y_lab <- "LOO-PIT (standard normal quantiles)"
227229
}
228230

229231
ggplot(data.frame(p = pit)) +

man/PPC-loo.Rd

Lines changed: 9 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-ppc-loo.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ test_that("ppc_loo_pit gives deprecation warning but still works", {
2828

2929
test_that("ppc_loo_pit_overlay returns ggplot object", {
3030
expect_gg(p1 <- ppc_loo_pit_overlay(y, yrep, lw, samples = 25))
31-
expect_gg(p2 <- ppc_loo_pit_qq(y, yrep, lw, compare = "normal"))
32-
expect_equal(p2$labels$x, "Normal")
3331
})
3432

3533
test_that("ppc_loo_pit_qq returns ggplot object", {
3634
expect_gg(p1 <- ppc_loo_pit_qq(y, yrep, lw))
3735
expect_equal(p1$labels$x, "Uniform")
36+
expect_gg(p2 <- ppc_loo_pit_qq(y, yrep, lw, compare = "normal"))
37+
expect_equal(p2$labels$x, "Normal")
3838
})
3939

4040
test_that("ppc_loo_pit functions work when pit specified instead of y,yrep,lw", {

0 commit comments

Comments
 (0)