This vignette provides a two-page introduction to the scoringRules package. For a more detailed introduction, see the paper 'Evaluating probabilistic forecasts with scoringRules' (Jordan, Krüger, and Lerch, Journal of Statistical Software, forthcoming) which is available as a further vignette to scoringRules.

# Background

Forecasting a continuous random variable, such as temperature (in degrees Celsius) or the inflation rate (in percent) is important in many situations. Since forecasts are usually surrounded by uncertainty, it makes sense to state forecast distributions, rather than point forecasts. The scoringRules package offers mathematical tools to evaluate a forecast distribution, $$F$$, after an outcome $$y$$ has realized. To this end, we use scoring rules which assign a penalty score $$S(y, F)$$ to the realization/forecast pair; a smaller score corresponds to a better forecast. See Gneiting and Katzfuss ('Probabilistic Forecasting', Annual Review of Statistics and Its Application, 2014) for an introduction to the relevant statistical literature.

scoringRules supports two types of forecast distributions, $$F$$: Distributions given by a parametric family (such as Normal or Gamma), and distributions given by a simulated sample. Furthermore, the package covers the two most popular scoring rules $$S$$: The logarithmic score (LogS), given by $\text{LogS}(y, F) = -\log f(y),$ where $$f$$ is the density conforming to $$F$$, and the continuous ranked probability score (CRPS), given by $\text{CRPS}(y, F) = \int_{-\infty}^\infty (F(z) - \mathbf{1}(y \le z))^2 dz,$ where $$\mathbf{1}(A)$$ is the indicator function of the event $$A$$. The LogS is typically easy to compute, and we include it mainly for reference purposes. By contrast, the CRPS can be very tricky to compute analytically, and cumbersome to approximate numerically. The scoringRules package implements several new methods to tackle this challenge. Specifically, we include many previously unknown analytical expressions, and incorporate recent findings on how to best compute the CRPS of a simulated forecast distribution.

# Example 1: Parametric forecast distribution

Suppose the forecast distribution is $$\mathcal{N}(2, 4)$$, and an outcome of zero realizes:\vspace{-1.5cm} The following piece of code computes the CRPS for this situation:

library(scoringRules)
# CRPS of a normal distribution with mean = standard deviation = 2, outcome is zero
crps(y = 0, family = "normal", mean = 2, sd = 2)

##  1.204883


As documented under ?crps, the parametric family used in the example is one of the following choices currently implemented in scoringRules:

• Normal, Mixture of normals, Two-piece normal, Log-normal, Generalized truncated/censored normal, (Scaled) Student t, Generalized truncated/censored Student t, Laplace, Log-Laplace, Logistic, Log-logistic, Generalized truncated/censored logistic, Exponential, Exponential with point mass, Two-piece exponential, Beta, Gamma, Uniform, Generalized extreme value, Generalized Pareto, Binomial, Hypergeometric, Negative binomial, Poisson

We provide analytical CRPS formulas in Appendix A of the vignette 'Evaluating Probabilistic Forecasts with scoringRules'. Whenever possible, our syntax and parametrization closely follow base R. For distributions not supported by base R, we have created documentation pages with details; see for example ?f2pnorm.

# Example 2: Simulated forecast distribution

Via data(gdp_mcmc), the user can load a sample data set with forecasts and realizations for the growth rate of US gross domestic product, a widely regarded economic indicator. The following plot shows the histogram of a simulated forecast distribution for the fourth quarter of 2012:\vspace{-1.3cm} Let's now compute the CRPS for this simulated forecast distribution:

# Load data
data(gdp_mcmc)
# Get forecast distribution for 2012:Q4
dat <- gdp_mcmc$forecasts[, "X2012Q4"] # Get realization for 2012:Q4 y <- gdp_mcmc$actuals[, "X2012Q4"]
# Compute CRPS of simulated sample
crps_sample(y = y, dat = dat)

##  0.9058803
{"ft_lang_label":"__label__en","ft_lang_prob":0.8638614,"math_prob":0.9797149,"size":3526,"snap":"2021-04-2021-17","text_gpt3_token_len":840,"char_repetition_ratio":0.13458262,"word_repetition_ratio":0.0,"special_character_ratio":0.23567782,"punctuation_ratio":0.12748344,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99834764,"pos_list":[0,1,2,3,4],"im_url_duplicate_count":[null,null,null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-23T02:23:35Z\",\"WARC-Record-ID\":\"<urn:uuid:2eeb6081-7f0e-4499-9766-76b9151ffae2>\",\"Content-Length\":\"34768\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:b4660c94-0ef2-4beb-891e-741e9d7af7e7>\",\"WARC-Concurrent-To\":\"<urn:uuid:bf12a48c-3249-42b6-8458-18309e510faf>\",\"WARC-IP-Address\":\"148.205.148.16\",\"WARC-Target-URI\":\"https://cran.itam.mx/web/packages/scoringRules/vignettes/gettingstarted.html\",\"WARC-Payload-Digest\":\"sha1:R36XK452XV7LLCPOKDZQWDWRZTX6SNT5\",\"WARC-Block-Digest\":\"sha1:FTYYCWMDIQEUK7ASKCVNJ2MB4T4SQPVD\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610703531702.36_warc_CC-MAIN-20210123001629-20210123031629-00183.warc.gz\"}"}