-
Notifications
You must be signed in to change notification settings - Fork 2
Issue 14: Use percent ED visits due to COVID data so we have data for whole timerange #61
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
Changes from 6 commits
75c662e
2aec003
3de8f80
a7080f7
491dd00
706ec14
463e688
45101c3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,16 +198,17 @@ get_bar_chart_seq_count <- function(obs_data, | |
| return(p) | ||
| } | ||
|
|
||
| #' Hospital admissions over time | ||
| #' Percent of hospital admissions due to covid over time | ||
| #' | ||
| #' @param location Location to plot (abbreviation) | ||
| #' @param date_range Vector of date range to plot, will use min and max | ||
| #' @param temporal_granularity Temporal granularity to plot | ||
| #' @param location_data Data.frame of location metadata to translate codes to | ||
| #' abbreviations | ||
| #' @param plot_name Name of plot | ||
| #' @param output_fp File.path to save plot | ||
| #' @param url URL for hospital admissions | ||
| #' @param output_fp File path to save plot | ||
| #' @param data_fp Filepath to NSSP data at the state and national level. | ||
| #' Originally obtained from: https://data.cdc.gov/Public-Health-Surveillance/NSSP-Emergency-Department-Visit-Trajectories-by-St/rdmq-nq56/about_data #nolint | ||
| #' | ||
| #' @returns ggplot object | ||
| #' @autoglobal | ||
|
|
@@ -220,37 +221,28 @@ get_plot_hosp_admissions <- function(location_to_plot, | |
| "output", "figs", | ||
| "data_figs" | ||
| ), | ||
| url = "https://raw.githubusercontent.com/CDCgov/covid19-forecast-hub/refs/heads/main/target-data/covid-hospital-admissions.csv") { # nolint | ||
| if (location_to_plot != "US minus CA") { | ||
| raw_data <- read_csv(url) |> | ||
| left_join(location_data, by = "location") |> | ||
| filter( | ||
| abbreviation == !!location_to_plot, | ||
| date >= min(date_range), | ||
| date <= max(date_range) | ||
| ) | ||
| } else { | ||
| raw_data <- read_csv(url) |> | ||
| left_join(location_data, by = "location") |> | ||
| filter( | ||
| !abbreviation %in% c("US", "CA"), | ||
| date >= min(date_range), | ||
| date <= max(date_range) | ||
| ) |> | ||
| group_by(date) |> | ||
| summarise(value = sum(value, na.rm = TRUE)) | ||
| } | ||
|
|
||
| data_fp = file.path("input", "nssp_states_and_national.csv")) { # nolint | ||
|
|
||
| nssp_cdcgov <- read_csv(data_fp) | ||
| raw_data <- nssp_cdcgov |> | ||
| left_join(location_data, | ||
| by = c("geography" = "location_name") # nolint | ||
| ) |> | ||
| rename(date = week_end) |> | ||
| filter( | ||
| abbreviation == !!location_to_plot, | ||
| date >= min(date_range), | ||
| date <= max(date_range) | ||
| ) | ||
|
Comment on lines
+226
to
+236
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# Verify the NSSP CSV schema and check for a sample of join key values
if [ -f "input/nssp_states_and_national.csv" ]; then
echo "=== CSV column names ==="
head -1 input/nssp_states_and_national.csv
echo ""
echo "=== Sample geography values (first 10 unique) ==="
tail -n +2 input/nssp_states_and_national.csv | cut -d',' -f1 | sort -u | head -10
else
echo "NSSP CSV file not found at input/nssp_states_and_national.csv"
echo ""
echo "Searching for NSSP-related CSV files in the repository..."
find . -name "*nssp*.csv" -o -name "*states*.csv" | head -20
fiRepository: epiforecasts/evalvariantnowcasthub Length of output: 608 🏁 Script executed: #!/bin/bash
# Find where location_data is created/loaded in the R file
grep -n "location_data" R/fig_data.R | head -20Repository: epiforecasts/evalvariantnowcasthub Length of output: 248 🏁 Script executed: #!/bin/bash
# View the function signature and parameter documentation
sed -n '200,240p' R/fig_data.RRepository: epiforecasts/evalvariantnowcasthub Length of output: 1772 🏁 Script executed: #!/bin/bash
# Find where get_plot_hosp_admissions is called
echo "=== Function calls to get_plot_hosp_admissions ==="
rg "get_plot_hosp_admissions" --type r -B 2 -A 5
echo ""
echo "=== Search for location_data creation/loading ==="
rg "location_data\s*<-|location_data\s*=" --type r -B 2 -A 2 | head -50Repository: epiforecasts/evalvariantnowcasthub Length of output: 5289 🏁 Script executed: #!/bin/bash
# Find the tar_target definition for location_data
rg "tar_target.*location_data|name\s*=\s*location_data" --type r -B 5 -A 10Repository: epiforecasts/evalvariantnowcasthub Length of output: 928 🏁 Script executed: #!/bin/bash
# Find location_fp definition
echo "=== Finding location_fp ==="
rg "location_fp\s*=" --type r -B 2 -A 2
echo ""
echo "=== Search for location CSV files ==="
find . -name "*location*" -type f | grep -E "\.(csv|tsv)$" | head -20Repository: epiforecasts/evalvariantnowcasthub Length of output: 454 🏁 Script executed: #!/bin/bash
# Search for location_fp assignment
echo "=== Finding location_fp assignment ==="
rg "location_fp.*<-|location_fp\s*=" --type r -B 1 -A 1
echo ""
echo "=== Check targets config file for location_fp ==="
grep -n "location_fp" targets/config_targets.R | head -20Repository: epiforecasts/evalvariantnowcasthub Length of output: 430 🏁 Script executed: #!/bin/bash
# View the tar_target definition for location_fp
sed -n '30,45p' targets/config_targets.RRepository: epiforecasts/evalvariantnowcasthub Length of output: 849 🏁 Script executed: #!/bin/bash
# Fetch and inspect the FluSight locations CSV
echo "=== Fetching FluSight locations CSV ==="
curl -s "https://raw.githubusercontent.com/cdcepi/FluSight-forecast-hub/refs/heads/main/auxiliary-data/locations.csv" | head -5 > /tmp/locations.csv
if [ -s /tmp/locations.csv ]; then
echo "=== Column names ==="
head -1 /tmp/locations.csv
echo ""
echo "=== First few rows ==="
head -6 /tmp/locations.csv
else
echo "Failed to fetch locations CSV"
fiRepository: epiforecasts/evalvariantnowcasthub Length of output: 742 Correct the join key: use The NSSP CSV's Change: by = c("geography" = "location_name")To: by = c("geography" = "location")🤖 Prompt for AI Agents |
||
|
|
||
| p <- ggplot(raw_data) + | ||
| geom_bar(aes(x = date, y = value), | ||
| geom_line(aes(x = date, y = percent_visits_covid), | ||
| fill = "black", | ||
| stat = "identity", position = "dodge" | ||
| ) + | ||
| get_plot_theme() + | ||
| xlab("") + | ||
| ylab("Hospital admissions") + | ||
| ylab("Percent of ED visits\ndue to COVID") + | ||
| # scale_y_continuous(transform = "log10")+ | ||
| scale_x_date( | ||
| limits = c(min(date_range), max(date_range)), | ||
|
|
@@ -263,7 +255,8 @@ get_plot_hosp_admissions <- function(location_to_plot, | |
| size = 10 | ||
| ), | ||
| legend.position = "bottom" | ||
| ) | ||
| ) + | ||
| ggtitle(glue::glue("{location_to_plot}")) | ||
| dir_create(output_fp, recurse = TRUE) | ||
| ggsave(file.path(output_fp, glue::glue("{plot_name}.png")), | ||
| plot = p, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Correct terminology: ED visits, not hospital admissions.
The title states "Percent of hospital admissions due to covid" but the data source (NSSP) and y-axis label (line 245) correctly reference "ED visits" (emergency department visits). Hospital admissions and ED visits are distinct metrics.
🔎 Proposed fix
📝 Committable suggestion
🤖 Prompt for AI Agents