Skip to content

Commit d400c4d

Browse files
resolving conflicts
1 parent 802a1e7 commit d400c4d

File tree

11 files changed

+178
-142
lines changed

11 files changed

+178
-142
lines changed

.pre-commit-config.yaml

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,55 @@
1-
# All available hooks: https://pre-commit.com/hooks.html
2-
# R specific hooks: https://github.com/lorenzwalthert/precommit
1+
# .pre-commit-config.yaml
32
repos:
4-
- repo: https://github.com/lorenzwalthert/precommit
5-
rev: v0.4.3.9015
3+
- repo: https://github.com/lorenzwalthert/precommit
4+
rev: v0.4.3.9016
65
hooks:
7-
- id: style-files
6+
- id: style-files
87
args: [--style_pkg=styler, --style_fun=tidyverse_style]
9-
# codemeta must be above use-tidy-description when both are used
10-
# - id: codemeta-description-updated
11-
- id: use-tidy-description
12-
- id: lintr
13-
- id: parsable-R
14-
- id: no-browser-statement
15-
- id: deps-in-desc
16-
- repo: https://github.com/pre-commit/pre-commit-hooks
17-
rev: v6.0.0
8+
# - id: codemeta-description-updated
9+
- id: use-tidy-description
10+
- id: lintr
11+
additional_dependencies:
12+
# From DESCRIPTION / Imports
13+
- cli
14+
- dplyr
15+
- rlang
16+
- readr
17+
- ggplot2
18+
- lubridate
19+
- fs
20+
- purrr
21+
- glue
22+
- scoringutils
23+
- zoo
24+
- stringr
25+
# GitHub remote for wwinference
26+
- github::CDCgov/ww-inference-model
27+
# Only if you use these linters
28+
- cyclocomp
29+
- spelling
30+
- id: parsable-R
31+
- id: no-browser-statement
32+
- id: deps-in-desc
33+
34+
- repo: https://github.com/pre-commit/pre-commit-hooks
35+
rev: v4.6.0
1836
hooks:
19-
- id: check-added-large-files
37+
- id: check-added-large-files
2038
args: ['--maxkb=200']
21-
- id: end-of-file-fixer
39+
- id: end-of-file-fixer
2240
exclude: '\.Rd'
23-
- repo: local
41+
- id: trailing-whitespace
42+
- id: check-yaml
43+
44+
- repo: local
2445
hooks:
25-
- id: forbid-to-commit
46+
- id: forbid-to-commit
2647
name: Don't commit common R artifacts
2748
entry: Cannot commit .Rhistory, .RData, .Rds or .rds.
2849
language: fail
2950
files: '\.Rhistory|\.RData|\.Rds|\.rds$'
30-
- repo: meta
51+
52+
- repo: meta
3153
hooks:
32-
- id: check-hooks-apply
33-
- id: check-useless-excludes
34-
- repo: https://github.com/pre-commit/pre-commit-hooks
35-
rev: v6.0.0
36-
hooks:
37-
- id: trailing-whitespace
38-
- id: check-yaml
39-
- id: check-added-large-files
54+
- id: check-hooks-apply
55+
- id: check-useless-excludes

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Imports:
3434
fs,
3535
purrr,
3636
glue,
37-
scoringutils
37+
scoringutils,
3838
zoo,
3939
stringr
4040
Suggests:

NAMESPACE

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# Generated by roxygen2: do not edit by hand
22

3-
export(get_model_draws_w_data)
43
export(convert_rolling_sum_to_inc)
54
export(quiet)
65
export(sample_metrics)
@@ -29,4 +28,3 @@ importFrom(scoringutils,log_shift)
2928
importFrom(scoringutils,score)
3029
importFrom(scoringutils,transform_forecasts)
3130
importFrom(wwinference,get_draws)
32-
importFrom(stringr,str_sub)

R/get_hosp_data.R

Lines changed: 65 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#' @param location_abbr Character string indicating abbreviation of state
55
#' @param forecast_date Character string or date indicating the date of
66
#' forecast in YYYY-MM-DD
7-
#' @param forecast_horizon Integer indicating the number of days to forecast. Default is `28`.
7+
#' @param forecast_horizon Forecast horizon. Default is `28`.
88
#' @param filepath_name Name of directory to save the raw input wastewater data.
99
#' @param right_trunc Boolean indicating whether to use the real-time, right
1010
#' truncated data or the final corrected data. Default is `FALSE` indicating
@@ -16,59 +16,60 @@
1616
#' @importFrom readr read_csv
1717
#' @importFrom lubridate ymd days
1818
get_hosp_for_eval <- function(location_name,
19-
location_abbr,
20-
forecast_date,
21-
forecast_horizon = 28,
22-
filepath_name = file.path("input", "data", "hosp")) {
23-
if (file.exists(file.path(filepath_name, "RKI_hosp_adj.csv"))) {
24-
RKI_hosp_adj <- read_csv(file.path(filepath_name, "RKI_hosp_adj.csv"))
25-
} else {
26-
RKI_hosp_adj <- read_csv("https://raw.githubusercontent.com/robert-koch-institut/COVID-19-Hospitalisierungen_in_Deutschland/refs/heads/main/Aktuell_Deutschland_adjustierte-COVID-19-Hospitalisierungen.csv") # nolint
27-
dir_create(filepath_name)
28-
write_csv(RKI_hosp_adj, file.path(filepath_name, "RKI_hosp_adj.csv"))
29-
# load in initial values
30-
}
31-
# Add a month to get out of the holiday period.
32-
date_to_get_init_vals <- min(RKI_hosp_adj$Datum) + days(30)
33-
init_vals <- get_initial_values(
34-
start_date_RKI_data = date_to_get_init_vals
35-
) |>
36-
filter(age_group == "00+") |>
37-
mutate(location = stringr::str_sub(location, -2)) |>
38-
filter(location == location_abbr) |>
39-
arrange(-desc(date)) |>
40-
pull(value)
19+
location_abbr,
20+
forecast_date,
21+
forecast_horizon = 28,
22+
filepath_name =
23+
file.path("input", "data", "hosp")) {
24+
if (file.exists(file.path(filepath_name, "RKI_hosp_adj.csv"))) {
25+
RKI_hosp_adj <- read_csv(file.path(filepath_name, "RKI_hosp_adj.csv"))
26+
} else {
27+
RKI_hosp_adj <- read_csv("https://raw.githubusercontent.com/robert-koch-institut/COVID-19-Hospitalisierungen_in_Deutschland/refs/heads/main/Aktuell_Deutschland_adjustierte-COVID-19-Hospitalisierungen.csv") # nolint
28+
dir_create(filepath_name)
29+
write_csv(RKI_hosp_adj, file.path(filepath_name, "RKI_hosp_adj.csv"))
30+
# load in initial values
31+
}
32+
# Add a month to get out of the holiday period.
33+
date_to_get_init_vals <- min(RKI_hosp_adj$Datum) + days(30)
34+
init_vals <- get_initial_values(
35+
start_date_RKI_data = date_to_get_init_vals
36+
) |>
37+
filter(age_group == "00+") |>
38+
mutate(location = stringr::str_sub(location, -2)) |>
39+
filter(location == location_abbr) |>
40+
arrange(-desc(date)) |>
41+
pull(value)
4142

42-
hosp_clean <- RKI_hosp_adj |>
43-
rename(
44-
date = Datum,
45-
state = Bundesland,
46-
age_group = Altersgruppe,
47-
# This is the initial reported hospital admissions (right-truncated)
48-
init_hosp_7d_count = `fixierte_7T_Hospitalisierung_Faelle`,
49-
# This is the updated, eventual reported admissions for that date
50-
updated_hosp_7d_count = `aktualisierte_7T_Hospitalisierung_Faelle`,
51-
state_pop = `Bevoelkerung`
52-
) |>
53-
arrange(-desc(date)) |>
54-
filter(
55-
state == location_name,
56-
date >= date_to_get_init_vals
57-
) |>
58-
# Replace with once we have initial values
59-
mutate(daily_hosp_admits = convert_rolling_sum_to_inc(
60-
rolling_sums = updated_hosp_7d_count,
61-
k = 7,
62-
initial_values = init_vals
63-
)) |>
64-
filter(
65-
date <= ymd(forecast_date) + days(forecast_horizon),
66-
state == location_name
67-
) |>
68-
select(
69-
date, daily_hosp_admits, state_pop, init_hosp_7d_count,
70-
updated_hosp_7d_count
71-
)
43+
hosp_clean <- RKI_hosp_adj |>
44+
rename(
45+
date = Datum,
46+
state = Bundesland,
47+
age_group = Altersgruppe,
48+
# This is the initial reported hospital admissions (right-truncated)
49+
init_hosp_7d_count = `fixierte_7T_Hospitalisierung_Faelle`,
50+
# This is the updated, eventual reported admissions for that date
51+
updated_hosp_7d_count = `aktualisierte_7T_Hospitalisierung_Faelle`,
52+
state_pop = `Bevoelkerung`
53+
) |>
54+
arrange(-desc(date)) |>
55+
filter(
56+
state == location_name,
57+
date >= date_to_get_init_vals
58+
) |>
59+
# Replace with once we have initial values
60+
mutate(daily_hosp_admits = convert_rolling_sum_to_inc(
61+
rolling_sums = updated_hosp_7d_count,
62+
k = 7,
63+
initial_values = init_vals
64+
)) |>
65+
filter(
66+
date <= ymd(forecast_date) + days(forecast_horizon),
67+
state == location_name
68+
) |>
69+
select(
70+
date, daily_hosp_admits, state_pop, init_hosp_7d_count,
71+
updated_hosp_7d_count
72+
)
7273
return(hosp_clean)
7374
}
7475

@@ -89,15 +90,17 @@ get_hosp_for_fit <- function(hosp_data_eval,
8990
calibration_period = 100,
9091
lag = 3) {
9192
if (isFALSE(right_trunc)) {
92-
hosp_for_fit <- hosp_data_eval |>
93-
filter(
94-
date >= ymd(forecast_date) - days(calibration_period),
95-
date <= ymd(forecast_date) - days(lag)
96-
) } else {
97-
# Insert function to use git history to get the data as of the forecast date
98-
hosp_for_fit <- NULL
99-
}
93+
hosp_for_fit <- hosp_data_eval |>
94+
filter(
95+
date >= ymd(forecast_date) - days(calibration_period),
96+
date <= ymd(forecast_date) - days(lag)
97+
)
98+
} else {
99+
# Insert function to use git history to get the data as of the forecast date
100+
hosp_for_fit <- NULL
101+
}
100102
return(hosp_for_fit)
103+
}
101104

102105
#' Get initial values of daily admissions
103106
#'
@@ -113,7 +116,7 @@ get_hosp_for_fit <- function(hosp_data_eval,
113116
#' triangle from the German Nowcast Hub. Default is from the data at
114117
#' https://raw.githubusercontent.com/KITmetricslab/hospitalization-nowcast-hub/refs/heads/main/data-truth/COVID-19/COVID-19_hospitalizations_preprocessed.csv #nolint
115118
#' @autoglobal
116-
#' @inheritParams get_hosp_data
119+
#' @inheritParams get_hosp_for_eval
117120
#' @importFrom glue glue
118121
#' @importFrom dplyr select filter mutate arrange desc
119122
#' @importFrom fs dir_create

R/get_model_draws_w_data.R

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#' Combining model draws with data for scoring
22
#'
3-
#' @param fit_obj_wwinference wwinference_fit object returned when wwinference::wwinference() is run
3+
#' @param fit_obj_wwinference wwinference_fit object
44
#' @param model_output Type of model output to extract, either "ww" or "hosp"
5-
#' @param include_ww Whether wastewater data was included in the model, either "TRUE" or "FALSE"
5+
#' @param include_ww Whether model included wastewater data, "TRUE" or "FALSE"
66
#' @param model Model type, either "wwinference" or "baseline"
77
#' @param forecast_date Forecast date
88
#' @param location Location name
99
#' @param eval_data Dataframe of observed data to compare against model output
10-
#'
1110
#' @return a dataframe containing model draws and observed data for scoring
1211
#' @importFrom wwinference get_draws
1312
#' @importFrom dplyr mutate rename left_join select ungroup
1413
#' @importFrom lubridate ymd
1514
#' @importFrom glue glue
15+
#' @importFrom rlang arg_match
1616
get_model_draws_w_data <- function(
1717
fit_obj_wwinference,
1818
model_output = c("ww", "hosp"),
@@ -39,7 +39,7 @@ get_model_draws_w_data <- function(
3939
"include_ww" = !!include_ww,
4040
"model" = !!model,
4141
"forecast_date" = lubridate::ymd(!!forecast_date),
42-
"location" = !!location,
42+
"location" = !!location
4343
) |>
4444
dplyr::rename(
4545
"value" = "pred_value",

R/get_ww_data.R

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22
#' For now, just pull the latest wastewater data and filter to exclude the
33
#' most recent dates
44
#'
5-
#' @inheritParams get_hosp_data
5+
#' @inheritParams get_hosp_for_eval
66
#' @param filepath_name Name of directory to save the raw input wastewater data.
77
#' @importFrom dplyr mutate filter select rename
88
#' @importFrom fs dir_create
99
#' @importFrom readr read_tsv read_csv write_csv
1010
#' @autoglobal
1111
get_ww_for_eval <- function(location_name,
12-
location_abbr,
13-
forecast_date,
14-
forecast_horizon = 28,
15-
filepath_name = file.path("input", "data", "ww")) {
12+
location_abbr,
13+
forecast_date,
14+
forecast_horizon = 28,
15+
filepath_name = file.path("input", "data", "ww")) {
1616
# For now, just pull the latest and filter to lag days before the forecast
1717
# date
1818

R/globals.R

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
# Generated by roxyglobals: do not edit by hand
22

33
utils::globalVariables(c(
4-
"age_group", # <get_hosp_data>
5-
"location", # <get_hosp_data>
6-
"value", # <get_hosp_data>
7-
"Datum", # <get_hosp_data>
8-
"Bundesland", # <get_hosp_data>
9-
"Altersgruppe", # <get_hosp_data>
10-
"fixierte_7T_Hospitalisierung_Faelle", # <get_hosp_data>
11-
"aktualisierte_7T_Hospitalisierung_Faelle", # <get_hosp_data>
12-
"Bevoelkerung", # <get_hosp_data>
13-
"state", # <get_hosp_data>
14-
"updated_hosp_7d_count", # <get_hosp_data>
15-
"daily_hosp_admits", # <get_hosp_data>
16-
"state_pop", # <get_hosp_data>
17-
"init_hosp_7d_count", # <get_hosp_data>
4+
"age_group", # <get_hosp_for_eval>
5+
"location", # <get_hosp_for_eval>
6+
"value", # <get_hosp_for_eval>
7+
"Datum", # <get_hosp_for_eval>
8+
"Bundesland", # <get_hosp_for_eval>
9+
"Altersgruppe", # <get_hosp_for_eval>
10+
"fixierte_7T_Hospitalisierung_Faelle", # <get_hosp_for_eval>
11+
"aktualisierte_7T_Hospitalisierung_Faelle", # <get_hosp_for_eval>
12+
"Bevoelkerung", # <get_hosp_for_eval>
13+
"state", # <get_hosp_for_eval>
14+
"updated_hosp_7d_count", # <get_hosp_for_eval>
15+
"daily_hosp_admits", # <get_hosp_for_eval>
16+
"state_pop", # <get_hosp_for_eval>
17+
"init_hosp_7d_count", # <get_hosp_for_eval>
1818
"location", # <get_initial_values>
1919
"age_group", # <get_initial_values>
2020
"value", # <get_initial_values>
21-
"daily_data", # <get_initial_values>
22-
"location", # <get_ww_data>
23-
"state", # <get_ww_data>
24-
"conc", # <get_ww_data>
25-
"pop_cov", # <get_ww_data>
26-
"change_in_lab_indicator", # <get_ww_data>
27-
"normalized", # <get_ww_data>
28-
"pathogen", # <get_ww_data>
29-
"below_LOD", # <get_ww_data>
30-
"site", # <get_ww_data>
31-
"lab", # <get_ww_data>
32-
"log_genome_copies_per_ml", # <get_ww_data>
33-
"log_lod", # <get_ww_data>
34-
"site_pop", # <get_ww_data>
21+
"location", # <get_ww_for_eval>
22+
"state", # <get_ww_for_eval>
23+
"conc", # <get_ww_for_eval>
24+
"pop_cov", # <get_ww_for_eval>
25+
"change_in_lab_indicator", # <get_ww_for_eval>
26+
"normalized", # <get_ww_for_eval>
27+
"pathogen", # <get_ww_for_eval>
28+
"below_LOD", # <get_ww_for_eval>
29+
"site", # <get_ww_for_eval>
30+
"lab", # <get_ww_for_eval>
31+
"log_genome_copies_per_ml", # <get_ww_for_eval>
32+
"log_lod", # <get_ww_for_eval>
33+
"site_pop", # <get_ww_for_eval>
3534
NULL
3635
))

0 commit comments

Comments
 (0)