This function summarises posterior samples for arbitrary strata. It optionally holds out the observed data (variables that are not ".draw", ".iteration", ".sample", ".chain" ) joins this to the summarised posterior.
Arguments
- samples
A
data.frame
of posterior samples with at least a numeric sample variable.- 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.
- by
A character vector of variables to summarise by. Defaults to
c("reference_date", ".group")
.- link_with_obs
Logical, should the observed data be linked to the posterior summary? This is useful for plotting the posterior against the observed data. Defaults to
TRUE
.
See also
Functions used for postprocessing of model fits
build_ord_obs()
,
enw_add_latest_obs_to_nowcast()
,
enw_nowcast_samples()
,
enw_nowcast_summary()
,
enw_posterior()
,
enw_pp_summary()
,
enw_quantiles_to_long()
,
subset_obs()
Examples
fit <- enw_example("nowcast")
samples <- summary(fit, type = "nowcast_sample")
enw_summarise_samples(samples, probs = c(0.05, 0.5, 0.95))
#> Key: <reference_date, .group>
#> reference_date .group report_date max_confirm location age_group confirm
#> <IDat> <num> <IDat> <int> <fctr> <fctr> <int>
#> 1: 2021-08-03 1 2021-08-22 149 DE 00+ 149
#> 2: 2021-08-04 1 2021-08-22 166 DE 00+ 166
#> 3: 2021-08-05 1 2021-08-22 133 DE 00+ 133
#> 4: 2021-08-06 1 2021-08-22 137 DE 00+ 137
#> 5: 2021-08-07 1 2021-08-22 139 DE 00+ 139
#> 6: 2021-08-08 1 2021-08-22 97 DE 00+ 97
#> 7: 2021-08-09 1 2021-08-22 58 DE 00+ 58
#> 8: 2021-08-10 1 2021-08-22 175 DE 00+ 175
#> 9: 2021-08-11 1 2021-08-22 233 DE 00+ 233
#> 10: 2021-08-12 1 2021-08-22 237 DE 00+ 237
#> 11: 2021-08-13 1 2021-08-22 204 DE 00+ 204
#> 12: 2021-08-14 1 2021-08-22 189 DE 00+ 189
#> 13: 2021-08-15 1 2021-08-22 125 DE 00+ 125
#> 14: 2021-08-16 1 2021-08-22 98 DE 00+ 98
#> 15: 2021-08-17 1 2021-08-22 242 DE 00+ 242
#> 16: 2021-08-18 1 2021-08-22 223 DE 00+ 223
#> 17: 2021-08-19 1 2021-08-22 202 DE 00+ 202
#> 18: 2021-08-20 1 2021-08-22 171 DE 00+ 171
#> 19: 2021-08-21 1 2021-08-22 112 DE 00+ 112
#> 20: 2021-08-22 1 2021-08-22 45 DE 00+ 45
#> reference_date .group report_date 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 q50 q95
#> <num> <num> <num>
#> 1: 149.00 149 149.00
#> 2: 166.00 167 170.00
#> 3: 133.00 136 139.00
#> 4: 138.00 141 145.00
#> 5: 141.00 146 151.05
#> 6: 99.00 103 109.00
#> 7: 59.00 62 67.00
#> 8: 180.00 185 192.00
#> 9: 246.00 255 267.00
#> 10: 255.00 267 281.00
#> 11: 223.00 236 252.00
#> 12: 216.00 230 249.00
#> 13: 149.95 165 183.00
#> 14: 116.00 128 144.05
#> 15: 275.00 292 313.00
#> 16: 270.00 292 320.00
#> 17: 263.00 290 325.00
#> 18: 254.95 292 348.00
#> 19: 237.00 304 406.00
#> 20: 240.85 371 569.05
#> q5 q50 q95