File: sample_posterior_R.Rd

package info (click to toggle)
r-cran-epiestim 2.2-4%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, sid, trixie
  • size: 636 kB
  • sloc: sh: 15; makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,786 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/sample_posterior_R.R
\name{sample_posterior_R}
\alias{sample_posterior_R}
\title{sample from the posterior R distribution}
\usage{
sample_posterior_R(R, n = 1000, window = 1L)
}
\arguments{
\item{R}{an \code{estimate_R} object from the estimate_r function
function.}

\item{n}{an integer specifying the number of samples to be taken from the
gamma distribution.}

\item{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
}
\description{
sample from the posterior R distribution
}
\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
}
\author{
Anne Cori
}