-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation.R
138 lines (138 loc) · 4.61 KB
/
validation.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
validation_targets <- list(
# validate both prior and posterior
tar_target(
validate_likelihood,
c(TRUE, FALSE)
),
# load data for validation data source
tar_target(
validation_obs,
filter_obs(observations, validation_source)
),
# extract the most up to date version of the validation data
tar_target(
current_validation_obs,
latest_obs(validation_obs)
),
# split data into that available in each forecast week
tar_target(
retro_validation_obs,
filter_by_availability(validation_obs, date = validation_dates),
map(validation_dates),
iteration = "list"
),
# plot prior predictive check
# plot posterior predictive check
# Targets producing forecasts for each week of observed data
# prior and predictive checks for validation data on the single strain model
tar_target(
single_predictive_checks,
do.call(
forecast,
c(
forecast_args,
retro_args,
list(
obs = retro_validation_obs,
strains = 1,
model = single_model,
likelihood = validate_likelihood,
overdispersion = overdispersion_scenarios
)
)
)[, likelihood := validate_likelihood],
cross(retro_validation_obs, validate_likelihood, overdispersion_scenarios)
),
# prior and predictive checks for validation data on the two strain model
# stratified by modelled relationship between variants
tar_target(
two_predictive_checks,
do.call(
forecast,
c(
forecast_args,
retro_args,
list(
obs = retro_validation_obs,
strains = 2,
variant_relationship = variant_relationship_scenarios,
model = two_model,
likelihood = validate_likelihood,
overdispersion = overdispersion_scenarios
)
)
)[, likelihood := validate_likelihood],
cross(retro_validation_obs, variant_relationship_scenarios,
overdispersion_scenarios, validate_likelihood)
),
## plot prior predictions for single model
tar_target(
plot_single_strain_prior,
plot_single_strain_predictions(single_predictive_checks,
current_validation_obs,
likelihood = FALSE),
format = "file"
),
## plot posterior predictions for single model
tar_target(
plot_single_strain_posterior,
plot_single_strain_predictions(single_predictive_checks,
current_validation_obs,
likelihood = TRUE),
format = "file"
),
## plot prior predictions for two strain model
tar_target(
plot_two_strain_prior_overdisp,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = FALSE, overdispersion = TRUE),
format = "file"
),
tar_target(
plot_two_strain_prior,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = FALSE, overdispersion = FALSE),
format = "file"
),
tar_target(
plot_two_strain_prior_overdisp_voc,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = FALSE, overdispersion = TRUE,
type = "voc"),
format = "file"
),
tar_target(
plot_two_strain_prior_voc,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = FALSE, overdispersion = FALSE,
type = "voc"),
format = "file"
),
## plot posterior predictions for two strain models
tar_target(
plot_two_strain_posterior_overdisp,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = TRUE, overdispersion = TRUE),
format = "file"
),
tar_target(
plot_two_strain_posterior,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = TRUE, overdispersion = FALSE),
format = "file"
),
tar_target(
plot_two_strain_posterior_overdisp_voc,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = TRUE, overdispersion = TRUE,
type = "voc"),
format = "file"
),
tar_target(
plot_two_strain_posterior_voc,
plot_two_strain_predictions(two_predictive_checks, current_validation_obs,
likelihood = TRUE, overdispersion = FALSE,
type = "voc"),
format = "file"
)
)