Skip to contents

A generic wrapper around enw_posterior() with opinionated defaults to extract the posterior prediction for the nowcast ("pp_inf_obs" from the stan code). The functionality of this function can be used directly on the output of epinowcast() using the supplied summary.epinowcast() method.

Usage

enw_nowcast_summary(
  fit,
  obs,
  max_delay = NULL,
  timestep = "day",
  probs = c(0.05, 0.2, 0.35, 0.5, 0.65, 0.8, 0.95)
)

Arguments

fit

A cmdstanr fit object.

obs

An observation data.frame containing reference_date columns of the same length as the number of rows in the posterior and the most up to date observation for each date. This is used to align the posterior with the observations. The easiest source of this data is the output of latest output of enw_preprocess_data() or enw_latest_data().

max_delay

Maximum delay to which nowcasts should be summarised. Must be equal (default) or larger than the modelled maximum delay. If it is larger, then nowcasts for unmodelled dates are added by assuming that case counts beyond the modelled maximum delay are fully observed.

timestep

The timestep to used. This can be a string ("day", "week", "month") or a numeric whole number representing the number of days.

probs

A vector of numeric probabilities to produce quantile summaries for. By default these are the 5%, 20%, 80%, and 95% quantiles which are also the minimum set required for plotting functions to work.

Value

A data.frame summarising the model posterior nowcast prediction. This uses observed data where available and the posterior prediction where not.

Examples

fit <- enw_example("nowcast")
enw_nowcast_summary(
  fit$fit[[1]],
  fit$latest[[1]],
  fit$max_delay
  )
#>     reference_date report_date .group max_confirm location age_group confirm
#>             <IDat>      <IDat>  <num>       <int>   <fctr>    <fctr>   <int>
#>  1:     2021-08-03  2021-08-22      1         149       DE       00+     149
#>  2:     2021-08-04  2021-08-22      1         166       DE       00+     166
#>  3:     2021-08-05  2021-08-22      1         133       DE       00+     133
#>  4:     2021-08-06  2021-08-22      1         137       DE       00+     137
#>  5:     2021-08-07  2021-08-22      1         139       DE       00+     139
#>  6:     2021-08-08  2021-08-22      1          97       DE       00+      97
#>  7:     2021-08-09  2021-08-22      1          58       DE       00+      58
#>  8:     2021-08-10  2021-08-22      1         175       DE       00+     175
#>  9:     2021-08-11  2021-08-22      1         233       DE       00+     233
#> 10:     2021-08-12  2021-08-22      1         237       DE       00+     237
#> 11:     2021-08-13  2021-08-22      1         204       DE       00+     204
#> 12:     2021-08-14  2021-08-22      1         189       DE       00+     189
#> 13:     2021-08-15  2021-08-22      1         125       DE       00+     125
#> 14:     2021-08-16  2021-08-22      1          98       DE       00+      98
#> 15:     2021-08-17  2021-08-22      1         242       DE       00+     242
#> 16:     2021-08-18  2021-08-22      1         223       DE       00+     223
#> 17:     2021-08-19  2021-08-22      1         202       DE       00+     202
#> 18:     2021-08-20  2021-08-22      1         171       DE       00+     171
#> 19:     2021-08-21  2021-08-22      1         112       DE       00+     112
#> 20:     2021-08-22  2021-08-22      1          45       DE       00+      45
#>     reference_date report_date .group max_confirm location age_group confirm
#>     cum_prop_reported delay prop_reported    mean median         sd     mad
#>                 <num> <num>         <num>   <num>  <num>      <num>   <num>
#>  1:                 1    19   0.000000000 149.000    149   0.000000  0.0000
#>  2:                 1    18   0.000000000 167.426    167   1.316912  1.4826
#>  3:                 1    17   0.000000000 135.812    136   1.867121  1.4826
#>  4:                 1    16   0.000000000 141.255    141   2.341679  2.2239
#>  5:                 1    15   0.007194245 145.884    146   3.085460  2.9652
#>  6:                 1    14   0.000000000 103.681    103   3.072243  2.9652
#>  7:                 1    13   0.000000000  62.762     62   2.461588  1.4826
#>  8:                 1    12   0.000000000 185.138    185   3.827742  4.4478
#>  9:                 1    11   0.000000000 255.903    255   6.410514  5.9304
#> 10:                 1    10   0.004219409 267.488    267   7.975931  7.4130
#> 11:                 1     9   0.000000000 236.164    236   8.459235  8.8956
#> 12:                 1     8   0.015873016 230.867    230  10.092332 10.3782
#> 13:                 1     7   0.040000000 165.026    165  10.254095 10.3782
#> 14:                 1     6   0.010204082 129.307    128   8.532969  8.8956
#> 15:                 1     5   0.012396694 292.749    292  11.792076 11.8608
#> 16:                 1     4   0.017937220 293.296    292  15.992941 14.8260
#> 17:                 1     3   0.019801980 291.404    290  19.436887 19.2738
#> 18:                 1     2   0.070175439 295.703    292  28.861250 28.1694
#> 19:                 1     1   0.383928571 309.456    304  51.295236 47.4432
#> 20:                 1     0   1.000000000 381.243    371 103.890978 96.3690
#>     cum_prop_reported delay prop_reported    mean median         sd     mad
#>         q5   q20   q35   q50   q65   q80    q95      rhat  ess_bulk  ess_tail
#>      <num> <num> <num> <num> <num> <num>  <num>     <num>     <num>     <num>
#>  1: 149.00 149.0   149   149   149 149.0 149.00        NA        NA        NA
#>  2: 166.00 166.0   167   167   168 168.0 170.00 0.9988498  997.2790  946.6047
#>  3: 133.00 134.0   135   136   136 137.0 139.00 0.9997035 1015.7372 1017.4859
#>  4: 138.00 139.0   140   141   142 143.0 145.00 1.0017705  901.5890  958.7197
#>  5: 141.00 143.0   144   146   147 148.0 151.05 0.9984520 1097.0842 1044.2543
#>  6:  99.00 101.0   102   103   105 106.0 109.00 0.9997410 1034.2365  913.6061
#>  7:  59.00  61.0    62    62    63  65.0  67.00 0.9987681 1012.1885  904.7496
#>  8: 180.00 182.0   183   185   186 188.0 192.00 1.0064762  885.6025  907.2186
#>  9: 246.00 250.0   253   255   258 261.0 267.00 1.0014583  933.4472  918.6322
#> 10: 255.00 261.0   264   267   270 274.0 281.00 1.0052639 1044.4533 1055.2781
#> 11: 223.00 229.0   232   236   239 243.0 252.00 1.0041063 1039.8102  897.5389
#> 12: 216.00 222.0   226   230   234 239.0 249.00 1.0026046 1018.9795  919.8161
#> 13: 149.95 156.8   160   165   168 173.0 183.00 0.9991933 1090.1636  782.0808
#> 14: 116.00 122.0   126   128   132 136.0 144.05 1.0000500 1023.7823  888.2873
#> 15: 275.00 283.0   288   292   297 303.0 313.00 0.9993709 1145.8224  968.8335
#> 16: 270.00 280.0   286   292   298 306.0 320.00 1.0008511 1056.0595  914.9342
#> 17: 263.00 274.0   284   290   298 306.0 325.00 0.9992936 1248.9469  968.8798
#> 18: 254.95 271.0   282   292   304 319.0 348.00 1.0008356 1412.5892 1036.8252
#> 19: 237.00 266.8   285   304   323 349.0 406.00 0.9988372 1195.0907  985.8485
#> 20: 240.85 293.8   332   371   405 459.2 569.05 0.9993392 1349.1168 1029.2555
#>         q5   q20   q35   q50   q65   q80    q95      rhat  ess_bulk  ess_tail