-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
88 lines (68 loc) · 2.88 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
## Model evaluation with the integrated quadratic distance (IQD)
### Authors: Thordis L. Thorarinsdottir ([email protected]) and Marion Haugen
The 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)
```