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      43 -5.303305 0.10812257
#> 2      60 -5.303305 0.19523700
#> 3      44 -5.303305 0.11245093
#> 4      49 -5.303305 0.13558526
#> 5      56 -5.303305 0.17215242
#> 6      41 -5.303305 0.09976436
#> 7      53 -5.303305 0.15588377
#> 8      45 -5.303305 0.11687879
#> 9      47 -5.303305 0.12603302
#> 10     54 -5.303305 0.16120715
#> 11     48 -5.303305 0.13075939
#> 12     52 -5.303305 0.15065988
#> 13     50 -5.303305 0.14051063
#> 14     50 -5.303305 0.14051063
#> 15     50 -5.303305 0.14051063
#> 16     55 -5.303305 0.16663003
#> 17     57 -5.303305 0.17777431
#> 18     53 -5.303305 0.15588377
#> 19     45 -5.303305 0.11687879
#> 20     48 -5.303305 0.13075939
#> 21     58 -5.303305 0.18349571
#> 22     56 -5.303305 0.17215242
#> 23     46 -5.303305 0.12140615
#> 24     43 -5.303305 0.10812257
#> 25     57 -5.303305 0.17777431
#> 26     40 -5.303305 0.09573451
#> 27     53 -5.303305 0.15588377
#> 28     53 -5.303305 0.15588377
#> 29     49 -5.303305 0.13558526
#> 30     53 -5.303305 0.15588377
#> 31     45 -5.303305 0.11687879
#> 32     50 -5.303305 0.14051063
#> 33     56 -5.303305 0.17215242
#> 34     50 -5.303305 0.14051063
#> 35     46 -5.303305 0.12140615
#> 36     58 -5.303305 0.18349571
#> 37     50 -5.303305 0.14051063
#> 38     51 -5.303305 0.14553551
#> 39     57 -5.303305 0.17777431
#> 40     51 -5.303305 0.14553551
#> 41     45 -5.303305 0.11687879
#> 42     47 -5.303305 0.12603302
#> 43     43 -5.303305 0.10812257
#> 44     61 -5.303305 0.20125690
#> 45     53 -5.303305 0.15588377
#> 46     43 -5.303305 0.10812257
#> 47     50 -5.303305 0.14051063
#> 48     42 -5.303305 0.10389372
#> 49     45 -5.303305 0.11687879
#> 50     54 -5.303305 0.16120715
#> 51     47 -5.303305 0.12603302
#> 52     47 -5.303305 0.12603302
#> 53     53 -5.303305 0.15588377
#> 54     46 -5.303305 0.12140615
#> 55     45 -5.303305 0.11687879
#> 56     58 -5.303305 0.18349571
#> 57     55 -5.303305 0.16663003
#> 58     46 -5.303305 0.12140615
#> 59     48 -5.303305 0.13075939
#> 60     55 -5.303305 0.16663003
#> 61     50 -5.303305 0.14051063
#> 62     44 -5.303305 0.11245093
#> 63     50 -5.303305 0.14051063
#> 64     42 -5.303305 0.10389372
#> 65     48 -5.303305 0.13075939
#> 66     48 -5.303305 0.13075939
#> 67     42 -5.303305 0.10389372
#> 68     53 -5.303305 0.15588377
#> 69     57 -5.303305 0.17777431
#> 70     54 -5.303305 0.16120715
#> 71     45 -5.303305 0.11687879
#> 72     45 -5.303305 0.11687879
#> 73     46 -5.303305 0.12140615
#> 74     51 -5.303305 0.14553551
#> 75     47 -5.303305 0.12603302
#> 76     47 -5.303305 0.12603302
#> 77     47 -5.303305 0.12603302
#> 78     56 -5.303305 0.17215242
#> 79     51 -5.303305 0.14553551
#> 80     55 -5.303305 0.16663003
#> 81     45 -5.303305 0.11687879
#> 82     48 -5.303305 0.13075939
#> 83     61 -5.303305 0.20125690
#> 84     53 -5.303305 0.15588377
#> 85     53 -5.303305 0.15588377
#> 86     56 -5.303305 0.17215242
#> 87     45 -5.303305 0.11687879
#> 88     41 -5.303305 0.09976436
#> 89     50 -5.303305 0.14051063
#> 90     43 -5.303305 0.10812257
#> 91     47 -5.303305 0.12603302
#> 92     55 -5.303305 0.16663003
#> 93     53 -5.303305 0.15588377
#> 94     37 -5.303305 0.08424197
#> 95     47 -5.303305 0.12603302
#> 96     46 -5.303305 0.12140615
#> 97     49 -5.303305 0.13558526
#> 98     48 -5.303305 0.13075939
#> 99     50 -5.303305 0.14051063
#> 100    56 -5.303305 0.17215242