Skip to content

Commit 3cac099

Browse files
committed
missing fn and helper var definitions
1 parent 3f455e7 commit 3cac099

File tree

4 files changed

+47
-32
lines changed

4 files changed

+47
-32
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ _site
2828
.Rdata
2929

3030
/.quarto/
31+
32+
/_*.local

slides/day1-afternoon.qmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2432,4 +2432,4 @@ cowplot::plot_grid(p1, p2)
24322432
* Group built [`{rtestim}`](https://dajmcdon.github.io/rtestim) doing for this nonparametrically.
24332433
24342434
* We may come back to this later...
2435-
-->
2435+
-->

slides/day1-morning.qmd

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -401,34 +401,6 @@ weekly_snapshots |>
401401

402402
**Example**: A signal based on insurance claims may take several days to appear as claims are processed
403403

404-
<!--
405-
## Latency and revision in signals - Example
406-
407-
* Recall the first example of panel & versioned data we've seen...
408-
409-
```{r latency-ca-june1}
410-
#| echo: false
411-
lat_ca_june1 <- dv_ca |>
412-
filter(time_value == "2020-06-01") |>
413-
summarise(min(version - time_value)) |>
414-
pull() |> as.numeric()
415-
```
416-
417-
* On June 1, this signal is subject to [**revision**]{.primary} over time (ex. consider Dec. 1's `percent_cli` across `version`):
418-
419-
```{r revision-ca-ex}
420-
#| echo: false
421-
head(x_dt_with_diff) |> as_tibble()
422-
```
423-
424-
and `r lat_ca_june1` days [**latent**]{.primary}: `min(version - time_value)`
425-
426-
```{r latency-ca-ex}
427-
#| echo: false
428-
x_dt_with_diff <- dv_ca |> mutate(version_time_diff = version - time_value)
429-
head(x_dt_with_diff |> group_by(time_value) |> slice(1) |> ungroup())
430-
```
431-
-->
432404

433405
<!--
434406
## Revision triangle, Outpatient visits in WA 2022
@@ -508,7 +480,7 @@ A forecast that is made today can only use data we have access to today
508480

509481
1. [**Sources that don't revise**]{.primary} (provisional and final are the same)
510482

511-
Facebook Survey and Google symptoms
483+
Google symptoms
512484

513485
2. [**Predictable revisions**]{.secondary}
514486

slides/day2-afternoon.qmd

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -647,6 +647,41 @@ pred_arx_hosp |>
647647
theme(legend.title = element_blank())
648648
```
649649

650+
```{r function errors}
651+
MSE <- function(truth, prediction) {
652+
mean((truth - prediction)^2)}
653+
654+
MAE <- function(truth, prediction) {
655+
mean(abs(truth - prediction))}
656+
657+
MAPE <- function(truth, prediction) {
658+
100 * mean(abs(truth - prediction) / truth)}
659+
660+
MASE <- function(truth, prediction) {
661+
100 * MAE(truth, prediction) / mean(abs(diff(truth)))}
662+
663+
getErrors <- function(truth, prediction, type) {
664+
return(data.frame(#"MSE" = MSE(truth, prediction),
665+
"MAE"= MAE(truth, prediction),
666+
#"MAPE" = MAPE(truth, prediction),
667+
"MASE" = MASE(truth, prediction),
668+
row.names = type))
669+
}
670+
671+
getAccuracy = function(finalized, predictions, row_name = "") {
672+
observed = (finalized |>
673+
filter(time_value %in% predictions$target_date))$deaths
674+
return(cbind(
675+
getErrors(observed, predictions$.pred, ""),
676+
"Coverage" = mean(observed >= predictions$`0.1` & observed <= predictions$`0.9`),
677+
row.names = row_name))
678+
}
679+
```
680+
681+
```{r error-arx}
682+
getAccuracy(ca, pred_arx)
683+
```
684+
650685
Quite different predictions!
651686

652687
## Customizing `arx_forecaster`
@@ -676,7 +711,7 @@ pred_arx_hosp <- covid_archive_dv |> epix_slide(
676711

677712
```{r arx-with-more-lags-plot}
678713
#| fig-align: left
679-
pred_arx_more_lags |>
714+
pred_arx_hosp |>
680715
ggplot(aes(target_date, .pred)) +
681716
geom_line(data = ca, aes(x = time_value, y = deaths), inherit.aes = FALSE, col = base) +
682717
geom_line(col = primary) +
@@ -689,7 +724,7 @@ pred_arx_more_lags |>
689724
```
690725

691726
```{r error-arx-more-lags}
692-
getAccuracy(ca, pred_arx_more_lags)
727+
getAccuracy(ca, pred_arx_hosp)
693728
```
694729

695730

@@ -768,6 +803,12 @@ Color corresponds to `forecast_date`
768803

769804
## Geo-pooling
770805

806+
```{r}
807+
#| echo: false
808+
h <- 28 # horizon
809+
w <- 120 + h # trailing window length
810+
```
811+
771812
```{r arx-geo-pooling}
772813
#| echo: true
773814
#| code-line-numbers: "1"

0 commit comments

Comments
 (0)