-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_target_data.R
More file actions
48 lines (35 loc) · 1.65 KB
/
get_target_data.R
File metadata and controls
48 lines (35 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#' Fetch FluSight target Data
#' Obtain influenza signal
#'
#' @return data frame of flu incidence with columns date, location,
#' location_name, value, weekly_rate
#'
fetch_flu <- function(){
require(dplyr)
require(lubridate)
require(RSocrata)
require(stringr)
#read data from data.cdc.gov, filtering for when flu reporting became mandatory
health_data = RSocrata::read.socrata(url = "https://data.cdc.gov/resource/mpgq-jmmr.json?$limit=999999") #%>%
#remove VI and AS as they are not included for FluSight, keep only necessary vars and add epiweek and epiyear
recent_data = health_data %>%
dplyr::filter(!jurisdiction %in% c("VI", "AS", "GU", "MP")) %>%
dplyr::select(jurisdiction, weekendingdate, totalconfflunewadm) %>%
dplyr::rename("value" = "totalconfflunewadm", "date"="weekendingdate", "state"="jurisdiction") %>%
dplyr::mutate(date = as.Date(date),
value = as.numeric(value),
state = str_replace(state, "USA", "US"))
#bind state population data
full_data = dplyr::left_join(recent_data, locations, by = join_by("state" == "abbreviation"))
#calculates weekly rate
final_dat = full_data %>%
dplyr::mutate(weekly_rate = (value*100000)/population ) %>%
select(date, location, location_name, value, weekly_rate)
return(final_dat)
}
library(dplyr)
library(lubridate)
library(RSocrata)
locations <- read.csv(file = "https://raw.githubusercontent.com/cdcepi/FluSight-forecast-hub/main/auxiliary-data/locations.csv") %>% dplyr::select(1:4)
target_data <- fetch_flu()
write.csv(target_data, file = "./data_sets/target-hospital-admissions.csv", row.names = FALSE)