Adds the mean and standard deviation of the delay distribution implied by
each draw of the distributional parameters, and quantiles of that
distribution if probs is given. Analytic solutions are used for the
families that have one. Every other family is summarised by simulating
delays from it, which works for any family brms can predict from.
Usage
add_summaries(
data,
family = NULL,
probs = NULL,
method = c("auto", "analytic", "sample"),
nsim = 1000
)Arguments
- data
A
data.frameof draws of the distributional parameters, as returned bydelay_parameter_draws().- family
A model fit with
epidist(), abrmsfamily, or the name of one, giving the delay distribution. IfNULL, the default, the family is taken fromdata, whichdelay_parameter_draws()records on it. Somedplyrverbs drop that record, so pass the fit or the family ifdatahas been through one of them.- probs
A numeric vector of probabilities to add quantiles of the delay distribution for. If
NULL, the default, no quantiles are added.- method
Either
"auto", the default, which uses the analytic solution when there is one and simulates otherwise,"analytic", which errors when there is no analytic solution, or"sample", which always simulates.- nsim
The number of delays to simulate per row of
data. Defaults to 1000. Only used when simulating.
Details
The summaries describe the delay distribution, not the posterior. A row of
data holds one draw of the distributional parameters, and the columns
added are the mean, standard deviation and quantiles of the delay
distribution those parameters define. Summarise the resulting columns across
draws to get posterior summaries of them.
Quantile columns are named as in posterior::quantile2(), so probs = 0.05
gives a q5 column.
Simulation adds Monte Carlo error to the summaries. The standard error of
the mean is the delay standard deviation divided by the square root of
nsim. Simulation is also memory hungry, because it draws nsim delays for
every row of data. Reduce the number of rows with epidist_strata(), or
the number of draws with the ndraws argument of
delay_parameter_draws(), if it is slow.
See also
Other postprocess:
delay_parameter_draws(),
epidist_strata()
Examples
draws <- data.frame(mu = c(1.8, 2.0), sigma = c(0.5, 0.4))
add_summaries(draws, family = "lognormal", probs = c(0.05, 0.95))
#> mu sigma mean sd q5 q95
#> 1 1.8 0.5 6.855149 3.653385 2.657998 13.76910
#> 2 2.0 0.4 8.004469 3.334232 3.826913 14.26689
