Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor jhu data processing to calculate inc signal #19

Open
elray1 opened this issue Dec 4, 2020 · 0 comments
Open

refactor jhu data processing to calculate inc signal #19

elray1 opened this issue Dec 4, 2020 · 0 comments
Assignees

Comments

@elray1
Copy link
Collaborator

elray1 commented Dec 4, 2020

move processing from load_jhu_data function to the assemble-historical-jhu.R script

Create a new R function called calc_jhu_inc that has the code in these lines:

covidData/R/jhu_data.R

Lines 97 to 172 in feb5648

tidyr::pivot_longer(
matches("^\\d{1,2}\\/\\d{1,2}\\/\\d{2,4}$"),
names_to = "date",
values_to = "cum"
) %>%
dplyr::mutate(
date = as.character(lubridate::mdy(date))
)
# summarized results for county level
results <- NULL
if ("county" %in% spatial_resolution) {
county_results <- jhu_data %>%
dplyr::filter(FIPS > 100) %>%
dplyr::mutate(
location = sprintf("%05d", FIPS)
) %>%
dplyr::filter(location < "80001") %>%
dplyr::group_by(location) %>%
dplyr::mutate(inc = diff(c(0, cum))) %>%
dplyr::select(location, date, cum, inc) %>%
dplyr::ungroup()
results <- dplyr::bind_rows(results, county_results)
}
# summarized results for state level
if ("state" %in% spatial_resolution) {
states_to_keep <- c(
"Alabama", "Alaska", "American Samoa", "Arizona", "Arkansas",
"California", "Colorado", "Connecticut", "Delaware",
"District of Columbia", "Florida", "Georgia", "Guam", "Hawaii", "Idaho",
"Illinois", "Indiana", "Iowa", "Kansas", "Kentucky", "Louisiana", "Maine",
"Maryland", "Massachusetts", "Michigan", "Minnesota",
"Mississippi", "Missouri", "Montana", "Nebraska", "Nevada",
"New Hampshire", "New Jersey", "New Mexico", "New York",
"North Carolina", "North Dakota", "Northern Mariana Islands",
"Ohio", "Oklahoma", "Oregon", "Pennsylvania", "Puerto Rico",
"Rhode Island", "South Carolina", "South Dakota", "Tennessee",
"Texas", "Utah", "Vermont", "Virgin Islands", "Virginia",
"Washington", "West Virginia", "Wisconsin", "Wyoming"
)
state_results <- jhu_data %>%
dplyr::filter(Province_State %in% states_to_keep) %>%
dplyr::mutate(location_name = Province_State) %>%
dplyr::group_by(location_name, date) %>%
dplyr::summarize(cum = sum(cum)) %>%
dplyr::group_by(location_name) %>%
dplyr::mutate(inc = diff(c(0, cum))) %>%
dplyr::ungroup() %>%
dplyr::left_join(
covidData::fips_codes %>% dplyr::filter(nchar(location) == 2),
by = "location_name"
) %>%
dplyr::select(location, date, cum, inc)
results <- dplyr::bind_rows(results, state_results)
}
# summarized results for national level
if ("national" %in% spatial_resolution) {
# because we don't filter on states_to_keep as above, we are off by a total
# of 3 deaths attributed to Diamond Princess.
national_results <- jhu_data %>%
dplyr::group_by(date) %>%
dplyr::summarize(cum = sum(cum)) %>%
dplyr::ungroup() %>%
dplyr::mutate(
inc = diff(c(0, cum)),
location = "US"
) %>%
dplyr::select(location, date, cum, inc)
results <- dplyr::bind_rows(results, national_results)
}
. We can save only the calculated incidence, not the cumulative values (as they can be reconstructed from the incidence). So the new function should return a tibble or data frame with columns location, date, inc.

In assemble-historical-jhu.R, at

function(filename) suppressMessages(readr::read_csv(filename)))
and
function(filename) suppressMessages(readr::read_csv(filename)))
, call the new function to process those inputs. After this point, the jhu_deaths_data and jhu_cases_data structures should be tibbles with columns issue_date and data, where in a given row, data is the tibble or data frame created above with columns location, date, and inc corresponding to the data for that issue date.

@elray1 elray1 changed the title consider refactoring data processing to calculate inc signal refactor jhu data processing to calculate inc signal Jan 11, 2021
@starkari starkari mentioned this issue Jan 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants