Which Applied Epi training is this question referring to?
Live intro course, final exercise using R markdown
Provide an overview of your problem
- I’d like to create a dynamic in-line code for the section under header: Weekly epidemic curve by city, which will dynamically update the month (or week) where cases have peaked.
I’m thinking the first step would be to get the week or month/year with the most number of cases, then pipe that into an in-line code. However, I’m at a loss how to start this process. Should I create a new table with the number of cases per week or month? Or can I somehow use the weekly_breaks df that we created for the epi curve?
- I’d also like to create a dynamic in-line code for the section under header: Cumulative case incidence by city, which will dynamically update the city with the highest incidence rate in the sentence.
For this part, I was already able to include the actual number of cases using the max(city_table$inc_per_10k). However I don’t know how to “call” the actual name of the city (in this case, College Park) with the highest number of cases.
Attached is my Rmd file for reference.
covid_sitrep_ian.Rmd (7.8 KB)
I will start answering your second question. You can extract the value in the City column with the highest incidence using this line
city_table$city[which.max(city_table$inc_per_10k)]. This will give you the name of the city with highest value in the
The first question is more complex because identifying peaks using code is not as simple as identifying them visually. A possible solution would be to create a summarized data frame grouped by months and extract the names of the n months with the highest number of cases, similar to what we did in the second question, the problem is, in this case, if n is 2, the selected months would be either December 2020 and January 2021, which can be interpreted as the same peak, not two peaks.
Therefore, before developing a solution that automatically identifies the peaks of a time series, the ideal would be to define what we would like to call a peak, and this will depend on the data set we have.
I hope it helped in some way
Thank you for this, I will try out your solutions and post updates if needed.