crps | R Documentation |
The crps()
and scrps()
functions and their loo_*()
counterparts can be
used to compute the continuously ranked probability score (CRPS) and scaled
CRPS (SCRPS) (see Bolin and Wallin, 2022). CRPS is a proper scoring rule, and
strictly proper when the first moment of the predictive distribution is
finite. Both can be expressed in terms of samples form the predictive
distribution. See e.g. Gneiting and Raftery (2007) for a comprehensive
discussion on CRPS.
crps(x, ...)
scrps(x, ...)
loo_crps(x, ...)
loo_scrps(x, ...)
## S3 method for class 'matrix'
crps(x, x2, y, ..., permutations = 1)
## S3 method for class 'numeric'
crps(x, x2, y, ..., permutations = 1)
## S3 method for class 'matrix'
loo_crps(
x,
x2,
y,
log_lik,
...,
permutations = 1,
r_eff = 1,
cores = getOption("mc.cores", 1)
)
## S3 method for class 'matrix'
scrps(x, x2, y, ..., permutations = 1)
## S3 method for class 'numeric'
scrps(x, x2, y, ..., permutations = 1)
## S3 method for class 'matrix'
loo_scrps(
x,
x2,
y,
log_lik,
...,
permutations = 1,
r_eff = 1,
cores = getOption("mc.cores", 1)
)
x |
A |
... |
Passed on to |
x2 |
Independent draws from the same distribution as draws in |
y |
A vector of observations or a single value. |
permutations |
An integer, with default value of 1, specifying how many
times the expected value of |X - X'| ( |
log_lik |
A log-likelihood matrix the same size as |
r_eff |
An optional vector of relative effective sample size estimates
containing one element per observation. See |
cores |
The number of cores to use for parallelization of |
To compute (S)CRPS, the user needs to provide two sets of draws, x
and
x2
, from the predictive distribution. This is due to the fact that formulas
used to compute CRPS involve an expectation of the absolute difference of x
and x2
, both having the same distribution. See the permutations
argument,
as well as Gneiting and Raftery (2007) for details.
A list containing two elements: estimates
and pointwise
.
The former reports estimator and standard error and latter the pointwise
values.
Bolin, D., & Wallin, J. (2022). Local scale invariance and robustness of proper scoring rules. arXiv. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.48550/arXiv.1912.05642")}
Gneiting, T., & Raftery, A. E. (2007). Strictly Proper Scoring Rules, Prediction, and Estimation. Journal of the American Statistical Association, 102(477), 359–378.
## Not run:
# An example using rstanarm
library(rstanarm)
data("kidiq")
fit <- stan_glm(kid_score ~ mom_hs + mom_iq, data = kidiq)
ypred1 <- posterior_predict(fit)
ypred2 <- posterior_predict(fit)
crps(ypred1, ypred2, y = fit$y)
loo_crps(ypred1, ypred2, y = fit$y, log_lik = log_lik(fit))
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.