@@ -206,25 +206,45 @@ smooth_fc <- function(x, aheads = 1:28, degree = 3L, quantiles = 0.5, fd) {
206206}
207207```
208208
209+ ``` {r load-stored-preds, echo=FALSE}
210+ smooth_preds_list <- readRDS("smooth-qr_smooth_preds_list.rds")
211+ baseline_preds <- readRDS("smooth-qr_baseline_preds.rds")
212+ smooth_preds <- smooth_preds_list %>%
213+ filter(degree == 3L) %>%
214+ select(geo_value:ahead, `0.5`)
215+ ```
216+
209217Notice that we allow the function user to specify the aheads, degree, and
210218quantile as they may want to change these parameter values. We also allow for
211219input of the forecast date as we fixed that at the onset of this demonstration.
212220
213221We now can produce smooth quantile regression predictions for our problem:
214222
215- ``` {r, warning = FALSE}
223+ ``` {r, eval = FALSE}
216224smooth_preds <- smooth_fc(edf, fd = fd)
225+ smooth_preds
226+ ```
217227
228+ ``` {r, echo=FALSE}
218229smooth_preds
230+ smooth_preds <- smooth_preds_list %>%
231+ filter(degree == 3L) %>%
232+ select(-degree)
219233```
234+
235+
220236Most often, we're not going to want to limit ourselves to just predicting the
221237median value as there is uncertainty about the predictions, so let's try to
222238predict several different quantiles in addition to the median:
223239
224- ``` {r, warning = FALSE}
240+ ``` {r, eval = FALSE}
225241several_quantiles <- c(.1, .25, .5, .75, .9)
226242smooth_preds <- smooth_fc(edf, quantiles = several_quantiles, fd = fd)
243+ smooth_preds
244+ ```
227245
246+ ``` {r, echo = FALSE}
247+ several_quantiles <- c(.1, .25, .5, .75, .9)
228248smooth_preds
229249```
230250
@@ -278,13 +298,14 @@ We can test the impact of different degrees by using the `map()` function.
278298Noting that this may take some time to run, let's try out all degrees from 1
279299to 7:
280300
281- ``` {r, warning = FALSE}
282- smooth_preds_list <- map(1:7, ~ smooth_fc(edf,
283- degree = .x,
284- quantiles = c(.1, .25, .5, .75, .9),
285- fd = fd
286- ) %>%
287- mutate(degree = .x)) %>% list_rbind()
301+ ``` {r, eval = FALSE}
302+ smooth_preds_list <- map(1:7, function(x) {
303+ smooth_fc(edf,
304+ degree = x,
305+ quantiles = c(.1, .25, .5, .75, .9),
306+ fd = fd) %>%
307+ mutate(degree = x)
308+ }) %>% list_rbind()
288309```
289310
290311One way to quantify the impact of these on the forecasting is to look at the
@@ -339,7 +360,7 @@ To get the basic quantile regression results we can utilize the forecaster that
339360we've already built. We can simply set the degree to be the number of ahead
340361values to re-run the code without smoothing.
341362
342- ``` {r, warning = FALSE}
363+ ``` {r, eval = FALSE}
343364baseline_preds <- smooth_fc(
344365 edf,
345366 degree = 28L, quantiles = several_quantiles, fd = fd
@@ -361,6 +382,7 @@ test performance in terms of accuracy through calculating either the, MAE or
361382MSE, where the performance measure of choice can be calculated over over all
362383times and locations for each ahead value
363384
385+
364386``` {r, message = FALSE}
365387baseline_preds_mae_df <- baseline_preds %>%
366388 left_join(tedf_sub, by = c("geo_value", "target_date")) %>%
@@ -382,7 +404,7 @@ ggplot(preds_mae_df, aes(ahead, mean, color = type)) +
382404 geom_line() +
383405 xlab("Ahead") +
384406 ylab("Mean MAE") +
385- scale_color_manual(values = c("#A69943 ", "#063970"))
407+ scale_color_manual(values = c("darkred ", "#063970"), name = "" )
386408```
387409
388410or over all aheads, times, and locations for a single numerical summary.
@@ -485,7 +507,7 @@ ggplot(preds_wis_df, aes(ahead, mean, color = type)) +
485507 geom_line() +
486508 xlab("Ahead") +
487509 ylab("Mean WIS") +
488- scale_color_manual(values = c("#A69943 ", "#063970"))
510+ scale_color_manual(values = c("darkred ", "#063970"), name = "" )
489511```
490512
491513The results are consistent with what we saw for MAE: The forecasts for the near
0 commit comments