# Example 1: Basic usage with synthetic data
set.seed(123)
dates <- seq(as.Date("2023-01-01"), by = "day", length.out = 30)
incidence <- c(1, 2, 4, 7, 12, 15, 18, 20, 22, 19,
16, 14, 11, 9, 7, 5, 4, 3, 2, 1,
rep(0, 10))
# Estimate reproduction number
result <- wallinga_lipsitch(
incidence = incidence,
dates = dates,
si_mean = 7,
si_sd = 3,
si_dist = "gamma"
)
# View results
head(result)
# Example 2: With bootstrap confidence intervals
result_ci <- wallinga_lipsitch(
incidence = incidence,
dates = dates,
si_mean = 7,
si_sd = 3,
si_dist = "gamma",
bootstrap = TRUE,
n_bootstrap = 500 # Reduced for faster example
)
# Plot results with confidence intervals
if (require(ggplot2)) {
library(ggplot2)
ggplot(result_ci, aes(x = date)) +
geom_ribbon(aes(ymin = R_corrected_lower, ymax = R_corrected_upper),
alpha = 0.3, fill = "blue") +
geom_line(aes(y = R_corrected), color = "blue", size = 1) +
geom_hline(yintercept = 1, linetype = "dashed", color = "red") +
labs(x = "Date", y = "Reproduction Number",
title = "Time-varying Reproduction Number") +
theme_minimal()
}
# Example 3: With smoothing and shifting
result_smooth <- wallinga_lipsitch(
incidence = incidence,
dates = dates,
si_mean = 7,
si_sd = 3,
si_dist = "gamma",
smoothing = 7, # 7-day smoothing window
shift = TRUE # Shift for comparison with instantaneous R
)
# Example 4: Using normal distribution for serial interval
result_normal <- wallinga_lipsitch(
incidence = incidence,
dates = dates,
si_mean = 6,
si_sd = 2,
si_dist = "normal",
smoothing = 5
)
Run the code above in your browser using DataLab