Skip to content

Commit ea71b9d

Browse files
Align arguments of *_pit_ecdf() functions for now.
1 parent bd79469 commit ea71b9d

File tree

8 files changed

+167
-162
lines changed

8 files changed

+167
-162
lines changed

R/ppc-loo.R

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -374,42 +374,40 @@ ppc_loo_pit_qq <- function(y,
374374

375375
#' @rdname PPC-loo
376376
#' @export
377-
#' @param eval_points For `ppc_loo_pit_ecdf()`, an optional integer defining
378-
#' the number of equally spaced evaluation points for the ECDF. Reducing
379-
#' `eval_poins` when using `interpolate_adj = FALSE` makes computing the
380-
#' confidence bands faster. If `pit` is supplied, defaults to `length(pit)`,
381-
#' otherwise `min(nrow(yrep) + 1,
382-
#' @param prob For `ppc_loo_pit_ecdf()`, the desired simultaneous coverage
383-
#' level of the bands around the ECDF. A value in (0,1).
377+
#' @param K For `ppc_loo_pit_ecdf()` an optional integer defining the number
378+
#' of equally spaced evaluation points for the PIT-ECDF. Reducing K when
379+
#' using `interpolate_adj = FALSE` makes computing the confidence bands
380+
#' faster. If `pit` is supplied, defaults to `length(pit)`, otherwise
381+
#' `yrep` determines the maximum accuracy of the estimated PIT values and
382+
#' `K` is set to `min(nrow(yrep) + 1, 1000)`.
384383
#' @param plot_diff For `ppc_loo_pit_ecdf()`, a boolean defining whether to
385-
#' plot the difference between the observed PIT-ECDF and the theoretical
386-
#' expectation for uniform PIT values rather than plotting the regular ECDF.
387-
#' The default is `FALSE`, but for large samples we recommend setting
388-
#' `plot_diff = TRUE` to better use the plot area.
389-
#' @param interval_method For `ppc_loo_pit_ecdf()`, a string that can be either
390-
#' "interpolate" or "optimize". If "simulate" (the default), the simultaneous
391-
#' confidence bands are interpolated based on precomputed values rather than
392-
#' solved for the specific combination of `eval_points` and `dim(yrep)`.
393-
#' The default is to use interpolation if `eval_points` is greater than 200.
394-
#'
384+
#' plot the difference between the observed PIT-ECDF and the theoretical
385+
#' expectation for uniform PIT values rather than plotting the regular ECDF.
386+
#' The default is `FALSE`, but for large samples we recommend setting
387+
#' `plot_diff = TRUE` to better use the plot area.
388+
#' @param interpolate_adj For `ppc_loo_pit_ecdf()`, a boolean defining if the
389+
#' simultaneous confidence bands should be interpolated based on precomputed
390+
#' values rather than computed exactly. Computing the bands may be
391+
#' computationally intensive and the approximation gives a fast method for
392+
#' assessing the ECDF trajectory. The default is to use interpolation if `K`
393+
#' is greater than 200.
395394
ppc_loo_pit_ecdf <- function(y,
396395
yrep,
397396
lw = NULL,
398397
...,
399398
psis_object = NULL,
400399
pit = NULL,
401-
eval_points = NULL,
400+
K = NULL,
402401
prob = .99,
403402
plot_diff = FALSE,
404-
interval_method = c("interpolate", "optimize")) {
403+
interpolate_adj = NULL) {
405404
check_ignored_arguments(...)
406405

407-
interval_method <- match.arg(interval_method)
408406
if (!is.null(pit)) {
409407
inform("'pit' specified so ignoring 'y','yrep','lw' if specified.")
410408
pit <- validate_pit(pit)
411-
if (is.null(eval_points)) {
412-
eval_points <- length(pit)
409+
if (is.null(K)) {
410+
K <- length(pit)
413411
}
414412
} else {
415413
suggested_package("rstantools")
@@ -418,39 +416,39 @@ ppc_loo_pit_ecdf <- function(y,
418416
lw <- .get_lw(lw, psis_object)
419417
stopifnot(identical(dim(yrep), dim(lw)))
420418
pit <- pmin(1, rstantools::loo_pit(object = yrep, y = y, lw = lw))
421-
if (is.null(eval_points)) {
422-
eval_points <- min(nrow(yrep) + 1, 1000)
419+
if (is.null(K)) {
420+
K <- min(nrow(yrep) + 1, 1000)
423421
}
424422
}
425423

426424
n_obs <- length(pit)
427425
gamma <- adjust_gamma(
428426
N = n_obs,
429-
K = eval_points,
427+
K = K,
430428
prob = prob,
431-
interpolate_adj = interval_method == "interpolate"
429+
interpolate_adj = interpolate_adj
432430
)
433-
lims <- ecdf_intervals(gamma = gamma, N = n_obs, K = eval_points)
431+
lims <- ecdf_intervals(gamma = gamma, N = n_obs, K = K)
434432
ggplot() +
435433
aes(
436-
x = seq(0, 1, length.out = eval_points),
437-
y = ecdf(pit)(seq(0, 1, length.out = eval_points)) -
438-
(plot_diff == TRUE) * seq(0, 1, length.out = eval_points),
434+
x = seq(0, 1, length.out = K),
435+
y = ecdf(pit)(seq(0, 1, length.out = K)) -
436+
(plot_diff == TRUE) * seq(0, 1, length.out = K),
439437
color = "y"
440438
) +
441439
geom_step(show.legend = FALSE) +
442440
geom_step(
443441
aes(
444442
y = lims$upper[-1] / n_obs -
445-
(plot_diff == TRUE) * seq(0, 1, length.out = eval_points),
443+
(plot_diff == TRUE) * seq(0, 1, length.out = K),
446444
color = "yrep"
447445
),
448446
linetype = 2, show.legend = FALSE
449447
) +
450448
geom_step(
451449
aes(
452450
y = lims$lower[-1] / n_obs -
453-
(plot_diff == TRUE) * seq(0, 1, length.out = eval_points),
451+
(plot_diff == TRUE) * seq(0, 1, length.out = K),
454452
color = "yrep"
455453
),
456454
linetype = 2, show.legend = FALSE
@@ -489,7 +487,6 @@ ppc_loo_pit <-
489487

490488
#' @rdname PPC-loo
491489
#' @export
492-
#' @template args-prob-prob_outer
493490
#' @param intervals For `ppc_loo_intervals()` and `ppc_loo_ribbon()`, optionally
494491
#' a matrix of pre-computed LOO predictive intervals that can be specified
495492
#' instead of `yrep` (ignored if `intervals` is specified). If not specified
@@ -502,6 +499,10 @@ ppc_loo_pit <-
502499
#' the plotted intervals. The default (`"index"`) is to plot them in the
503500
#' order of the observations. The alternative (`"median"`) arranges them
504501
#' by median value from smallest (left) to largest (right).
502+
#' @param prob,prob_outer Values between `0` and `1` indicating the desired
503+
#' probability mass to include in the inner and outer intervals. The defaults
504+
#' are `prob=0.5` and `prob_outer=0.9` for `ppc_loo_intervals()` and
505+
#' `prob = 0.99` for `ppc_loo_pit_ecdf()`.
505506
#' @param subset For `ppc_loo_intervals()` and `ppc_loo_ribbon()`, an optional
506507
#' integer vector indicating which observations in `y` (and `yrep`) to
507508
#' include. Dropping observations from `y` and `yrep` manually before passing

man/PPC-loo.Rd

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

0 commit comments

Comments
 (0)