cpi: Central Prediction Interval

View source: R/cpi.R

cpiR Documentation

Central Prediction Interval

Description

This function can calculate the central prediction interval score (IS), overprediction, underprediction, width and coverage of a central prediction interval given observations of univariate variable and quantiles of a predictive distribution for a certain nominal coverage.

Usage

cpi(
  y,
  lower,
  upper,
  nominal.coverage,
  separate = "is",
  na.action = na.omit,
  aggregate = FALSE,
  ...
)

Arguments

y

vector of observations

lower

vector with the lower quantiles (depending on nominal.coverage; see details)

upper

vector with the upper quantiles (depending on nominal.coverage; see details)

nominal.coverage

numeric; nominal coverage in % (see details)

separate

character; vector with "is", "overprediction", "underprediction", "width" or "coverage"; default: "is" (see details)

na.action

function to handle the NA's. Default: na.omit.

aggregate

logical or function for aggregating the single scores, e.g. sum, mean, weighted.mean, .... Default: FALSE, i.e. no aggregation function.

...

further arguments passed to the aggregate function.

Details

For a vector y of length n, lower, upper and nominal.coverage should be given as vector of length n, where the i-th entry of y belongs to the i-th entry of the other vectors. For nominal.coverage only one value is also sufficient.

The nominal.coverage corresponds to alpha := (100 - nominal.coverage)/100. Consequently lower must provide the alpha/2-quantiles and upper the (1-alpha/2)-quantiles of a predictive distribution. Internally, nominal.coverage will be transformed to alpha.

The parameter separate allows to choose the output values. "is" is the central prediction interval score, "overprediction" is the overprediction, "underprediction" is the underprediction, "width" is the central prediction interval width and "coverage" is the central prediction interval coverage. If an observation lies in a central prediction interval, the output will be 1, otherwise 0 for the parameter "coverage".

A lower IS indicates a better forecast.

A lower central prediction interval width indicates a sharper forecast.

A score of the central prediction interval coverage close to nominal.coverage indicates a more calibrated forecast. A central prediction interval coverage score of nominal.coverage is optimal and indicates a calibrated forecast.

Value

Vector or list of score value(s) specified in separate.

Author(s)

David Jobst

References

Gneiting, T. and Raftery, A. (2007). Strictly Proper Scoring Rules, Prediction, and Estimation. Journal of the American Statistical Association, 102, 359-378.

Examples

# simulated data
n <- 30
y <- rnorm(n, mean = 1:n)
nominal.coverage <- 90
alpha <- (100-nominal.coverage)/100
lower <- qnorm(alpha/2, rnorm(n, mean = 1:n))
upper <- qnorm((1-alpha/2), rnorm(n, mean = 1:n))

# cpi calculation
cpi(y = y, lower = lower, upper = upper, nominal.coverage = nominal.coverage,
separate = "is")
cpi(y = y, lower = lower, upper = upper, nominal.coverage = nominal.coverage,
separate = "is", aggregate = mean)

cpi(y = y, lower = lower, upper = upper, nominal.coverage = nominal.coverage,
separate = c("is", "overprediction", "underprediction", "width", "coverage"))
cpi(y = y, lower = lower, upper = upper, nominal.coverage = nominal.coverage,
separate = c("is", "overprediction", "underprediction", "width", "coverage"),
aggregate = mean)


jobstdavid/eppverification documentation built on May 13, 2024, 5:20 p.m.