@@ -374,42 +374,40 @@ ppc_loo_pit_qq <- function(y,
374
374
375
375
# ' @rdname PPC-loo
376
376
# ' @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)`.
384
383
# ' @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.
395
394
ppc_loo_pit_ecdf <- function (y ,
396
395
yrep ,
397
396
lw = NULL ,
398
397
... ,
399
398
psis_object = NULL ,
400
399
pit = NULL ,
401
- eval_points = NULL ,
400
+ K = NULL ,
402
401
prob = .99 ,
403
402
plot_diff = FALSE ,
404
- interval_method = c( " interpolate " , " optimize " ) ) {
403
+ interpolate_adj = NULL ) {
405
404
check_ignored_arguments(... )
406
405
407
- interval_method <- match.arg(interval_method )
408
406
if (! is.null(pit )) {
409
407
inform(" 'pit' specified so ignoring 'y','yrep','lw' if specified." )
410
408
pit <- validate_pit(pit )
411
- if (is.null(eval_points )) {
412
- eval_points <- length(pit )
409
+ if (is.null(K )) {
410
+ K <- length(pit )
413
411
}
414
412
} else {
415
413
suggested_package(" rstantools" )
@@ -418,39 +416,39 @@ ppc_loo_pit_ecdf <- function(y,
418
416
lw <- .get_lw(lw , psis_object )
419
417
stopifnot(identical(dim(yrep ), dim(lw )))
420
418
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 )
423
421
}
424
422
}
425
423
426
424
n_obs <- length(pit )
427
425
gamma <- adjust_gamma(
428
426
N = n_obs ,
429
- K = eval_points ,
427
+ K = K ,
430
428
prob = prob ,
431
- interpolate_adj = interval_method == " interpolate "
429
+ interpolate_adj = interpolate_adj
432
430
)
433
- lims <- ecdf_intervals(gamma = gamma , N = n_obs , K = eval_points )
431
+ lims <- ecdf_intervals(gamma = gamma , N = n_obs , K = K )
434
432
ggplot() +
435
433
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 ),
439
437
color = " y"
440
438
) +
441
439
geom_step(show.legend = FALSE ) +
442
440
geom_step(
443
441
aes(
444
442
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 ),
446
444
color = " yrep"
447
445
),
448
446
linetype = 2 , show.legend = FALSE
449
447
) +
450
448
geom_step(
451
449
aes(
452
450
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 ),
454
452
color = " yrep"
455
453
),
456
454
linetype = 2 , show.legend = FALSE
@@ -489,7 +487,6 @@ ppc_loo_pit <-
489
487
490
488
# ' @rdname PPC-loo
491
489
# ' @export
492
- # ' @template args-prob-prob_outer
493
490
# ' @param intervals For `ppc_loo_intervals()` and `ppc_loo_ribbon()`, optionally
494
491
# ' a matrix of pre-computed LOO predictive intervals that can be specified
495
492
# ' instead of `yrep` (ignored if `intervals` is specified). If not specified
@@ -502,6 +499,10 @@ ppc_loo_pit <-
502
499
# ' the plotted intervals. The default (`"index"`) is to plot them in the
503
500
# ' order of the observations. The alternative (`"median"`) arranges them
504
501
# ' 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()`.
505
506
# ' @param subset For `ppc_loo_intervals()` and `ppc_loo_ribbon()`, an optional
506
507
# ' integer vector indicating which observations in `y` (and `yrep`) to
507
508
# ' include. Dropping observations from `y` and `yrep` manually before passing
0 commit comments