Skip to contents

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.

Usage

enw_summarise_samples(
  samples,
  probs = c(0.05, 0.2, 0.35, 0.5, 0.65, 0.8, 0.95),
  by = c("reference_date", ".group"),
  link_with_obs = TRUE
)

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.

Value

A data.frame summarising the posterior samples.

See also

Examples

fit <- enw_example("nowcast")
samples <- summary(fit, type = "nowcast_sample")
enw_summarise_samples(samples, probs = c(0.05, 0.5, 0.95))
#>     reference_date .group report_date max_confirm location age_group confirm
#>  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
#>     cum_prop_reported delay prop_reported    mean median        sd     mad  q5
#>  1:                 1    19   0.000000000 149.000  149.0  0.000000  0.0000 149
#>  2:                 1    18   0.000000000 167.453  167.0  1.291301  1.4826 166
#>  3:                 1    17   0.000000000 135.677  135.0  1.853674  1.4826 133
#>  4:                 1    16   0.000000000 140.896  141.0  2.169768  2.9652 138
#>  5:                 1    15   0.007194245 145.222  145.0  2.760133  2.9652 141
#>  6:                 1    14   0.000000000 103.248  103.0  2.893591  2.9652  99
#>  7:                 1    13   0.000000000  62.742   62.0  2.412313  2.9652  59
#>  8:                 1    12   0.000000000 185.065  185.0  3.687054  4.4478 180
#>  9:                 1    11   0.000000000 255.574  255.0  6.079925  5.9304 246
#> 10:                 1    10   0.004219409 266.480  266.0  7.480345  7.4130 255
#> 11:                 1     9   0.000000000 235.082  235.0  7.671123  7.4130 224
#> 12:                 1     8   0.015873016 229.150  229.0  9.532280 10.3782 215
#> 13:                 1     7   0.040000000 163.327  163.0  8.941478  8.8956 149
#> 14:                 1     6   0.010204082 130.404  130.0  8.343284  8.8956 118
#> 15:                 1     5   0.012396694 299.890  299.0 12.795923 13.3434 280
#> 16:                 1     4   0.017937220 303.138  301.0 17.375755 17.0499 278
#> 17:                 1     3   0.019801980 311.131  309.0 24.503638 23.7216 275
#> 18:                 1     2   0.070175439 318.522  315.0 34.923992 34.0998 270
#> 19:                 1     1   0.383928571 334.231  327.5 53.967621 51.1497 258
#> 20:                 1     0   1.000000000 322.430  306.0 93.868922 80.8017 198
#>       q50    q95
#>  1: 149.0 149.00
#>  2: 167.0 170.00
#>  3: 135.0 139.00
#>  4: 141.0 145.00
#>  5: 145.0 150.00
#>  6: 103.0 109.00
#>  7:  62.0  67.00
#>  8: 185.0 191.00
#>  9: 255.0 266.00
#> 10: 266.0 279.05
#> 11: 235.0 248.00
#> 12: 229.0 246.00
#> 13: 163.0 178.00
#> 14: 130.0 145.00
#> 15: 299.0 322.00
#> 16: 301.0 334.05
#> 17: 309.0 356.00
#> 18: 315.0 383.00
#> 19: 327.5 436.00
#> 20: 306.0 493.05