-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_targets.R
111 lines (98 loc) · 3.33 KB
/
_targets.R
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
# Created by use_targets().
# Load packages required to define the pipeline:
library(targets)
library(tarchetypes)
library(tibble)
library(crew)
library(covidHubUtils)
data("hub_locations")
# Set target options:
tar_option_set(
controller = crew_controller_local(workers = 4),
packages = c("tidyverse", "covidHubUtils", "distfromq", "alloscore", "gh"), # packages that your targets need to run
imports = c("alloscore"),
format = "rds" # default storage format
)
## for custom package install
# remotes::install_github("aaronger/alloscore")
# remotes::install_github("reichlab/distfromq")
# remotes::install_github("reichlab/covidHubUtils")
# Run the R scripts in the R/ folder:
tar_source(files = c("R/data-ingestion.R",
"R/plot-alloscores.R",
"R/run-alloscore.R",
"R/determine-model-eligibility.R",
"R/exponential-examples.R",
"R/percap.R",
"R/plot_functions.R"))
values <- tibble(forecast_dates = as.character(seq.Date(as.Date("2021-11-22"), as.Date("2022-02-28"), by = "7 days")))
## create a group of alloscore targets
##values <- tidyr::expand_grid(models = mkeep, forecast_dates = forecast_dates)
## set of required locations: all states + DC
reqd_locs <- hub_locations |>
dplyr::filter(geo_type == "state", !(geo_value %in% c("us", "as", "gu", "mp", "pr", "um", "vi"))) |>
dplyr::pull(fips)
# Lists of targets:
setup <- list(
tar_target(
name = eligible_models,
command = determine_eligible_models(values$forecast_dates, locations = reqd_locs)
),
tar_target(
name = forecast_data,
command = get_forecast_data(values$forecast_dates, models = eligible_models, locations = reqd_locs)
),
tar_target(
name = truth_data,
command = get_truth_data()
),
tar_target(
name = score_data,
command = get_forecast_scores(forecast_data, truth_data)
),
tar_target(
name = exponential_example,
command = make_exponential_example_figure()
),
tar_target(
name = Kat15k_alloscores,
command = run_and_assemble_alloscores(forecast_data,
truth_data,
reference_dates = values$forecast_dates,
one_K = 15000)
),
tar_target(
name = pops22,
command = readr::read_csv("https://www2.census.gov/programs-surveys/popest/datasets/2020-2022/state/totals/NST-EST2022-ALLDATA.csv") |>
dplyr::select(full_location_name = NAME, POPESTIMATE2021) |>
dplyr::inner_join(hub_locations, by = join_by(full_location_name))
)
)
## from Ben's "overk" analysis
# tar_map(
# values=values,
# tar_target(alloscore_overk, run_alloscore_overk(forecast_data, truth_data, forecast_dates))
# )
mapped <- tar_map(
unlist = FALSE,
values = values,
tar_target(
alloscore,
run_alloscore_one_date(forecast_data, truth_data, forecast_dates)
)
)
combined <- tar_combine(
name = all_alloscore_data,
mapped[["alloscore"]],
command = assemble_alloscores(dplyr::bind_rows(!!!.x))
)
# tar_target(
# name = figure_K_v_alloscore,
# command = plot_K_v_alloscore(alloscore_df),
# format = "file"
# )
make_percap <- tar_target(
name = percap,
command = score_per_capita_allocation(dat = Kat15k_alloscores, pops = pops22)
)
list(setup, mapped, combined, make_percap)