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

Off by one hotfix #47

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions R/retrieve.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
#' @title Get hospitalization data
#' @name Get flu and COVID-19 hospitalization data from healthdata.gov endpoint
#' @description Retrieves hospitalization data from the healthdata.gov endpoint with optional filtering on fields, and return the results into a nice tibble.
#' @param endpoint URL to healthdata.gov endpoint (see references)..
#' @param state A two-letter state abbreviation.
#' @param limitrows Limit API query to at most this number of results. Default is `NULL` (no limit).
#' @param mindate Minimum date of results returned (ISO 8601 format: YYYY-MM-DD). See examples.
#' @param maxdate Maximum date of results returned (ISO 8601 format: YYYY-MM-DD). See examples.
#' @param mindate Minimum date of results returned (ISO 8601 format: YYYY-MM-DD). See examples. Note that after retrieving the data, dates will be shifted back one day because the admissions data is _previous_ day's flu/covid admissions.
#' @param maxdate Maximum date of results returned (ISO 8601 format: YYYY-MM-DD). See examples. Note that after retrieving the data, dates will be shifted back one day because the admissions data is _previous_ day's flu/covid admissions.
#' @param limitcols Limit the columns returned to the subjectively defined important ones?
#' @param app_token App token from healthdata.gov. If `NULL` you might get rate limited. Add an entry to your `~/.Renviron` with `HEALTHDATA_APP_TOKEN="tokenhere"` that you got from <https://healthdata.gov/profile/edit/developer_settings>.
#' @return A tibble
Expand Down Expand Up @@ -89,6 +88,9 @@ get_hdgov_hosp <- function(endpoint="https://healthdata.gov/resource/g62h-syeh.j
d <- d %>% dplyr::select(state:cov.deaths.cov)
}

# Data is previous day's stats. Shift dates back one day to deal with this.
d$date <- d$date-1

message(paste0(nrow(d), " rows retrieved from:\n", api_url))
return(d)

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions scratch/eval.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ eval_wrap <- function(hosp = NULL, ilidat = NULL, min_hhs = "2020-10-12", max_hh

hosp <-
get_hdgov_hosp(mindate = min_hhs, maxdate=max_hhs) %>%
mutate(date = date - 1) %>%
# mutate(date = date - 1) %>%
mutate(flu.admits = as.numeric(flu.admits),
flu.admits.cov = as.numeric(flu.admits.cov)) %>%
mutate(epiweek = lubridate::epiweek(date),
Expand Down Expand Up @@ -128,7 +128,7 @@ models <-
## alternative is to keep hosp=NULL param to eval_wrap and the function will retrieve each time
hosp_dat <-
get_hdgov_hosp(mindate = "2020-10-12", maxdate="2021-12-27") %>%
mutate(date = date - 1) %>%
# mutate(date = date - 1) %>%
mutate(flu.admits = as.numeric(flu.admits),
flu.admits.cov = as.numeric(flu.admits.cov)) %>%
mutate(epiweek = lubridate::epiweek(date),
Expand Down
2 changes: 1 addition & 1 deletion scratch/explore-covariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tail(h)
# weekly data summed across states
hu <-
h %>%
mutate(date = date - 1) %>%
# mutate(date = date - 1) %>%
mutate(epiweek = lubridate::epiweek(date),
epiyear = lubridate::epiyear(date),
.after=date) %>%
Expand Down
2 changes: 1 addition & 1 deletion scratch/hosp-arima.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ library(fiphde)

tmp_hosp_dat <-
get_hdgov_hosp(maxdate="2021-12-26") %>%
mutate(date = date - 1) %>%
# mutate(date = date - 1) %>%
mutate(flu.admits = as.numeric(flu.admits),
flu.admits.cov = as.numeric(flu.admits.cov)) %>%
mutate(epiweek = lubridate::epiweek(date),
Expand Down
2 changes: 1 addition & 1 deletion scratch/workflow.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ hosp <- get_hdgov_hosp(maxdate="2021-12-26")

tmp_weekly_flu <-
hosp %>%
mutate(date = date - 1) %>%
# mutate(date = date - 1) %>%
mutate(flu.admits = as.numeric(flu.admits),
flu.admits.cov = as.numeric(flu.admits.cov)) %>%
mutate(epiweek = lubridate::epiweek(date),
Expand Down