Skip to contents

Performance of (population) historical forecast

Usage

add_historical_pred(
  test,
  train,
  max_score,
  discrete = TRUE,
  add_uniform = TRUE,
  include_samples = FALSE,
  n_samples = NULL
)

Arguments

test

Testing dataframe. The only requirements is that it contains a column "Score".

train

Training dataframe. The only requirements is that it contains a column "Score".

max_score

Maximum value that the score can take

discrete

Whether to estimate a discrete or continuous historical forecast

add_uniform

Whether to include samples from uniform distribution when computing a discrete historical forecast. This ensures that all states are visited.

include_samples

Whether to return samples from the historical forecast in the output

n_samples

If include_samples=TRUE, how many samples to return. When NULL, the function return the training set.

Value

Dataframe test appended by the columns "lpd", "RPS" (or CRPS if discrete=FALSE) and optionally "Samples"

Details

The continuous historical forecast is calculated by considering the training set as samples from the predictive distribution.

Examples

max_score <- 100
train <- data.frame(Score = rbinom(1e2, max_score, 0.2))
test <- data.frame(Score = rbinom(1e2, max_score, 0.5))
add_historical_pred(test, train, max_score)
#>     Score       lpd        RPS
#> 1      52 -5.303305 0.14980075
#> 2      42 -5.303305 0.10303458
#> 3      50 -5.303305 0.13965149
#> 4      40 -5.303305 0.09487537
#> 5      53 -5.303305 0.15502463
#> 6      55 -5.303305 0.16577090
#> 7      49 -5.303305 0.13472612
#> 8      45 -5.303305 0.11601965
#> 9      55 -5.303305 0.16577090
#> 10     45 -5.303305 0.11601965
#> 11     45 -5.303305 0.11601965
#> 12     50 -5.303305 0.13965149
#> 13     48 -5.303305 0.12990025
#> 14     54 -5.303305 0.16034801
#> 15     41 -5.303305 0.09890523
#> 16     48 -5.303305 0.12990025
#> 17     46 -5.303305 0.12054702
#> 18     39 -5.303305 0.09094503
#> 19     46 -5.303305 0.12054702
#> 20     46 -5.303305 0.12054702
#> 21     53 -5.303305 0.15502463
#> 22     47 -5.303305 0.12517388
#> 23     46 -5.303305 0.12054702
#> 24     53 -5.303305 0.15502463
#> 25     52 -5.303305 0.14980075
#> 26     55 -5.303305 0.16577090
#> 27     50 -5.303305 0.13965149
#> 28     69 -5.303305 0.25213906
#> 29     50 -5.303305 0.13965149
#> 30     43 -5.303305 0.10726343
#> 31     54 -5.303305 0.16034801
#> 32     53 -5.303305 0.15502463
#> 33     44 -5.303305 0.11159179
#> 34     53 -5.303305 0.15502463
#> 35     45 -5.303305 0.11601965
#> 36     42 -5.303305 0.10303458
#> 37     44 -5.303305 0.11159179
#> 38     54 -5.303305 0.16034801
#> 39     58 -5.303305 0.18263657
#> 40     45 -5.303305 0.11601965
#> 41     53 -5.303305 0.15502463
#> 42     38 -5.303305 0.08711418
#> 43     52 -5.303305 0.14980075
#> 44     57 -5.303305 0.17691518
#> 45     52 -5.303305 0.14980075
#> 46     53 -5.303305 0.15502463
#> 47     53 -5.303305 0.15502463
#> 48     59 -5.303305 0.18845746
#> 49     45 -5.303305 0.11601965
#> 50     50 -5.303305 0.13965149
#> 51     53 -5.303305 0.15502463
#> 52     51 -5.303305 0.14467637
#> 53     47 -5.303305 0.12517388
#> 54     41 -5.303305 0.09890523
#> 55     50 -5.303305 0.13965149
#> 56     47 -5.303305 0.12517388
#> 57     50 -5.303305 0.13965149
#> 58     47 -5.303305 0.12517388
#> 59     45 -5.303305 0.11601965
#> 60     41 -5.303305 0.09890523
#> 61     54 -5.303305 0.16034801
#> 62     49 -5.303305 0.13472612
#> 63     47 -5.303305 0.12517388
#> 64     49 -5.303305 0.13472612
#> 65     60 -5.303305 0.19437786
#> 66     45 -5.303305 0.11601965
#> 67     45 -5.303305 0.11601965
#> 68     44 -5.303305 0.11159179
#> 69     40 -5.303305 0.09487537
#> 70     50 -5.303305 0.13965149
#> 71     41 -5.303305 0.09890523
#> 72     48 -5.303305 0.12990025
#> 73     48 -5.303305 0.12990025
#> 74     45 -5.303305 0.11601965
#> 75     53 -5.303305 0.15502463
#> 76     42 -5.303305 0.10303458
#> 77     48 -5.303305 0.12990025
#> 78     46 -5.303305 0.12054702
#> 79     60 -5.303305 0.19437786
#> 80     51 -5.303305 0.14467637
#> 81     55 -5.303305 0.16577090
#> 82     49 -5.303305 0.13472612
#> 83     53 -5.303305 0.15502463
#> 84     52 -5.303305 0.14980075
#> 85     61 -5.303305 0.20039776
#> 86     53 -5.303305 0.15502463
#> 87     48 -5.303305 0.12990025
#> 88     47 -5.303305 0.12517388
#> 89     55 -5.303305 0.16577090
#> 90     35 -5.303305 0.07621866
#> 91     56 -5.303305 0.17129328
#> 92     42 -5.303305 0.10303458
#> 93     58 -5.303305 0.18263657
#> 94     44 -5.303305 0.11159179
#> 95     53 -5.303305 0.15502463
#> 96     34 -5.303305 0.07278582
#> 97     50 -5.303305 0.13965149
#> 98     49 -5.303305 0.13472612
#> 99     49 -5.303305 0.13472612
#> 100    52 -5.303305 0.14980075