d <- 10 # number of dimensions
m <- 50 # number of samples from multivariate forecast distribution
# parameters for multivariate normal example
mu0 <- rep(0, d)
mu <- rep(1, d)
S0 <- S <- diag(d)
S0[S0==0] <- 0.2
S[S==0] <- 0.1
# generate samples from multivariate normal distributions
obs <- drop(mu0 + rnorm(d) %*% chol(S0))
fc_sample <- replicate(m, drop(mu + rnorm(d) %*% chol(S)))
# compute Energy Score
es_sample(y = obs, dat = fc_sample)
# in the univariate case, Energy Score and CRPS are the same
# illustration: Evaluate forecast sample for the first variable
es_sample(y = obs[1], dat = fc_sample[1, , drop = FALSE])
crps_sample(y = obs[1], dat = fc_sample[1, ])
# illustration of observation weights for Energy Score
# example: equal weights for first half of draws; zero weights for other draws
w <- rep(c(1, 0), each = .5*m)/(.5*m)
es_sample(y = obs, dat = fc_sample, w = w)
# weighting matrix for variogram score
# note that, unlike for w, weights in w_vs refer to dimensions
# (rows of dat) rather than draws (cols of dat)
w_vs <- outer(1:d, 1:d, function(x, y) .5^abs(x-y))
vs_sample(y = obs, dat = fc_sample)
vs_sample(y = obs, dat = fc_sample, w_vs = w_vs)
vs_sample(y = obs, dat = fc_sample, w_vs = w_vs, p = 1)
Run the code above in your browser using DataLab