@@ -269,16 +269,18 @@ ppc_loo_pit <-
269
269
# ' object returned by the \code{psis} function (or by the \code{loo} function
270
270
# ' with argument \code{save_psis} set to \code{TRUE}).
271
271
# ' @param prob A value between 0 and 1 indicating the desired probability mass
272
- # ' to include in the intervals. The default is 0.9.
272
+ # ' to include in the inner interval. The default is 0.5.
273
+ # ' @param prob_outer The probability mass to include in the outer interval.
274
+ # ' The default is 0.9.
273
275
# ' @param intervals For \code{ppc_loo_intervals} and \code{ppc_loo_ribbon},
274
- # ' optionally a matrix of precomputed LOO predictive intervals intervals with
276
+ # ' optionally a matrix of precomputed LOO predictive intervals
275
277
# ' that can be specified instead of \code{yrep} and \code{lw} (these are both
276
278
# ' ignored if \code{intervals} is specified). If not specified the intervals
277
279
# ' are computed internally before plotting. If specified, \code{intervals}
278
280
# ' must be a matrix with number of rows equal to the number of data points and
279
- # ' three columns in the following order: the first for the lower bound of the
280
- # ' interval, the second for median (50\%), and the third for the interval
281
- # ' upper bound (column names are ignored).
281
+ # ' five columns in the following order: lower outer interval, lower inner
282
+ # ' interval, median (50\%), upper inner interval and upper outer interval
283
+ # ' (column names are ignored).
282
284
# ' @param order For \code{ppc_loo_intervals}, a string indicating how to arrange
283
285
# ' the plotted intervals. The default (\code{"index"}) is to plot them in the
284
286
# ' order of the observations. The alternative (\code{"median"}) arranges them
@@ -300,7 +302,8 @@ ppc_loo_intervals <-
300
302
subset = NULL ,
301
303
intervals = NULL ,
302
304
... ,
303
- prob = 0.9 ,
305
+ prob = 0.5 ,
306
+ prob_outer = 0.9 ,
304
307
size = 1 ,
305
308
fatten = 3 ,
306
309
order = c(" index" , " median" )) {
@@ -309,11 +312,14 @@ ppc_loo_intervals <-
309
312
y <- validate_y(y )
310
313
order_by_median <- match.arg(order ) == " median"
311
314
if (! is.null(intervals )) {
312
- stopifnot(is.matrix(intervals ), ncol(intervals ) == 3 )
315
+ stopifnot(is.matrix(intervals ), ncol(intervals ) %in% c( 3 , 5 ) )
313
316
message(
314
317
" 'intervals' specified so ignoring " ,
315
318
" 'yrep', 'psis_object', 'subset', if specified."
316
319
)
320
+ if (ncol(intervals ) == 3 ) {
321
+ intervals <- cbind(intervals [, 1 ], intervals , intervals [, 3 ])
322
+ }
317
323
} else {
318
324
suggested_package(" loo" , min_version = " 2.0.0" )
319
325
yrep <- validate_yrep(yrep , y )
@@ -323,7 +329,8 @@ ppc_loo_intervals <-
323
329
yrep <- yrep [, subset , drop = FALSE ]
324
330
psis_object <- .psis_subset(psis_object , subset )
325
331
}
326
- a <- (1 - prob ) / 2
332
+ probs <- sort(c(prob , prob_outer ))
333
+ a <- (1 - probs ) / 2
327
334
stopifnot(identical(dim(psis_object ), dim(yrep )))
328
335
intervals <- suppressWarnings(t(loo :: E_loo(
329
336
x = yrep ,
@@ -367,17 +374,21 @@ ppc_loo_ribbon <-
367
374
subset = NULL ,
368
375
intervals = NULL ,
369
376
... ,
370
- prob = 0.9 ,
377
+ prob = 0.5 ,
378
+ prob_outer = 0.9 ,
371
379
alpha = 0.33 ,
372
380
size = 0.25 ) {
373
381
check_ignored_arguments(... )
374
382
y <- validate_y(y )
375
383
if (! is.null(intervals )) {
376
- stopifnot(is.matrix(intervals ), ncol(intervals ) == 3 )
384
+ stopifnot(is.matrix(intervals ), ncol(intervals ) %in% c( 3 , 5 ) )
377
385
message(
378
386
" 'intervals' specified so ignoring " ,
379
387
" 'yrep', 'psis_object', 'subset', if specified."
380
388
)
389
+ if (ncol(intervals ) == 3 ) {
390
+ intervals <- cbind(intervals [, 1 ], intervals , intervals [, 3 ])
391
+ }
381
392
} else {
382
393
suggested_package(" loo" , min_version = " 2.0.0" )
383
394
yrep <- validate_yrep(yrep , y )
@@ -387,7 +398,8 @@ ppc_loo_ribbon <-
387
398
yrep <- yrep [, subset , drop = FALSE ]
388
399
psis_object <- .psis_subset(psis_object , subset )
389
400
}
390
- a <- (1 - prob ) / 2
401
+ probs <- sort(c(prob , prob_outer ))
402
+ a <- (1 - probs ) / 2
391
403
stopifnot(identical(dim(psis_object ), dim(yrep )))
392
404
intervals <- suppressWarnings(t(loo :: E_loo(
393
405
x = yrep ,
@@ -416,9 +428,11 @@ ppc_loo_ribbon <-
416
428
y_id = seq_along(y ),
417
429
y_obs = y ,
418
430
x = x ,
419
- lo = intervals [, 1 ],
420
- mid = intervals [, 2 ],
421
- hi = intervals [, 3 ])
431
+ ll = intervals [, 1 ],
432
+ l = intervals [, 2 ],
433
+ m = intervals [, 3 ],
434
+ h = intervals [, 4 ],
435
+ hh = intervals [, 5 ])
422
436
}
423
437
424
438
# subset a psis_object without breaking it
0 commit comments