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
containingreference_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 ofenw_preprocess_data()
orenw_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.
See also
Functions used for postprocessing of model fits
enw_add_latest_obs_to_nowcast()
,
enw_nowcast_samples()
,
enw_posterior()
,
enw_pp_summary()
,
enw_quantiles_to_long()
,
enw_summarise_samples()
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.318432 1.4826
#> 3: 1 17 0.000000000 135.789 136 1.854162 1.4826
#> 4: 1 16 0.000000000 141.288 141 2.378805 1.4826
#> 5: 1 15 0.007194245 146.019 146 3.079630 2.9652
#> 6: 1 14 0.000000000 103.853 104 2.969884 2.9652
#> 7: 1 13 0.000000000 62.766 63 2.432110 2.9652
#> 8: 1 12 0.000000000 185.035 185 3.847932 4.4478
#> 9: 1 11 0.000000000 256.031 256 6.498790 5.9304
#> 10: 1 10 0.004219409 267.692 267 7.713536 7.4130
#> 11: 1 9 0.000000000 236.057 235 8.508004 7.4130
#> 12: 1 8 0.015873016 231.407 231 10.083304 10.3782
#> 13: 1 7 0.040000000 164.876 164 9.848127 10.3782
#> 14: 1 6 0.010204082 128.858 128 8.134495 7.4130
#> 15: 1 5 0.012396694 293.309 292 11.938427 11.8608
#> 16: 1 4 0.017937220 293.042 292 15.799489 14.8260
#> 17: 1 3 0.019801980 291.478 290 21.108128 19.2738
#> 18: 1 2 0.070175439 293.178 291 29.440398 28.1694
#> 19: 1 1 0.383928571 308.518 302 51.151522 46.7019
#> 20: 1 0 1.000000000 375.644 363 103.424281 91.1799
#> 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 149.00 149 149.00 149 149.00 NA NA NA
#> 2: 166.00 166 167.00 167 168.00 168 170.00 0.9997778 1003.5643 828.2026
#> 3: 133.00 134 135.00 136 136.00 137 139.00 1.0005878 991.0805 916.0962
#> 4: 138.00 139 140.00 141 142.00 143 146.00 1.0056729 1041.2029 872.9772
#> 5: 141.00 143 145.00 146 147.00 148 152.00 1.0001025 991.1639 885.1056
#> 6: 100.00 101 102.65 104 105.00 106 109.00 0.9991163 982.3833 917.3468
#> 7: 59.00 61 62.00 63 63.00 65 67.00 1.0009067 911.2098 793.6687
#> 8: 179.00 182 183.00 185 186.00 188 192.00 1.0002531 1004.7790 972.0392
#> 9: 246.00 251 253.00 256 258.00 261 268.00 0.9997137 1025.3311 936.5679
#> 10: 256.00 261 265.00 267 270.00 274 282.00 1.0004951 1040.1417 1008.8448
#> 11: 223.00 229 233.00 235 239.00 243 251.00 0.9985724 1201.4893 863.9704
#> 12: 216.00 222 227.00 231 234.00 240 250.00 1.0035756 751.4194 655.0188
#> 13: 150.00 157 160.00 164 168.00 173 181.00 1.0025186 927.9122 920.9413
#> 14: 117.00 122 125.00 128 131.00 135 143.00 1.0010009 1080.4014 964.2083
#> 15: 276.00 283 288.00 292 297.00 303 315.00 1.0002316 1159.2978 984.6276
#> 16: 268.00 280 286.00 292 299.00 306 320.00 1.0047058 1087.6045 957.9921
#> 17: 260.00 274 282.00 290 298.35 308 330.00 1.0002334 1129.6391 914.6275
#> 18: 250.00 269 280.00 291 301.00 316 344.00 0.9993186 1126.3831 903.3288
#> 19: 239.00 267 286.00 302 322.00 343 399.10 0.9992178 1328.2832 998.7573
#> 20: 233.95 292 327.00 363 397.00 447 565.05 0.9991666 1554.0485 999.3402
#> q5 q20 q35 q50 q65 q80 q95 rhat ess_bulk ess_tail