Calculate the weekly growth rate from daily collected data.
Use the linelist object in the ebola_sim_clean list from the {outbreaks} R package. linelist is an outbreak data set.
Use the date_of _onset column of linelist to calculate the case counts.
Keep the first 20 weeks in linelist as period of analysis.
Steps in code
# Calculate the weekly growth rate of an outbreak# Load required packageslibrary(outbreaks)library(incidence2)library(i2extras)library(dplyr)# Load the simulated Ebola outbreak datadata(ebola_sim_clean)# Extract the first element of the listlinelist <- ebola_sim_clean$linelist# Read linelist dataas_tibble(linelist)
# Get an incidence2 object with case counts per week# from data collected per dayincidence2_week <- incidence2::incidence(x = linelist, date_index ="date_of_onset",interval ="week" )# Read case counts per weekincidence2_week
# Filter the dataset to keep the first 20 weeks. incidence2_filter <- incidence2_week[1:20,]# Model the incidenceincidence2_fit <- i2extras::fit_curve( incidence2_filter, model ="poisson", alpha =0.05 )# Print the model resulti2extras::growth_rate(incidence2_fit)
# A tibble: 1 × 9
count_variable model r r_lower r_upper growth_or_decay time time_lower
<chr> <list> <dbl> <dbl> <dbl> <chr> <dbl> <dbl>
1 date_of_onset <glm> 0.184 0.168 0.200 doubling 3.77 3.46
# ℹ 1 more variable: time_upper <dbl>
# Plot the model result with prediction intervalsplot(incidence2_fit, ci =FALSE, pi =TRUE)
# Read plot documentation for an incidence2_fit object# ?plot.incidence2_fit
Steps in detail
The outbreaks package is loaded to access the simulated Ebola outbreak data.
The ebola_sim_clean object from the package contains the simulated outbreak data.
The linelist object contains the first list element from ebola_sim_clean.
The incidence() function from the incidence2 package converts the data object linelist to an incidence2 class object.
The date_of_onset column is used in the date_index argument as the onset dates of the outbreak.
The "week" text string is used in the interval argument to count number of cases per week interval.
The incidence2 object provides observations arranged in descendant order with respect to the date_index.
The number of weeks to consider is set to 20 and stored in the dat_filter object.
The fit_curve() function from the i2extras package fits a Poisson linear regression model to the epicurve in the dat_filter object with an alpha value of 0.05 to calculate the 95% confidence intervals.
The growth_rate() function calculate the weekly growth/decay rate.
The plot() function plot the fitted epicurve.
Please note that the code assumes the necessary packages are already installed. If they are not, you can install them using first the install.packages("pak") function and then the pak::pak() function for both packages in CRAN or GitHub before loading them with library().
Additionally, make sure to adjust the serial interval distribution parameters according to the specific outbreak you are analyzing.