---
title: "Closed form expressions for the continuous ranked probability score"
author: "Alexander Jordan"
date: "`r Sys.Date()`"
output:
  rmarkdown::html_vignette:
    toc: TRUE
    toc_depth: 2
    number_sections: TRUE
vignette: >
  %\VignetteIndexEntry{CRPS formulas}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
# output: pdf_document
bibliography: closedforms.bib
---

# Introduction

The continuous ranked probability score can be given in multiple equivalent forms,
\begin{align*}
\label{eq:kernel}\mathrm{CRPS}(F,y) &= \mathbb{E}_F|Y-y| - \frac{1}{2}\mathbb{E}_F|Y-Y'| \\
&= \int_{-\infty}^y F(x)^2 \, \mathrm{d} x + \int_y^{\infty} \left(1 - F(x)\right)^2 \, \mathrm{d} x \\
&= 2\int_0^{F(y)} \alpha\left(y - F^{-1}(\alpha)\right) \, \mathrm{d} \alpha + 2\int_{F(y)}^1 (1 - \alpha)\left(F^{-1}(\alpha) - y\right) \, \mathrm{d} \alpha,
\end{align*}
where the first is the kernel representation, followed by the threshold decomposition, and lastly the quantile decomposition. The threshold decomposition corresponds to the integral of the Brier score over all event thresholds, while the quantile decomposition is the integral of the quantile score over all probabilities. 

# Distributions for variables on the real line

## Laplace distribution (`"lapl"`) {#Laplace}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F, y) &= |y| + \exp(-|y|) - \frac{3}{4}, \\
	\mathrm{CRPS}(F_{\mu, \sigma}, y) &= \sigma\, \mathrm{CRPS}\left(F, \tfrac{y - \mu}{\sigma}\right).
\end{align*}
Laplace distribution:
\begin{align*}
F(x) &= \begin{cases} \frac{1}{2} \exp(x), & x < 0,\\ 1 - \frac{1}{2} \exp(-x), & x \geq 0, \end{cases} \\
F_{\mu, \sigma}(x) &= F\left(\tfrac{x - \mu}{\sigma}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-
|`"location"` | $\mu \in \mathbb{R}$ |
|`"scale"`    | $\sigma > 0$         |

See also: [Two-piece exponential distribution](#tpexp)

## Logistic distribution (`"logis"`) {#Logistic}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F, y) &= y - 2\log(F(y)) - 1, \\
	\mathrm{CRPS}(F_{\mu, \sigma}, y) &= \sigma\, \mathrm{CRPS}\left(F, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Logistic distribution:
\begin{align*}
F(x) &= \frac{1}{1 + \exp(-x)}, \\
F_{\mu, \sigma}(x) &= F\left(\tfrac{x - \mu}{\sigma}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-
|`"location"` | $\mu \in \mathbb{R}$ |
|`"scale"`    | $\sigma > 0$         |

See also: [Generalized truncated/censored logistic distribution](#GenLogistic)


## Normal distribution (`"norm"`) {#Normal}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F, y) &= y\left(2F(y)-1\right) + 2f(y)  - \frac{1}{\sqrt{\pi}}, \\
	\mathrm{CRPS}(F_{\mu, \sigma}, y) &= \sigma\, \mathrm{CRPS}\left(F, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Normal distribution:
\begin{align*}
f(x) &= \tfrac{1}{\sqrt{2\pi}}\exp\left(-\tfrac{x^2}{2}\right), \\
F(x) &= \int_{-\infty}^x f(t)\, \mathrm{d} x, \\
F_{\mu, \sigma}(x) &= F\left(\tfrac{x - \mu}{\sigma}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-
|`"mean"`     | $\mu \in \mathbb{R}$ |
|`"sd"`       | $\sigma > 0$         |

Notes:

- @gneiting2005 is the original source of this CRPS formula.

See also: [Mixture of normal distributions](#Mixnorm), [Two-piece normal distribution](#tpnorm), [Generalized truncated/censored normal distribution](#GenNormal)


## Mixture of normal distributions (`"mixnorm"`) {#Mixnorm}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F,y) &= \sum_{i=1}^M \omega_i A\left(y-\mu_i,\sigma_i^2\right) - \frac{1}{2} \sum_{i=1}^M\sum_{j=1}^{M}\omega_i \omega_j A\left(\mu_i-\mu_j,\sigma_i^2+\sigma_j^2\right).
\end{align*}
Finite mixture of normal distributions:
\begin{align*}
  F(x) &= \sum_{i=1}^M \omega_i \Phi\left(\tfrac{x-\mu_i}{\sigma_i}\right), \\
  A\left(\mu,\sigma^2\right) &= \mu\left(2\Phi\left(\tfrac{\mu}{\sigma}\right) -1 \right) + 2\sigma \varphi\left(\tfrac{\mu}{\sigma}\right), \\
  \varphi(x) &= \tfrac{1}{\sqrt{2\pi}}\exp\left(-\tfrac{x^2}{2}\right), \\
  \Phi(x) &= \int_{-\infty}^x \varphi(t)\, \mathrm{d} x.
\end{align*}
Parameters:

Name | Domain
:-|:-
|`"m"`     |$\mu_1, \ldots, \mu_M \in \mathbb{R}$
|`"s"`     |$\sigma_1, \ldots, \sigma_M > 0$
|`"w"`     |$\omega_1, \ldots, \omega_M > 0$, $\omega_1 + \ldots + \omega_M = 1$

Notes:

- @grimit2006 is the original source of this CRPS formula.
- Computation time increases quadratically in the number of mixture components. For $M$ in the order of several thousand, numerical integration to machine precision may be faster than using the formula above.

See also: [Normal distribution](#Normal)


## Student's $t$-distribution (`"t"`) {#Student}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_\nu, y) &= y\Big(2F_\nu(y) - 1\Big) + 2f_\nu(y) \left(\frac{\nu + y^2}{\nu - 1}\right) - \frac{2\sqrt{\nu}}{\nu - 1}\frac{B(\tfrac{1}{2}, \nu - \tfrac{1}{2})}{B(\tfrac{1}{2}, \tfrac{\nu}{2})^2}, \\
	\mathrm{CRPS}(F_{\nu, \mu, \sigma}, y) &= \sigma\, \mathrm{CRPS}\left(F_\nu, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Student's $t$-distribution:
\begin{align*}
f_\nu(x) &= \frac{1}{\sqrt{\nu}B(\tfrac{1}{2},\tfrac{\nu}{2})}\left(1+\frac{x^2}{\nu}\right)^{-\tfrac{\nu+1}{2}}, \\
F_\nu(x) &= \frac{1}{2} + \frac{x\ {}_2F_1(\tfrac{1}{2},\tfrac{\nu+1}{2};\tfrac{3}{2};-\tfrac{x^2}{\nu})}{\sqrt{\nu} B(\tfrac{1}{2},\tfrac{\nu}{2})}, \\
F_{\nu, \mu, \sigma}(x) &= F_\nu\left(\tfrac{x - \mu}{\sigma}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-|:-
|`"df"`       | $\nu > 1$ (for $\nu \in (0, 1]$ the CRPS is undefined)
|`"location"` | $\mu \in \mathbb{R}$
|`"scale"`    | $\sigma > 0$

Mathematical functions:

Symbol | Name
:-|:-
${}_2F_1$ | hypergeometric function
$B$ | beta function

See also: [Generalized truncated/censored Student's $t$-distribution](#GenStudent)


## Two-piece exponential distribution (``"2pexp"``) {#tpexp}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_{\sigma_1, \sigma_2}, y) &= \begin{cases}	\left\lvert y \right\rvert + \frac{2\sigma_1^2}{\sigma_1 + \sigma_2}\exp\left(-\left\lvert \frac{y}{\sigma_1}\right\rvert \right) - \frac{ 2\sigma_1^2}{\sigma_1 + \sigma_2} + \frac{\sigma_1^3 + \sigma_2^3}{2(\sigma_1 + \sigma_2)^2}, & y < 0, \\ \left\lvert y \right\rvert + \frac{2\sigma_2^2}{\sigma_1 + \sigma_2}\exp\left(-\left\lvert \frac{y}{\sigma_2}\right\rvert \right) - \frac{ 2\sigma_2^2}{\sigma_1 + \sigma_2} + \frac{\sigma_1^3 + \sigma_2^3}{2(\sigma_1 + \sigma_2)^2}, & y \ge 0, \end{cases} \\
	\mathrm{CRPS}(F_{\mu, \sigma_1, \sigma_2}, y) &= \mathrm{CRPS}(F_{\sigma_1, \sigma_2}, y - \mu).
\end{align*}
Two-piece exponential distribution:
\begin{align*}
F_{\sigma_1, \sigma_2}(x) &= \begin{cases} \frac{\sigma_1}{\sigma_1 + \sigma_2}\exp\left(\frac{x}{\sigma_1}\right), & x < 0, \\
1 - \frac{\sigma_2}{\sigma_1 + \sigma_2}\exp\left(-\frac{x}{\sigma_2}\right), & x \ge 0,\end{cases} \\
F_{\mu, \sigma_1, \sigma_2}(x) &= F_{\sigma_1, \sigma_2}(x - \mu).
\end{align*}
Parameters:

Name | Domain
:-|:-
| `"location"` | $\mu \in \mathbb{R}$ |
| `"scale1"`   | $\sigma_1 > 0$ |
| `"scale2"`   | $\sigma_2 > 0$ |

See also: [Laplace](#Laplace)


## Two-piece normal distribution (`"2pnorm"`) {#tpnorm}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_{\sigma_1, \sigma_2}, y) &= \sigma_1\, \mathrm{CRPS}\left(F_{-\infty, 0}^{0, \sigma_2/(\sigma_1 + \sigma_2)}, \tfrac{\min(0, y)}{\sigma_1}\right) \\
	&\quad + \sigma_2\, \mathrm{CRPS}\left(F_{0, \sigma_1/(\sigma_1 + \sigma_2)}^{\infty, 0}, \tfrac{\max(0, y)}{\sigma_2}\right), \\
	\mathrm{CRPS}(F_{\mu, \sigma_1, \sigma_2}, y) &= \mathrm{CRPS}(F_{\sigma_1, \sigma_2}, y - \mu),
\end{align*}
with $F_{l, L}^{u, U}$ as in [Generalized truncated/censored normal distribution](#GenNormal).

Two-piece normal distribution:
\begin{align*}
  F_{\sigma_1,\sigma_2}(x) &= \begin{cases} \frac{2\sigma_1}{\sigma_1+\sigma_2}\Phi\left(\frac{x}{\sigma_1}\right), & x < 0,\\ \frac{\sigma_1-\sigma_2}{\sigma_1+\sigma_2} + \frac{2\sigma_2}{\sigma_1+\sigma_2} \Phi\left(\frac{x}{\sigma_2}\right), & x \ge 0, \end{cases} \\
  F_{\mu, \sigma_1, \sigma_2}(x) &= F_{\sigma_1, \sigma_2}(x - \mu), \\
  \Phi(x) &= \int_{-\infty}^x \varphi(t)\, \mathrm{d} x, \\
  \varphi(x) &= \tfrac{1}{\sqrt{2\pi}}\exp\left(-\tfrac{x^2}{2}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-
| `"location"` | $\mu \in \mathbb{R}$ |
| `"scale1"`   | $\sigma_1 > 0$ |
| `"scale2"`   | $\sigma_2 > 0$ |

Notes:

- @gneiting2010 give an explicit CRPS formula.
- The left tail follows a right-censored normal distribution, censored at 0 with mass \mbox{$\sigma_2/(\sigma_1 + \sigma_2)$}, with location parameter 0 and scale parameter $\sigma_1$. The right tail follows a left-censored normal distribution, censored at 0 with mass \mbox{$\sigma_1/(\sigma_1 + \sigma_2)$}, with location parameter 0 and scale parameter $\sigma_2$.
- The same construction can be used to implement two-piece families based on the [$t$](#Student), [logistic](#Logistic), [exponential](#Exponential) (see section [Two-piece exponential](#tpexp)), and [generalized Pareto](#GPD) distributions.

See also: [Normal distribution](#Normal)


# Distributions for non-negative variables


## Exponential distribution (`"exp"`) {#Exponential}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_\lambda, y) &= |y| - \frac{2F_\lambda(y)}{\lambda} + \frac{1}{2\lambda}.
\end{align*}
Exponential distribution:
\begin{align*}
F_\lambda(x) = \begin{cases} 1 - \exp(-\lambda x), & x \ge 0, \\ 0, & x < 0.\end{cases}
\end{align*}
Parameters:

Name | Domain
:-|:-
`"rate"` | $\lambda > 0$

See also: [Exponential distribution with point mass](#GenExp), [Generalized Pareto distribution with point mass](#GPD)


## Gamma distribution (`"gamma"`)
CRPS formula:
	\[
	\mathrm{CRPS}(F_{\alpha,\beta},y) = y\left(2F_{\alpha,\beta}(y)-1\right) - \frac{\alpha}{\beta}\left(2F_{\alpha + 1, \beta}(y) -1\right) - \frac{1}{\beta B\left(\tfrac{1}{2},\alpha\right)}
	\]
Gamma distribution:
\begin{align*}
F_{\alpha,\beta}(x) &= \begin{cases}\frac{\Gamma_l(\alpha,\beta x)}{\Gamma(\alpha)}, & x \geq 0, \\ 0, & x < 0. \end{cases}
\end{align*}
Parameters:

Name | Domain
:-|:-
`"shape"` | $\alpha > 0$
`"rate"` | $\beta > 0$

Mathematical functions:

Symbol | Name
:-|:-
$B$ | beta function
$\Gamma$ | gamma function
$\Gamma_l$ | lower incomplete gamma function

Notes:

- @moeller2013 is the original source of this CRPS formula.


## Log-Laplace distribution (`"llapl"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_{\mu, \sigma}, y) &= y\Big(2F_{\mu, \sigma}(y) - 1\Big) + \exp(\mu) \left(\tfrac{\sigma}{4 - \sigma^2} + A(y) \right)
\end{align*}
Log-Laplace distribution:
\begin{align*}
  F_{\mu, \sigma}(x) &= \begin{cases} 0, & x \leq 0,\\ \frac{1}{2}\exp\left(\frac{\log x - \mu}{\sigma}\right), & 0 < x < \exp(\mu), \\
1 - \frac{1}{2}\exp\left(-\frac{\log x - \mu}{\sigma}\right), & x \geq \exp(\mu), \end{cases} \\
  A(x) &= \begin{cases} \frac{1}{1 + \sigma}\left(1-\left(2F_{\mu, \sigma}(x)\right)^{1+\sigma}\right), & x < \exp(\mu), \\ -\frac{1}{1-\sigma}\left(1-\left(2(1-F_{\mu, \sigma}(x))\right)^{1-\sigma}\right), & y \geq \exp(\mu). \end{cases}
\end{align*}
Parameters:

Name | Domain
:-|:-
`"locationlog"` | $\mu \in \mathbb{R}$
`"scalelog"` | $\sigma \in (0, 1)$ (for $\sigma \ge 1$ the CRPS is undefined)


## Log-logistic distribution (`"llogis"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_{\mu, \sigma}, y) &= y\left(2F_{\mu, \sigma}(y) - 1\right) - 2\exp(\mu) B(F_{\mu, \sigma}(y); 1 + \sigma, 1 - \sigma) \\
	&\quad + \exp(\mu)(1 - \sigma)B(1 + \sigma, 1 - \sigma)
\end{align*}
Log-logistic distribution:
\begin{align*}
F_{\mu, \sigma}(x) &= \begin{cases} 0, & x \leq 0, \\ \left(1 + \exp\left(-\tfrac{\log x - \mu}{\sigma}\right)\right)^{-1}, & x > 0, \end{cases}
\end{align*}
Parameters:

Name | Domain
:-|:-
`"locationlog"` | $\mu \in \mathbb{R}$
`"scalelog"` | $\sigma \in (0, 1)$ (for $\sigma \ge 1$ the CRPS is undefined)

Mathematical functions:

Symbol | Name
:-|:-
$B(\cdot, \cdot)$ | beta function
$B(x; \cdot, \cdot)$ | incomplete beta function

Notes:

- @taillardat2016 give an alternative CRPS formula.


## Log-normal distribution (`"lnorm"`)
\begin{align*}
	\mathrm{CRPS}(F_{\mu,\sigma},y) &= y\left(2F_{\mu, \sigma}(y) - 1\right) - 2 \exp(\mu+\sigma^2/2)\left(\Phi\left(\tfrac{\log y -\mu - \sigma^2}{\sigma}\right) + \Phi\left(\tfrac{\sigma}{\sqrt{2}}\right) - 1\right)
\end{align*}
Log-normal distribution:
\begin{align*}
  F_{\mu,\sigma}(x) &= \begin{cases} 0, & x\leq 0, \\ \Phi\left(\tfrac{\log x - \mu}{\sigma}\right), & x > 0, \end{cases} \\
  \varphi(x) &= \tfrac{1}{\sqrt{2\pi}}\exp\left(-\tfrac{x^2}{2}\right), \\
  \Phi(x) &= \int_{-\infty}^x \varphi(t)\, \mathrm{d} x.
\end{align*}
Parameters:

Name | Domain
:-|:-
`"locationlog"` | $\mu \in \mathbb{R}$
`"scalelog"` | $\sigma > 0$

Notes:

- @baran2014 is the original source of this CRPS formula.


# Distributions with flexible support and/or point masses


## Beta distribution (`"beta"`) {#Beta}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_{\alpha, \beta}, y) &= y(2F_{\alpha, \beta}(y) - 1) + \frac{\alpha}{\alpha + \beta} \left(1 - 2F_{\alpha + 1, \beta}(y) - \frac{2B(2\alpha, 2\beta)}{\alpha B(\alpha, \beta)^2} \right), \\
	\mathrm{CRPS}(F_{l, \alpha, \beta}^{u}, y) &= (u - l)\, \mathrm{CRPS}\left(F_{\alpha, \beta}, \tfrac{y - l}{u - l} \right).
\end{align*}

Beta distribution:
\begin{align*}
  F_{\alpha, \beta}(x) &= \begin{cases} 0 & x < 0\\ I(x; \alpha, \beta) & 0 \leq x < 1\\ 1 & x \geq 1 \end{cases}, \\
  F_{l, \alpha, \beta}^{u}(x) &= F_{\alpha, \beta}\left(\tfrac{x - l}{u - l}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-
`"shape1"` | $\alpha > 0$
`"shape2"` | $\beta > 0$
`"lower"` | $l \in \mathbb{R}$, $l < u$
`"upper"` | $u \in \mathbb{R}$, $l < u$

Mathematical functions:

Symbol | Name
:-|:-
$B$ | beta function
$I$ | regularized incomplete beta function

Notes:

-	@taillardat2016 give an equivalent expression.

See also: [Continuous uniform distribution](#Unif)


## Continuous uniform (`"unif"`) {#Unif}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F, y) &= |y - z| + z^2 - z + \frac{1}{3}, \\
	\text{where}\quad z &= \begin{cases} 0, & y < 0, \\ y, & 0 \le y < 1, \\ 1, & y \ge 1. \end{cases}
\end{align*}
Continuous uniform:
\begin{align*}
  F(x) &= \begin{cases} 0, & x < 0,\\ x, & 0 \leq x < 1,\\ 1, & x > 1. \end{cases}
\end{align*}

See also: [Beta distribution](#Beta)


### Generalized continuous uniform (`"unif"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_{L}^{U}, y) &= |y - z| + z^2(1 - L - U) - z(1 - 2L) \\
	&\quad + \frac{(1 - L - U)^2}{3} + (1 - L)U, \\
	\text{where}\quad z &= \begin{cases} 0, & y < 0, \\ y, & 0 \le y < 1, \\ 1, & y \ge 1, \end{cases} \\
	\mathrm{CRPS}(F_{l, L}^{u, U}, y) &= (u - l)\, \mathrm{CRPS}\left(F_{L}^{U}, \tfrac{y - l}{u - l} \right).
\end{align*}
Continuous uniform with point masses and support transformation:
\begin{align*}
  F_{L}^{U}(x) &= \begin{cases} 0, & x < 0, \\ L + (1 - L - U) x, & 0 \leq x < 1,\\ 1, & x \geq 1, \end{cases} \\
  F_{l, L}^{u, U}(x) &= F_{L}^{U}\left(\tfrac{x - l}{u - l}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-
`"min"` | $l \in \mathbb{R}$, $l < u$
`"max"` | $u \in \mathbb{R}$, $l < u$
`"lmass"` | $L \ge 0$, $L + U < 1$
`"umass"` | $U \ge 0$, $L + U < 1$


## Exponential distribution with point mass (`"expM"`) {#GenExp}
\begin{align*}
	\mathrm{CRPS}(F_{M}, y) &= |y| - 2  (1 - M)F(y) + \frac{(1 - M)^2}{2}, \\
	\mathrm{CRPS}(F_{M, \mu, \sigma}, y) &= \sigma\, \mathrm{CRPS}\left(F_M, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Exponential distribution with point mass:
\begin{align*}
  F_M(x) &= \begin{cases} M + (1 - M)F(x), & x \ge 0, \\ 0, & x < 0, \end{cases} \\
  F(x) &= \begin{cases} 1 - \exp(-x), & x \ge 0, \\ 0, & x < 0, \end{cases} \\
  F_{M, \mu, \sigma}(x) &= F_M\left(\tfrac{x - \mu}{\sigma}\right).
\end{align*}
Parameters:

Name | Domain
:-|:-|:-
|`"location"` | $\mu \in \mathbb{R}$
|`"scale"`    | $\sigma > 0$
|`"mass"` | $M \in [0, 1]$

See also: [Exponential distribution](#Exponential), [Generalized Pareto distribution with point mass](#GPD)


## Generalized extreme value distribution (`"gev"`)
CRPS formula:
\begin{align*}
  \mathrm{CRPS}(F_{\xi, \mu, \sigma}, y) &= \sigma\, \mathrm{CRPS}\left(F_{\xi}, \tfrac{y - \mu}{\sigma} \right), \\
	\text{For $\xi = 0$:}\quad \mathrm{CRPS}(F_{\xi},y) &= - y - 2 \mathrm{Ei}(\log F_{\xi}(y)) + C - \log 2, \\
  \text{For $\xi \neq 0$:} \quad \mathrm{CRPS}(F_\xi, y) &= y\left(2F_\xi(y) - 1\right) - 2G_\xi(y) - \frac{1 - \left(2 - 2^\xi\right)\Gamma(1 - \xi)}{\xi}.
\end{align*}
Generalized extreme value distribution:
\begin{align*}
  F_{\xi, \mu, \sigma}(x) &= F_{\xi}\left(\tfrac{x - \mu}{\sigma}\right), \\
  \text{for $\xi = 0$:}\quad F_{\xi}(x) &= \exp\left(-\exp(-x)\right) \\
  \text{for $\xi > 0$:}\quad F_{\xi}(x) &= \begin{cases} 0, & x \le -\frac{1}{\xi}, \\ \exp\left(-(1+\xi x)^{-1/\xi}\right), & x >  -\frac{1}{\xi}, \end{cases}\\
  G_{\xi}(x) &= \begin{cases} 0, & x \le -\frac{1}{\xi}, \\ -\frac{F_\xi(x)}{\xi} + \frac{\Gamma_u(1 - \xi, -\log F_\xi(x))}{\xi}, & x > -\frac{1}{\xi}, \end{cases} \\
  \text{for $\xi < 0$:}\quad F_{\xi}(x) &= \begin{cases} \exp\left(-(1+\xi x)^{-1/\xi}\right), & x <  -\frac{1}{\xi}, \\ 1, & x \ge -\frac{1}{\xi}, \end{cases} \\
  G_\xi(x) &= \begin{cases} -\frac{F_\xi(x)}{\xi} + \frac{\Gamma_u(1 - \xi, -\log F_\xi(x))}{\xi}, & x < -\frac{1}{\xi}, \\ -\frac{1}{\xi} + \frac{\Gamma(1 - \xi)}{\xi}, & x \ge -\frac{1}{\xi}. \end{cases}
\end{align*}
Parameters:

Name | Domain
:-|:-|:-
|`"shape"` | $\xi < 1$ (for $\xi \ge 1$ the CRPS is undefined)
|`"location"` | $\mu \in \mathbb{R}$
|`"scale"`    | $\sigma > 0$

Mathematical constants and functions:

Symbol | Name
:-|:-
$C$ | Euler-Mascheroni constant
$\mathrm{Ei}$ | exponential integral
$\Gamma$ | gamma function
$\Gamma_u$ | upper incomplete gamma function

Notes:

- @friederichs2012 is the original source of this formula.


## Generalized Pareto distribution with point mass (`"gpd"`) {#GPD}
CRPS formula:
\begin{align*}
  \mathrm{CRPS}(F_{M, \xi}, y) &= |y| - \frac{2(1 - M)}{1 - \xi}\left(1 - \left(1 - F_\xi(y)\right)^{1 - \xi}\right) + \frac{(1 - M)^2}{2 - \xi}, \\
  \mathrm{CRPS}(F_{M, \xi, \mu, \sigma}, y) &= \sigma\, \mathrm{CRPS}\left(F_{M, \xi}, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Generalized Pareto distribution with point mass:
\begin{align*}
  F_{M, \xi}(x) &= \begin{cases} M + (1 - M)F_\xi(x), & x \ge 0, \\ 0, & x < 0, \end{cases} \\
  F_{M, \xi, \mu, \sigma}(x) &= F_{M, \xi}\left(\tfrac{x - \mu}{\sigma}\right) \\
  \text{for $\xi > 0$:}\quad F_\xi(x) &= \begin{cases} 0, & x < 0, \\ 1 - (1 + \xi x)^{-1/\xi}, & x \ge 0, \end{cases} \\
  \text{for $\xi < 0$:}\quad F_\xi(x) &= \begin{cases} 0, & x < 0, \\ 1 - (1 + \xi x)^{-1/\xi}, & 0 \le x < |\xi|^{-1}, \\ 1, & x \ge |\xi|^{-1}, \end{cases} \\
  \text{for $\xi = 0$:}\quad F_\xi(x) &= \begin{cases} 0, & x < 0, \\ 1 - \exp(-x), & x \ge 0. \end{cases}
\end{align*}
Parameters:

Name | Domain
:-|:-|:-
|`"shape"` | $\xi < 1$ (for $\xi \ge 1$ the CRPS is undefined)
|`"location"` | $\mu \in \mathbb{R}$
|`"scale"`    | $\sigma > 0$
|`"mass"` | $M \in [0, 1]$

Notes:

- @friederichs2012 give CRPS formulas for the generalized Pareto distribution without a point mass.

See also: [Exponential distribution](#Exponential), [Exponential distribution with point mass](#GenExp)


## Generalized truncated/censored logistic distribution (`"gtclogis"`) {#GenLogistic}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}\left(F_{l, L}^{u, U}, y\right) &= |y - z| + uU^2 - lL^2 \\
	&\quad - \left(\frac{1 - L - U}{F(u) - F(l)}\right)z \left(\frac{(1 - 2L)F(u) + (1 - 2U)F(l)}{1 - L - U}\right) \\
	&\quad - \left(\frac{1 - L - U}{F(u) - F(l)}\right)\left(2\log F(-z) - 2G(u)U - 2G(l)L\right) \\
	&\quad - \left(\frac{1 - L - U}{F(u) - F(l)}\right)^2 (H(u) - H(l)), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u, \end{cases} \\
	\mathrm{CRPS}(F_{l, L, \mu, \sigma}^{u, U}, y) &= \sigma\, \mathrm{CRPS}\left(F_{(l - \mu)/\sigma, L}^{(u - \mu)/\sigma, U}, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Generalized truncated/censored logistic distribution:
\begin{align*}
  F_{l, L}^{u, U}(x) &= \begin{cases} 0, & x < l, \\ \frac{1 - L - U}{F(u) - F(l)} F(z) - \frac{1 - L - U}{F(u) - F(l)} F(l) + L, & l \leq x < u, \\ 1, & x \geq u, \end{cases} \\
  F_{l, L, \mu, \sigma}^{u, U}(x) &= F_{(l - \mu)/\sigma, L}^{(u - \mu)/\sigma, U}\left(\tfrac{x - \mu}{\sigma}\right), \\
F(x) &= \frac{1}{1 + \exp(-x)}, \\
G(x) &= xF(x) + \log F(-x), \\
H(x) &= F(x) - xF(x)^2 + (1 - 2F(x))\log F(-x).
\end{align*}
Parameters:

Name | Domain
:-|:-|:-
|`"location"`|$\mu \in \mathbb{R}$
|`"scale"`   |$\sigma > 0$
|`"lower"`   |$l \in \mathbb{R}$, $l < u$
|`"upper"`   |$u \in \mathbb{R}$, $l < u$
|`"lmass"`   |$L \ge 0$, $L + U < 1$
|`"umass"`   |$U \ge 0$, $L + U < 1$

See also: [Logistic distribution](#Logistic)

### Censored logistic distribution (`"clogis"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}\left(F_{l}^{u}, y\right) &= |y - z| +  z + \log \left(\frac{F(-l)F(u)}{F(z)^2}\right) - F(u) + F(l), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u. \end{cases}
\end{align*}
Censored logistic distribution:
\begin{align*}
  F_{l}^{u}(x) = \begin{cases} 0, & x < l, \\ F(x), & l \leq x < u, \\ 1, & x \geq u, \end{cases}
\end{align*}
where all other symbols are as given in [Generalized truncated/censored logistic distribution](#GenLogistic).

Notes:

-	@taillardat2016 give a CRPS formula for a left-censored logistic distribution with boundary 0.


### Truncated logistic distribution (`"tlogis"`)
\begin{align*}
	\mathrm{CRPS}\left(F_{l}^{u}, y\right) &= |y - z| - \frac{zF(u) + zF(l) + 2\log F(-z)}{F(u) - F(l)} - \frac{H(u) - H(l)}{(F(u) - F(l))^2}, \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u. \end{cases}
\end{align*}
Truncated logistic distribution:
\begin{align*}
  F_{l}^{u}(x) = \begin{cases} 0, & x < l, \\ \frac{F(x) - F(l)}{F(u) - F(l)}, & l \leq x < u, \\ 1, & x \geq u, \end{cases}
\end{align*}
where all other symbols are as given in [Generalized truncated/censored logistic distribution](#GenLogistic).

Notes:

- @moeller2013 give a CRPS formula for a left-truncated logistic distribution with boundary 0.

## Generalized truncated/censored normal distribution (`"gtcnorm"`) {#GenNormal}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}\left(F_{l, L}^{u, U}, y\right) &= |y - z| + uU^2 - lL^2 \\
	&\quad + \left(\frac{1 - L - U}{F(u) - F(l)}\right)z\left(2F(z) - \frac{(1 - 2L)F(u) + (1 - 2U)F(l)}{1 - L - U}\right) \\
	&\quad + \left(\frac{1 - L - U}{F(u) - F(l)}\right)\left(2f(z) - 2f(u)U - 2f(l)L\right) \\
	&\quad - \left(\frac{1 - L - U}{F(u) - F(l)}\right)^2 \left(\frac{1}{\sqrt{\pi}}\right) \left(F\left(u\sqrt{2}\right) - F\left(l\sqrt{2}\right)\right), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u, \end{cases} \\
	\mathrm{CRPS}(F_{l, L, \mu, \sigma}^{u, U}, y) &= \sigma\, \mathrm{CRPS}\left(F_{(l - \mu)/\sigma, L}^{(u - \mu)/\sigma, U}, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Generalized truncated/censored normal distribution:
\begin{align*}
  F_{l, L}^{u, U}(x) &= \begin{cases} 0, & x < l, \\ \frac{1 - L - U}{F(u) - F(l)} F(z) - \frac{1 - L - U}{F(u) - F(l)} F(l) + L, & l \leq x < u, \\ 1, & x \geq u, \end{cases} \\
  F_{l, L, \mu, \sigma}^{u, U}(x) &= F_{(l - \mu)/\sigma, L}^{(u - \mu)/\sigma, U}\left(\tfrac{x - \mu}{\sigma}\right), \\
  F(x) &= \int_{-\infty}^x f(t)\, \mathrm{d}t, \\
  f(x) &= \frac{1}{\sqrt{2\pi}}\exp(-x^2/2).
\end{align*}
Parameters:

Name | Domain
:-|:-|:-
|`"location"`|$\mu \in \mathbb{R}$
|`"scale"`   |$\sigma > 0$
|`"lower"`   |$l \in \mathbb{R}$, $l < u$
|`"upper"`   |$u \in \mathbb{R}$, $l < u$
|`"lmass"`   |$L \ge 0$, $L + U < 1$
|`"umass"`   |$U \ge 0$, $L + U < 1$

See also: [Normal distribution](#Normal)

### Censored normal distribution (`"cnorm"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}\left(F_{l}^{u}, y\right) &= |y - z| + uF(-u)^2 - lF(l)^2 \\
	& \quad + z(2F(z) - 1) \\
	& \quad + 2f(z) - 2f(u)F(-u) - 2f(l)F(l) \\
	& \quad - \left(\frac{1}{\sqrt{\pi}}\right) \left(F\left(u\sqrt{2}\right) - F\left(l\sqrt{2}\right)\right), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u. \end{cases}
\end{align*}
Censored normal distribution:
\begin{align*}
  F_{l}^{u}(x) = \begin{cases} 0, & x < l, \\ F(x), & l \leq x < u, \\ 1, & x \geq u, \end{cases}
\end{align*}
where all other symbols are as given in [Generalized truncated/censored normal distribution](#GenNormal).

Notes:

- @thorarinsdottir2010 give a CRPS formula for a left-censored normal distribution with boundary 0.


### Truncated normal distribution (`"tnorm"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}\left(F_{l}^{u}, y\right) &= |y - z| \\
	& \quad + \left(\frac{1}{F(u) - F(l)}\right) z\left(2F(z) - F(u) - F(l)\right) \\
	& \quad + \left(\frac{1}{F(u) - F(l)}\right) 2f(z) \\
	& \quad - \left(\frac{1}{F(u) - F(l)}\right)^2 \left(\frac{1}{\sqrt{\pi}}\right) \left(F\left(u\sqrt{2}\right) - F\left(l\sqrt{2}\right)\right), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u. \end{cases}
\end{align*}
Truncated normal distribution:
\begin{align*}
  F_{l}^{u}(x) = \begin{cases} 0, & x < l, \\ \frac{F(x) - F(l)}{F(u) - F(l)}, & l \leq x < u, \\ 1, & x \geq u, \end{cases}
\end{align*}
where all other symbols are as given in [Generalized truncated/censored normal distribution](#GenNormal).

Notes:

-	@gneiting2006 give a CRPS formula for a left-truncated normal distribution with boundary 0.


## Generalized truncated/censored Student's $t$-distribution (`"gtct"`) {#GenStudent}
CRPS formula:
\begin{align*}
	\mathrm{CRPS}\left(F_{l, L, \nu}^{u, U}, y\right) &= |y - z| + uU^2 - lL^2 \\
	&\quad  + \left(\frac{1 - L - U}{F_\nu(u) - F_\nu(l)}\right) z\left(2F_\nu(z) - \frac{(1 - 2L)F_\nu(u) + (1 - 2U)F_\nu(l)}{1 - L - U}\right) \\
	&\quad - \left(\frac{1 - L - U}{F_\nu(u) - F_\nu(l)}\right)\left(2G_\nu(z) - 2G_\nu(u)U - 2G_\nu(l)L\right) \\
	&\quad - \left(\frac{1 - L - U}{F_\nu(u) - F_\nu(l)}\right)^2 \bar{B}_\nu \left(H_\nu(u) - H_\nu(l)\right), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u, \end{cases} \\
	\mathrm{CRPS}(F_{l, L, \nu, \mu, \sigma}^{u, U}, y) &= \sigma\, \mathrm{CRPS}\left(F_{(l - \mu)/\sigma, L, \nu}^{(u - \mu)/\sigma, U}, \tfrac{y - \mu}{\sigma} \right).
\end{align*}
Generalized truncated/censored Student's $t$-distribution:
\begin{align*}
  F_{l, L, \nu}^{u, U}(x) &= \begin{cases} 0, & x < l, \\ \frac{1 - L - U}{F(u) - F(l)} F(z) - \frac{1 - L - U}{F(u) - F(l)} F(l) + L, & l \leq x < u, \\ 1, & x \geq u, \end{cases} \\
  F_{l, L, \nu, \mu, \sigma}^{u, U}(x) &= F_{\tfrac{l - \mu}{\sigma}, L, \nu}^{\tfrac{u - \mu}{\sigma}, U}\left(\tfrac{x - \mu}{\sigma}\right), \\
  f_\nu(x) &= \frac{1}{\sqrt{\nu}B\left(\tfrac{1}{2}, \tfrac{\nu}{2}\right)}\left(1 + \frac{x^2}{\nu}\right)^{-(\nu + 1)/2}, \\
  F_\nu(x) &= \frac{1}{2} + \frac{x\ {}_2F_1\left(\tfrac{1}{2},\tfrac{\nu+1}{2};\tfrac{3}{2};-\tfrac{x^2}{\nu}\right)}{\sqrt{\nu} B\left(\tfrac{1}{2},\tfrac{\nu}{2}\right)}, \\
  G_\nu(x) &= -\left(\frac{\nu + x^2}{\nu - 1}\right) f_\nu(x), \\
  H_\nu(x) &= \frac{1}{2} + \frac{1}{2}\, \mathrm{sgn}(x)\, I \left(\tfrac{x^2}{\nu + x^2}; \tfrac{1}{2}, \nu - \tfrac{1}{2}\right), \\
  \bar{B}_\nu &= \left(\frac{2\sqrt{\nu}}{\nu - 1}\right)\frac{B\left(\tfrac{1}{2}, \nu - \tfrac{1}{2}\right)}{B\left(\tfrac{1}{2}, \tfrac{\nu}{2}\right)^2}.
\end{align*}
Parameters:

Name | Domain
:-|:-
`"df"` | $\nu > 0$ (for $\nu \le 1$ the CRPS is undefined)
`"location"`|$\mu \in \mathbb{R}$
`"scale"`   |$\sigma > 0$
`"lower"`   |$l \in \mathbb{R}$, $l < u$
`"upper"`   |$u \in \mathbb{R}$, $l < u$
`"lmass"`   |$L \ge 0$, $L + U < 1$
`"umass"`   |$U \ge 0$, $L + U < 1$

Mathematical functions:

Symbol | Name
:-|:-
${}_2F_1$ | hypergeometric function
$B$ | beta function
$I$ | regularized incomplete beta function
$\mathrm{sgn}$ | sign function

See also: [Student's $t$-distribution](#Student)

### Censored $t$-distribution (`"ct"`)
CRPS formula:
	\begin{align*}
	\mathrm{CRPS}\left(F_{l, \nu}^{u}, y\right) &= |y - z| + uF_\nu(-u)^2 - lF_\nu(l)^2 \\
	& \quad + z(2F_\nu(z) - 1) \\
	& \quad - 2G_\nu(z) + 2G_\nu(u)F_\nu(-u) + 2G_\nu(l)F_\nu(l) \\
	& \quad - \bar{B}_\nu \left(H_\nu(u) - H_\nu(l) \right), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u. \end{cases}
\end{align*}
Censored Student's $t$-distribution:
\begin{align*}
  F_{l, \nu}^{u}(x) &= \begin{cases} 0, & x < l, \\ F_\nu(x), & l \leq x < u, \\ 1, & x \geq u, \end{cases}
\end{align*}
where all other symbols are as given in [Generalized truncated/censored Student's $t$-distribution](#GenStudent).


### Truncated $t$-distribution (`"tt"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}\left(F_{l, \nu}^{u}, y\right) &= |y - z| \\
	& \quad + \left(\frac{1}{F_\nu(u) - F_\nu(l)}\right) z\left(2F_\nu(z) - F_\nu(u) - F_\nu(l)\right) \\
	& \quad - \left(\frac{1}{F_\nu(u) - F_\nu(l)}\right) 2G_\nu(z) \\
	& \quad - \left(\frac{1}{F_\nu(u) - F_\nu(l)}\right)^2 \bar{B}_\nu \left(H_\nu(u) - H_\nu(l)\right), \\
	\text{where}\quad z&= \begin{cases} l, & y < l, \\ y, & l \le y < u, \\ u, & y \ge u. \end{cases}
\end{align*}
Truncated Student's $t$-distribution:
\begin{align*}
  F_{l, \nu}^{u}(x) &= \begin{cases} 0, & x < l, \\ \frac{F_\nu(x) - F_\nu(l)}{F_\nu(u) - F_\nu(l)}, & l \leq x < u, \\ 1, & x \geq u, \end{cases}
\end{align*}
where all other symbols are as given in [Generalized truncated/censored Student's $t$-distribution](#GenStudent).


# Distributions for discrete variables


## Negative binomial distribution (`"nbinom"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_{n, p}, y) &= y\left(2F_{n, p}(y) - 1\right) \\
	&\quad - \frac{n(1-p)}{p^2}\left(p\left(2F_{n+1,p}(y-1) - 1\right) + {\ }_2F_1\left(n+1, \tfrac{1}{2}; 2; -\tfrac{4(1-p)}{p^2}\right)\right)
\end{align*}
Negative binomial distribution:
\begin{align*}
  F_{n, p}(x) &= \begin{cases} I\left(p; n, \lfloor x+1\rfloor\right), & x \geq 0, \\ 0, & x < 0, \end{cases} \\
  f_{n, p}(x) &= \begin{cases}\frac{\Gamma(x+n)}{\Gamma(n) x!} p^n (1-p)^x, & x = 0, 1, 2, \ldots, \\ 0, & \text{otherwise}. \end{cases}
\end{align*}
Parameters:

Name | Domain
:-|:-
`"size"` | $n > 0$
`"prob"` | $p \in (0, 1]$

Mathematical functions:

Symbol | Name
:-|:-
$\lfloor\cdot\rfloor$ | floor function
${}_2F_1$ | hypergeometric function
$I$ | regularized incomplete beta function

Notes:

-	@wei2014 is the original source of this CRPS formula.


## Poisson distribution (`"pois"`)
CRPS formula:
\begin{align*}
	\mathrm{CRPS}(F_\lambda, y) &= (y - \lambda) \left(2F_\lambda(y) - 1\right) + 2\lambda f_\lambda\left(\lfloor y\rfloor\right) - \lambda \exp(-2\lambda)\left(I_0(2\lambda) + I_1(2\lambda)\right)
\end{align*}
Poisson distribution:
\begin{align*}
  F_\lambda(x) &= \begin{cases} \frac{\Gamma_u(\lfloor x+1\rfloor, \lambda)}{\Gamma(\lfloor x+1 \rfloor)}, & x \geq 0,\\ 0, & x < 0, \end{cases}\\
  f_\lambda(x) &= \begin{cases}\frac{\lambda^x}{x!}e^{-\lambda}, & x = 0, 1, 2, \ldots, \\ 0, & \text{otherwise}, \end{cases}
\end{align*}
Parameter:

Name | Domain
:-|:-
`"lambda"` | $\lambda > 0$

Mathematical functions:

Symbol | Name
:-|:-
$\lfloor \cdot \rfloor$ | floor function
$\Gamma$ | gamma function
$\Gamma_u$ | upper incomplete gamma function
$I_m$ | modified Bessel function of the first kind

Notes:

-	@wei2014 is the original source of this CRPS formula.


# References