https://github.com/norskregnesentral/iqd
Functions to calculate the integrated qudratic distance (IQD)
https://github.com/norskregnesentral/iqd
Last synced: 25 days ago
JSON representation
Functions to calculate the integrated qudratic distance (IQD)
- Host: GitHub
- URL: https://github.com/norskregnesentral/iqd
- Owner: NorskRegnesentral
- Created: 2020-02-19T14:48:08.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2024-04-16T09:42:36.000Z (over 1 year ago)
- Last Synced: 2025-01-10T16:46:03.470Z (9 months ago)
- Language: R
- Size: 46.9 KB
- Stars: 1
- Watchers: 5
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.Rmd
Awesome Lists containing this project
README
## Model evaluation with the integrated quadratic distance (IQD)
### Authors: Thordis L. Thorarinsdottir (thordis@nr.no) and Marion HaugenThe integrated quadratic distance (IQD) measures the similarity between two distributions by the integral over the squared difference between the two distribution functions. For background information on the IQD and its properties, see
T L Thorarinsdottir, T Gneiting and N Gissibl (2013): Using proper divergence functions to evaluate climate models. SIAM/ASA Journal on Uncertainty Quantification, 1(1): 522-534.
For examples of the use of the IQD, see the example below or
Q Yuan, T L Thorarinsdottir, S Beldring, W K Wong, S Huang and C-Y Xu (2019): New approach for bias correction and stochastic downscaling of future projections for daily mean temperatures to a high-resolution grid. Journal of Applied Meteorology and Climatology, 58: 2617-2632.
Three functions for calculating the IQD between two empirical distribution functions (ECDFs) are available:
* **IQD_crps(X,Y)** uses the sample version of the continuous ranked probability score (CRPS), as implemented in the R package scoringRules, where **X** and **Y** are vectors of values corresponding to the two ECDFs.
* **IQD_integrate(X,Y)** uses direct numerical integration of the IQD formula, where **X** and **Y** are vectors corresponding to the two ECDFs.
* **wIQD_integrate(X,Y,wFct)** uses direct numerical integration of the IQD formula to calculate a weighted version of the IQD for the weight function **wFct**, where **X** and **Y** are vectors corresponding to the two ECDFs (see Yuan et al. (2019) for examples of weight functions).
The following are needed to use these functions:
```{r message=FALSE}
library(scoringRules)
source("IQDfunctions.R")
```### Example of the use of the IQD
Example 1:
```{r}
set.seed(17)
z <- seq(from=-6, to=7, by=0.001)
x1 <- rnorm(81, mean=0, sd=2)
x2 <- rnorm(81, mean=1, sd=2)
y1 <- ecdf(x1)
y2 <- ecdf(x2)
par(mex=0.75, mar=c(5,5,1,1))
cols <- c("blueviolet", "aquamarine3")
plot( z,
y1(z),
type="l",
col=cols[1],
lwd=2,
ylab="Probability",
xlab="Sample value")
polygon( c(z, rev(z), z[1]),
c(y2(z), rev(y1(z)), y1(z)[1]),
col="gray90",
border=NA )
lines( z, y2(z), col=cols[2], lwd=2 )
lines( z, y1(z), col=cols[1], lwd=2 )
```Calculate the IQD
```{r}
PrintIQD(x1,x2)
```Example 2:
```{r}
x3 <- rnorm(81, mean=0, sd=1)
y2 <- ecdf(x3)
plot( z,
y1(z),
type="l",
col=cols[1],
lwd=2,
ylab="Probability",
xlab="Sample value" )
polygon( c(z[1:6001], rev(z[1:6001]), z[1]),
c(y2(z)[1:6001], rev(y1(z)[1:6001]),
y1(z)[1]), col="gray90", border="NA" )
polygon( c(z[6001:13001], rev(z[6001:13001]), z[6001]),
c(y1(z)[6001:13001], rev(y2(z)[6001:13001]), y2(z)[6001]),
col="gray90",
border="NA" )
lines( z, y2(z), col=cols[2], lwd=2 )
lines( z, y1(z), col=cols[1], lwd=2 )
``````{r}
PrintIQD(x1,x3)
```