Skip to content

Commit

Permalink
add covid data generation file
Browse files Browse the repository at this point in the history
  • Loading branch information
avallecam committed Mar 6, 2025
1 parent 3ded3d0 commit b47bb03
Showing 1 changed file with 77 additions and 0 deletions.
77 changes: 77 additions & 0 deletions instructors/data-covid-filter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@

library(tidyverse)
library(incidence2)

# read data ---------------------------------------------------------------

incidence_class <- incidence2::covidregionaldataUK %>%
as_tibble() %>%
filter(region == "London") %>%
# preprocess missing values
tidyr::replace_na(
list(
deaths_new = 0,
cases_new = 0
)
) %>%
# compute the daily incidence
incidence2::incidence(
date_index = "date",
counts = c("cases_new","deaths_new"),
date_names_to = "date",
complete_dates = TRUE
) %>%
identity()

# number of dates ---------------------------------------------------------

incidence_class %>%
count(date) %>%
nrow()

incidence_class %>%
filter(date < ymd(20200415)) %>%
count(date) %>%
nrow()

incidence_class %>%
filter(date < ymd(20200701)) %>%
count(date) %>%
nrow()

# plot incidence ----------------------------------------------------------

incidence_class %>%
plot()

incidence_class %>%
filter(date < ymd(20200415)) %>%
plot()

incidence_class %>%
filter(date < ymd(20200701)) %>%
plot()

# adapt for cfr -----------------------------------------------------------

covid_incidence2 <- incidence_class %>%
cfr::prepare_data(
cases_variable = "cases_new",
deaths_variable = "deaths_new") %>%
as_tibble()

covid_incidence2


# write data --------------------------------------------------------------

covid_incidence2 %>%
filter(date < ymd(20200415)) %>%
write_rds(file.path("episodes", "data", "covid_70days.rds"))

covid_incidence2 %>%
filter(date < ymd(20200701)) %>%
write_rds(file.path("episodes", "data", "covid_150days.rds"))

covid_incidence2 %>%
write_rds(file.path("episodes", "data", "covid_490days.rds"))

0 comments on commit b47bb03

Please sign in to comment.