estimateR | R Documentation |
The function estimateR
uses the relative transmission probabilities to estimate
the individual-level, time-level, and average effective reproductive numbers
for an outbreak.
estimateR(
df,
indIDVar,
dateVar,
pVar,
timeFrame = c("days", "months", "weeks", "years"),
rangeForAvg = NULL,
bootSamples = 0,
alpha = 0.05,
progressBar = TRUE
)
df |
The name of the dateset with transmission probabilities (column |
indIDVar |
The name (in quotes) of the individual ID columns
(data frame |
dateVar |
The name (in quotes) of the columns with the dates that the individuals are
observed (data frame |
pVar |
The column name (in quotes) of the transmission probabilities. |
timeFrame |
The time frame used to calculate Rt
(one of |
rangeForAvg |
A vector with the start and ending time period to be used to calculate the average effective reproductive number. |
bootSamples |
The number of bootstrap samples; if 0, then no confidence intervals are calculated. |
alpha |
The alpha level for the confidence intervals. |
progressBar |
A logical indicating if a progress bar should be printed (default is TRUE). |
The effective reproductive number is the average number of cases an infectious case will produce in a population of both susceptible and non-susceptibe individuals. The rational behind this reproductive number estimation is Wallinga and Teunis (2004) where the individual-level reproductive number is estimated by summing the relative probability that the individual infected any other individual.
If p_{ij}
equals the relative probability that case i
was infected by
case j
, then the individual-level reproductive number (R_j
) is calculated by:
R_j = \sum_{m \ne j} {p_{mj}}
The time-level reproductive number is then estimated by averaging the individual-level reproductive numbers for all individuals observed in the time frame (can specify days, weeks, months, years).
Finally, the time-level reproductive numbers are averaged to
estimate the average effective reproductive number within rangeForAvg
.
To get the best estimate of the average effective reproductive number, one should
only consider the stable portion of the outbreak (exclude the beginning and end).
If bootSamples > 0
, bootstrap confidence intervals will be estimated for
both the time-level and average reproductive numbers using parametric bootstrapping.
A list with five elements:
RiDf
- a data frame with the individual-level reproductive numbers. Column names:
<indIDVar>
- the individual ID with name specified.
<dateVar>
- the date the individual was observed with name specified.
Ri
- the individual-level reproductive number.
nInfectees
- the number of possible infectees for this individual.
RtDf
- a data frame with the time-level reproductive numbers. Column names:
time
- the time frame corresponding to the reproductive number estimate
(day for "days" and "weeks", month for "months", year for "years").
timeRank
- the rank of the time frame.
Rt
- the time-level reproductive number for this time frame.
ciLower
- lower bound of confidence interval for Rt
(only if bootSamples > 0).
ciUpper
- upper bound of confidence interval for Rt
(only if bootSamples > 0).
RtAvgDf
- a data frame with the average effective reproductive. Column names:
RtAvg
- the average time-level reproductive number between the range
specified in rangeForAvg
.
ciLower
- lower bound of confidence interval for Rt
(only if bootSamples > 0).
ciUpper
- upper bound of confidence interval for Rt
(only if bootSamples > 0).
timeFrame
- a vector with the timeFrame input
rangeForAvg
- a vector with the rangeForAvg input
Wallinga J, Teunis P. Different epidemic curves for severe acute respiratory syndrome reveal similar impacts of control measures. American Journal of Epidemiology. 2004 Sep 15;160(6):509-16.
nbProbabilities
estimateRi
estimateRt
estimateRtAvg
## Use the nbResults data frame included in the package which has the results
## of the nbProbabilities() function on a TB-like outbreak.
## Getting initial estimates of the reproductive number
# (without specifying rangeForAvg and without confidence intervals)
rInitial <- estimateR(nbResults, dateVar = "infectionDate",
indIDVar = "individualID", pVar = "pScaled",
timeFrame = "months")
## Finding the stable portion of the outbreak for rangeForAvg using plot of Rt
cut1 <- 25
cut2 <- 125
# Optional plot to determine the cutpoints above
# ggplot(data = rInitial$RtDf, aes(x = timeRank, y = Rt)) +
# geom_point() +
# geom_line() +
# geom_hline(data = rInitial$RtAvgDf, aes(yintercept = RtAvg), size = 0.7) +
# geom_vline(aes(xintercept = cut1), linetype = 2, size = 0.7) +
# geom_vline(aes(xintercept = cut2), linetype = 2, size = 0.7)
## Finding the final reproductive number estimates with confidence intervals
# NOTE should run with bootSamples > 2.
rFinal <- estimateR(nbResults, dateVar = "infectionDate",
indIDVar = "individualID", pVar = "pScaled",
timeFrame = "months", rangeForAvg = c(cut1, cut2),
bootSamples = 2, alpha = 0.05)
rFinal$RtAvgDf
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.