Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix y axis for ppc_loo_pit_qq() with 'compare = "normal"' #243

Merged
merged 5 commits into from
Oct 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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, #243, @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)
Expand Down
20 changes: 11 additions & 9 deletions R/ppc-loo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)) +
Expand Down
16 changes: 9 additions & 7 deletions man/PPC-loo.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tests/testthat/test-ppc-loo.R
Original file line number Diff line number Diff line change
Expand Up @@ -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", {
Expand Down