Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

sample_posterior_R

sample from the posterior R distribution


Description

sample from the posterior R distribution

Usage

sample_posterior_R(R, n = 1000, window = 1L)

Arguments

R

an estimate_R object from the estimate_r function function.

n

an integer specifying the number of samples to be taken from the gamma distribution.

window

an integer (or sequence of integers) specifying the window(s) from which to estimate R. Defaults to the first window. If multiple windows are specified, the resulting samples will be drawn from several distributions.

Value

n values of R from the posterior R distribution

Author(s)

Anne Cori

Examples

## load data on pandemic flu in a school in 2009
data("Flu2009")

## estimate the reproduction number (method "non_parametric_si")
## when not specifying t_start and t_end in config, they are set to estimate
## the reproduction number on sliding weekly windows                          
res <- estimate_R(incid = Flu2009$incidence, 
                  method = "non_parametric_si",
                  config = make_config(list(si_distr = Flu2009$si_distr)))

## Sample R from the first weekly window
win <- 1L
R_median <- res$R$`Median(R)`[win]
R_CrI <- c(res$R$`Quantile.0.025(R)`[win], res$R$`Quantile.0.975(R)`[win])

set.seed(2019-06-06) # fixing the random seed for reproducibility
R_sample <- sample_posterior_R(res, n = 1000, window = win)
hist(R_sample, col = "grey", main = "R sampled from the first weekly window")
abline(v = R_median, col = "red")       # show the median estimated R
abline(v = R_CrI, col = "red", lty = 2) # show the 95%CrI of R

EpiEstim

Estimate Time Varying Reproduction Numbers from Epidemic Curves

v2.2-4
GPL (>= 2)
Authors
Anne Cori [aut, cre] (<https://orcid.org/0000-0002-8443-9162>), Simon Cauchemez [ctb], Neil M. Ferguson [ctb] (<https://orcid.org/0000-0002-1154-8093>), Christophe Fraser [ctb] (<https://orcid.org/0000-0003-2399-9657>), Elisabeth Dahlqwist [ctb] (<https://orcid.org/0000-0001-5797-6803>), P. Alex Demarsh [ctb], Thibaut Jombart [ctb] (<https://orcid.org/0000-0003-2226-8692>), Zhian N. Kamvar [ctb] (<https://orcid.org/0000-0003-1458-7108>), Justin Lessler [ctb] (<https://orcid.org/0000-0002-9741-8109>), Shikun Li [ctb], Jonathan A. Polonsky [ctb] (<https://orcid.org/0000-0002-8634-4255>), Jake Stockwin [ctb], Robin Thompson [ctb] (<https://orcid.org/0000-0001-8545-5212>), Rolina van Gaalen [ctb]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.