@@ -283,15 +283,15 @@ data.
283
283
284
284
There are many ways we could modify ` four_week_ahead ` ; one simple modification
285
285
would be to include a growth rate estimate as part of the model.
286
- Another would be to include a time component to the prediction (useful if we
287
- expect there to be a strong seasonal component).
288
286
Another would be to convert from rates to counts, for example if that were the
289
287
preferred prediction format.
288
+ Another would be to include a time component to the prediction (useful if we
289
+ expect there to be a strong seasonal component).
290
290
291
291
## Growth rate
292
292
293
293
One feature that may potentially improve our forecast is looking at the growth
294
- rate
294
+ rate
295
295
296
296
``` {r growth_rate_recipe}
297
297
growth_rate_recipe <- epi_recipe(
@@ -305,12 +305,17 @@ growth_rate_recipe <- epi_recipe(
305
305
step_epi_naomit() |>
306
306
step_training_window()
307
307
```
308
+
308
309
Inspecting the newly added column:
310
+
309
311
``` {r growth_rate_print}
310
312
growth_rate_recipe |>
311
313
prep(training_data) |>
312
314
bake(training_data) |>
313
- select(geo_value, time_value, case_rate, death_rate, gr_7_rel_change_death_rate)
315
+ select(
316
+ geo_value, time_value, case_rate,
317
+ death_rate, gr_7_rel_change_death_rate
318
+ )
314
319
```
315
320
And the role:
316
321
``` {r growth_rate_roles}
@@ -320,7 +325,7 @@ prepped$term_info |> filter(grepl("gr", variable))
320
325
```
321
326
322
327
To demonstrate the changes in the layers that come along with it, we will use
323
- ` quantile_reg() ` as the model:
328
+ ` quantile_reg() ` as the model, which requires changing from ` layer_residual_quantiles() ` to ` layer_quantile_distn() ` and ` layer_point_from_distn() ` :
324
329
``` {r layer_and_fit}
325
330
growth_rate_layers <- frosting() |>
326
331
layer_predict() |>
@@ -347,14 +352,17 @@ gr_predictions <- gr_fit_workflow |>
347
352
```
348
353
<details >
349
354
<summary > Plot </summary >
355
+
356
+ Plotting the result; this is reusing some code from the landing page to print
357
+ the forecast date.
358
+
350
359
``` {r plotting}
351
- # plotting the result
352
360
forecast_date_label <-
353
361
tibble(
354
362
geo_value = rep(used_locations, 2),
355
363
.response_name = c(rep("case_rate", 4), rep("death_rate", 4)),
356
364
dates = rep(forecast_date - 7 * 2, 2 * length(used_locations)),
357
- heights = c(rep(150, 4), rep(0.40 , 4))
365
+ heights = c(rep(150, 4), rep(0.30 , 4))
358
366
)
359
367
360
368
result_plot <- autoplot(
@@ -379,11 +387,6 @@ result_plot
379
387
380
388
TODO ` get_test_data ` isn't actually working here...
381
389
382
- [ ^ 1 ] : Think of baking a cake, where adding the frosting is the last step in the process of actually baking.
383
-
384
- [ ^ 2 ] : Note that the frosting doesn't require any information about the training
385
- data, since the output of the model only depends on the model used.
386
-
387
390
## Population scaling
388
391
389
392
Suppose we're sending our predictions to someone who is looking to understand
@@ -425,3 +428,8 @@ which are 2-3 orders of magnitude larger than the corresponding rates above.
425
428
` df ` represents the scaling value; in this case it is the state populations,
426
429
while ` rate_rescaling ` gives the denominator of the rate (our fit values were
427
430
per 100,000).
431
+
432
+ [ ^ 1 ] : Think of baking a cake, where adding the frosting is the last step in the process of actually baking.
433
+
434
+ [ ^ 2 ] : Note that the frosting doesn't require any information about the training
435
+ data, since the output of the model only depends on the model used.
0 commit comments