Skip to content

Commit 4606f25

Browse files
committed
styler::style_folder("all_the_folders")
1 parent b60b01b commit 4606f25

12 files changed

+929
-921
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ dashboard:
8686
Rscript scripts/dashboard.R
8787

8888
update_site:
89-
Rscript -e "source('R/utils.R'); update_site()"
89+
Rscript -e "suppressPackageStartupMessages(source(here::here('R', 'load_all.R'))); update_site()"
9090

9191
netlify:
9292
netlify deploy --dir=reports --prod

R/forecasters/forecaster_climatological.R

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
climate_linear_ensembled <- function(epi_data,
2-
outcome,
3-
extra_sources = "",
4-
ahead = 7,
5-
trainer = parsnip::linear_reg(),
6-
quantile_levels = covidhub_probs(),
7-
filter_source = "",
8-
filter_agg_level = "",
9-
scale_method = c("quantile", "std", "none"),
10-
center_method = c("median", "mean", "none"),
11-
nonlin_method = c("quart_root", "none"),
12-
drop_non_seasons = FALSE,
13-
residual_tail = 0.99,
14-
residual_center = 0.35,
15-
...) {
2+
outcome,
3+
extra_sources = "",
4+
ahead = 7,
5+
trainer = parsnip::linear_reg(),
6+
quantile_levels = covidhub_probs(),
7+
filter_source = "",
8+
filter_agg_level = "",
9+
scale_method = c("quantile", "std", "none"),
10+
center_method = c("median", "mean", "none"),
11+
nonlin_method = c("quart_root", "none"),
12+
drop_non_seasons = FALSE,
13+
residual_tail = 0.99,
14+
residual_center = 0.35,
15+
...) {
1616
scale_method <- arg_match(scale_method)
1717
center_method <- arg_match(center_method)
1818
nonlin_method <- arg_match(nonlin_method)
@@ -49,7 +49,9 @@ climate_linear_ensembled <- function(epi_data,
4949
}
5050
learned_params <- calculate_whitening_params(season_data, outcome, scale_method, center_method, nonlin_method)
5151
epi_data %<>% data_whitening(outcome, learned_params, nonlin_method)
52-
epi_data <- epi_data %>% select(geo_value, source, time_value, season, value = !!outcome) %>% mutate(epiweek = epiweek(time_value))
52+
epi_data <- epi_data %>%
53+
select(geo_value, source, time_value, season, value = !!outcome) %>%
54+
mutate(epiweek = epiweek(time_value))
5355
pred_climate <- climatological_model(epi_data, ahead) %>% mutate(forecaster = "climate")
5456
pred_geo_climate <- climatological_model(epi_data, ahead, geo_agg = FALSE) %>% mutate(forecaster = "climate_geo")
5557
pred_linear <- forecaster_baseline_linear(epi_data, ahead, residual_tail = residual_tail, residual_center = residual_center) %>% mutate(forecaster = "linear")

R/utils.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,8 +305,10 @@ update_site <- function() {
305305
report_md_content <- readLines(template_path)
306306
# Get the list of files in the reports directory
307307
report_files <- dir_ls(reports_dir, regexp = ".*_prod_on_.*.html")
308-
report_table <- tibble(filename = report_files,
309-
dates = str_match_all(filename, "[0-9]{4}-..-..")) %>%
308+
report_table <- tibble(
309+
filename = report_files,
310+
dates = str_match_all(filename, "[0-9]{4}-..-..")
311+
) %>%
310312
unnest_wider(dates, names_sep = "_") %>%
311313
rename(forecast_date = dates_1, generation_date = dates_2) %>%
312314
mutate(

scripts/covid_hosp_explore.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ if (!exists("ref_time_values_")) {
99
start_date <- as.Date("2023-10-04")
1010
end_date <- as.Date("2024-04-24")
1111
date_step <- 7L
12-
#ref_time_values_ <- as.Date(c("2023-11-08", "2023-11-22"))
12+
# ref_time_values_ <- as.Date(c("2023-11-08", "2023-11-22"))
1313
}
1414
time_value_adjust <- 3 # this moves the week marker from Saturday to Wednesday
1515

scripts/covid_hosp_prod.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,8 @@ rlang::list2(
183183
if (submission_directory != "cache") {
184184
validation <- validate_submission(
185185
submission_directory,
186-
file_path = sprintf("CMU-climatological-baseline/%s-CMU-climatological-baseline.csv", get_forecast_reference_date(as.Date(forecast_generation_date))))
186+
file_path = sprintf("CMU-climatological-baseline/%s-CMU-climatological-baseline.csv", get_forecast_reference_date(as.Date(forecast_generation_date)))
187+
)
187188
} else {
188189
validation <- "not validating when there is no hub (set submission_directory)"
189190
}

scripts/flu_hosp_explore.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ rlang::list2(
536536
family_notebooks,
537537
command = {
538538
actual_eval_data <- hhs_evaluation_data
539-
mutate(target_end_date = target_end_date + 3)
539+
mutate(target_end_date = target_end_date + 3)
540540
delphi_forecaster_subset <- forecaster_parameter_combinations[[forecaster_families]]$id
541541
outside_forecaster_subset <- c("FluSight-baseline", "FluSight-ensemble", "UMass-flusion")
542542
filtered_forecasts <- joined_forecasts %>%

scripts/flu_hosp_prod.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
source("scripts/targets-common.R")
33
source("scripts/targets-exploration-common.R")
44

5+
submit_climatological <- FALSE
56
submission_directory <- Sys.getenv("FLU_SUBMISSION_DIRECTORY", "cache")
67
insufficient_data_geos <- c("as", "mp", "vi", "gu")
78
# date to cut the truth data off at, so we don't have too much of the past
@@ -10,7 +11,7 @@ truth_data_date <- "2023-09-01"
1011
end_date <- Sys.Date()
1112
# Generically set the generation date to the next Wednesday (or today if it's Wednesday)
1213
forecast_generation_date <- seq.Date(as.Date("2024-11-20"), Sys.Date(), by = 7L)
13-
14+
# forecast_generation_date <- as.Date("2025-01-08")
1415
very_latent_locations <- list(list(
1516
c("source"),
1617
c("flusurv", "ILI+")

scripts/one_offs/making_hhs_weekly_ex.R

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,10 @@ daily_to_weekly_archive <- function(epi_arch,
127127

128128
health_data_covid <- map(forecast_dates, get_health_data)
129129
compactified_health_data_covid <- mapply(\(x, y) mutate(x, version = y),
130-
health_data_covid,
131-
forecast_dates,
132-
SIMPLIFY = FALSE) %>%
130+
health_data_covid,
131+
forecast_dates,
132+
SIMPLIFY = FALSE
133+
) %>%
133134
bind_rows() %>%
134135
filter(!is.na(hhs)) %>%
135136
as_epi_archive(compactify = TRUE)
@@ -141,9 +142,10 @@ weekly_archive_covid <- compactified_health_data_covid %>%
141142

142143
health_data_flu <- map(forecast_dates, \(x) get_health_data(x, "flu"))
143144
compactified_health_data_flu <- mapply(\(x, y) mutate(x, version = y),
144-
health_data_flu,
145-
forecast_dates,
146-
SIMPLIFY = FALSE) %>%
145+
health_data_flu,
146+
forecast_dates,
147+
SIMPLIFY = FALSE
148+
) %>%
147149
bind_rows() %>%
148150
filter(!is.na(hhs)) %>%
149151
as_epi_archive(compactify = TRUE)

scripts/reports/baseline_linear_model.Rmd

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@ $$\\[.4in]$$
1414

1515
```{r echo=FALSE}
1616
knitr::opts_chunk$set(
17-
fig.align = "center",
18-
message = FALSE,
19-
warning = FALSE,
20-
cache = FALSE
17+
fig.align = "center",
18+
message = FALSE,
19+
warning = FALSE,
20+
cache = FALSE
2121
)
2222
knitr::opts_knit$set(root.dir = here::here())
2323
ggplot2::theme_set(ggplot2::theme_bw())
@@ -40,24 +40,24 @@ library(ggplot2)
4040
library(plotly)
4141
4242
if (params$disease == "flu") {
43-
epi_data <- readr::read_csv("https://data.cdc.gov/resource/ua7e-t2fy.csv?$limit=20000&$select=weekendingdate,jurisdiction,totalconfflunewadm", show_col_types = FALSE) %>%
44-
rename(time_value = weekendingdate, value = totalconfflunewadm, geo_value = jurisdiction)
43+
epi_data <- readr::read_csv("https://data.cdc.gov/resource/ua7e-t2fy.csv?$limit=20000&$select=weekendingdate,jurisdiction,totalconfflunewadm", show_col_types = FALSE) %>%
44+
rename(time_value = weekendingdate, value = totalconfflunewadm, geo_value = jurisdiction)
4545
} else if (params$disease == "covid") {
46-
epi_data <- readr::read_csv("https://data.cdc.gov/resource/ua7e-t2fy.csv?$limit=20000&$select=weekendingdate,jurisdiction,totalconfc19newadm", show_col_types = FALSE) %>%
47-
rename(time_value = weekendingdate, value = totalconfc19newadm, geo_value = jurisdiction)
46+
epi_data <- readr::read_csv("https://data.cdc.gov/resource/ua7e-t2fy.csv?$limit=20000&$select=weekendingdate,jurisdiction,totalconfc19newadm", show_col_types = FALSE) %>%
47+
rename(time_value = weekendingdate, value = totalconfc19newadm, geo_value = jurisdiction)
4848
} else {
49-
stop("Invalid disease")
49+
stop("Invalid disease")
5050
}
5151
today <- Sys.Date()
5252
epi_data <- epi_data %>%
53-
filter(geo_value %nin% c("AS", "USA", "VI", "PR", "MP", "GU")) %>%
54-
mutate(time_value = as.Date(time_value), geo_value = tolower(geo_value)) %>%
55-
mutate(
56-
target_end_date = time_value,
57-
value = ifelse(value == 0, NA, value)
58-
) %>%
59-
arrange(geo_value, time_value) %>%
60-
as_epi_df(as_of = today)
53+
filter(geo_value %nin% c("AS", "USA", "VI", "PR", "MP", "GU")) %>%
54+
mutate(time_value = as.Date(time_value), geo_value = tolower(geo_value)) %>%
55+
mutate(
56+
target_end_date = time_value,
57+
value = ifelse(value == 0, NA, value)
58+
) %>%
59+
arrange(geo_value, time_value) %>%
60+
as_epi_df(as_of = today)
6161
6262
aheads <- -1:3
6363
forecast_date <- today
@@ -69,18 +69,18 @@ subset_geos <- c("ca", "ny", "fl", "tx", "pa")
6969

7070
```{r}
7171
quantile_forecast <- map(aheads, ~ forecaster_baseline_linear(epi_data, .x, log = FALSE)) %>%
72-
bind_rows() %>%
73-
filter(geo_value %in% subset_geos) %>%
74-
mutate(forecaster = "baseline_linear")
72+
bind_rows() %>%
73+
filter(geo_value %in% subset_geos) %>%
74+
mutate(forecaster = "baseline_linear")
7575
truth_data <- epi_data %>%
76-
filter(geo_value %in% subset_geos, time_value > forecast_date - 365 * 2)
76+
filter(geo_value %in% subset_geos, time_value > forecast_date - 365 * 2)
7777
train_fit <- quantile_forecast %>%
78-
filter(is.na(quantile)) %>%
79-
mutate(time_value = target_end_date)
78+
filter(is.na(quantile)) %>%
79+
mutate(time_value = target_end_date)
8080
quantile_forecast <- quantile_forecast %>% filter(!is.na(quantile))
8181
train_data <- epi_data %>%
82-
filter(geo_value %in% subset_geos, time_value > forecast_date - 30) %>%
83-
summarize(start = min(time_value), stop = max(time_value))
82+
filter(geo_value %in% subset_geos, time_value > forecast_date - 30) %>%
83+
summarize(start = min(time_value), stop = max(time_value))
8484
8585
# Bad forecast filters
8686
filter_geos <- filter_forecast_geos(quantile_forecast, truth_data)
@@ -92,7 +92,7 @@ Filter geo recommendations: `r paste(filter_geos, collapse = ", ")`.
9292

9393
```{r}
9494
p <- plot_forecasts(quantile_forecast, forecast_date, truth_data = truth_data, relevant_period = train_data) +
95-
geom_point(data = train_fit, mapping = aes(x = time_value, y = value), size = 0.25)
95+
geom_point(data = train_fit, mapping = aes(x = time_value, y = value), size = 0.25)
9696
9797
ggplotly(p, tooltip = "text", height = 5000, width = 1700)
9898
```
@@ -101,18 +101,18 @@ ggplotly(p, tooltip = "text", height = 5000, width = 1700)
101101

102102
```{r}
103103
quantile_forecast <- map(aheads, ~ forecaster_baseline_linear(epi_data, .x, log = TRUE)) %>%
104-
bind_rows() %>%
105-
filter(geo_value %in% subset_geos) %>%
106-
mutate(forecaster = "baseline_linear")
104+
bind_rows() %>%
105+
filter(geo_value %in% subset_geos) %>%
106+
mutate(forecaster = "baseline_linear")
107107
truth_data <- epi_data %>%
108-
filter(geo_value %in% subset_geos, time_value > forecast_date - 365 * 2)
108+
filter(geo_value %in% subset_geos, time_value > forecast_date - 365 * 2)
109109
train_fit <- quantile_forecast %>%
110-
filter(is.na(quantile)) %>%
111-
mutate(time_value = target_end_date)
110+
filter(is.na(quantile)) %>%
111+
mutate(time_value = target_end_date)
112112
quantile_forecast <- quantile_forecast %>% filter(!is.na(quantile))
113113
train_data <- epi_data %>%
114-
filter(geo_value %in% subset_geos, time_value > forecast_date - 30) %>%
115-
summarize(start = min(time_value), stop = max(time_value))
114+
filter(geo_value %in% subset_geos, time_value > forecast_date - 30) %>%
115+
summarize(start = min(time_value), stop = max(time_value))
116116
117117
filter_geos <- filter_forecast_geos(quantile_forecast, truth_data)
118118
```
@@ -123,7 +123,7 @@ Filter geo recommendations: `r paste(filter_geos, collapse = ", ")`.
123123

124124
```{r}
125125
p <- plot_forecasts(quantile_forecast, forecast_date, truth_data = truth_data, relevant_period = train_data) +
126-
geom_point(data = train_fit, mapping = aes(x = time_value, y = value), size = 0.25)
126+
geom_point(data = train_fit, mapping = aes(x = time_value, y = value), size = 0.25)
127127
128128
ggplotly(p, tooltip = "text", height = 5000, width = 1700)
129129
```

0 commit comments

Comments
 (0)