Skip to contents

Given a forecast object having at least one paired quantiles, assume that the forecasted values are distributed according to a normal distribution with the same quantile pair. The logarithmic score is then calculated following this normality assumption.

Usage

log_score_approx_normal(fcst, obs, summarize = TRUE, quantpair.choice = 1)

Arguments

fcst

A forecast object (see output of create_forecast()).

obs

An observations data frame.

summarize

A boolean, defaults to TRUE. If TRUE, a single number will be returned as the score for the forecast. If FALSE, a data frame with columns named time, val_obs, and score will be returned, containing the scores for each individual time point. This can be used by plotting functions to colour-code observations, for example.

quantpair.choice

(Optional) Integer. If several quantiles pairs are present in the forecast object, determine which one to use to calculate the mean and standard deviation of the implied normal distribution.

Value

If summarize is FALSE, a data frame containing times, observations, scores, quantiles used, and implied mean and standard deviation of the normal distribution. Otherwise, returns the mean of all scores at every times.

Examples

fcst <- create_forecast(
dplyr::tibble(
  time    = 1:3,
  val_q5  = seq(1,8, length.out = 3),
  val_q10 = 9:11,
  val_q25 = 12:14,
  val_q50 = 100:102,
  val_q75 = 200:202,
  val_q90 = 203:205,
  val_q95 = seq(210,220, length.out = 3)
))

obs <- data.frame(time=1:3, val_obs=c(105,101,300))

s = log_score_approx_normal(fcst, obs,
                            summarize = F,
                            quantpair.choice = 1)
print(s)
#>   time val_obs     score val_q5 val_q95 implied_normal_mean implied_normal_sd
#> 1    1     105 -5.070505    1.0     210              105.50          63.53149
#> 2    2     101 -5.086975    4.5     215              109.75          63.98746
#> 3    3     300 -9.249953    8.0     220              114.00          64.44342

s = log_score_approx_normal(fcst, obs,
                            summarize = F,
                            quantpair.choice = 2)
print(s)
#>   time val_obs     score val_q10 val_q90 implied_normal_mean implied_normal_sd
#> 1    1     105 -5.245665       9     203                 106           75.6895
#> 2    2     101 -5.248720      10     204                 107           75.6895
#> 3    3     300 -8.462949      11     205                 108           75.6895

s = log_score_approx_normal(fcst, obs,
                            summarize = TRUE,
                            quantpair.choice = 3)
print(s)
#> [1] -6.172684