forked from frec-5174/eco4cast-in-R-book
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpulling-together2.qmd
99 lines (73 loc) · 4.22 KB
/
pulling-together2.qmd
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
# Putting it together: Analyzing forecasts {#sec-analysis}
The scores for the forecast generated by the book have been found in the [catalog](https://radiantearth.github.io/stac-browser/#/external/raw.githubusercontent.com/eco4cast/neon4cast-ci/main/catalog/scores/models/model_items/bookcast_forest.json). The catalog provides metadata and code that is used for data access.
## Analyzing submitted forecasts
```{r}
#| echo: false
#| message: false
library(tidyverse)
library(lubridate)
```
The code to download all forecasts generated by the model used in this book is:
```{r}
all_results <- arrow::open_dataset("s3://anonymous@bio230014-bucket01/challenges/scores/parquet/project_id=neon4cast/duration=P1D/variable=nee/model_id=bookcast_forest?endpoint_override=sdsc.osn.xsede.org")
df <- all_results |>
filter(site_id == "OSBS") |>
collect()
```
The code above can be found in the catalog link at the top of the page.
## Aggregated scores
We can look at the mean score for the process model but this provides very little context for the quality of forecast. It is more informative to compare the score to the score from other models.
```{r}
df |>
summarise(mean_crps = mean(crps, na.rm = TRUE))
```
## Comparing to baselines
We will benchmark our process model forecast against to two "naive" baselines of `climatology` and `persistenceRW`.
```{r}
all_results <- arrow::open_dataset("s3://anonymous@bio230014-bucket01/challenges/scores/parquet/project_id=neon4cast/duration=P1D/variable=nee?endpoint_override=sdsc.osn.xsede.org")
df_with_baselines <- all_results |>
filter(site_id == "OSBS",
model_id %in% c("bookcast_forest", "climatology", "persistenceRW")) |>
collect()
```
## Aggregated scores
We can first look at the aggregated scores (all reference_datetime and datetime combinations). Importantly, the code below uses `pivot_wider` and `pivot_longer` to ensure we only include datetimes where all three models provided forecasts. Otherwise there would be different periods from the three models in the aggregated score.
```{r}
df_with_baselines |>
select(model_id, crps, datetime, reference_datetime) |>
pivot_wider(names_from = model_id, values_from = crps) |>
na.omit() |>
pivot_longer(-c(datetime, reference_datetime), names_to = "model_id", values_to = "crps") |>
summarise(mean_crps = mean(crps), .by = c("model_id")) |>
ggplot(aes(x = model_id, y = mean_crps)) +
geom_bar(stat="identity")
```
## By horizon
How does forecast performance change as forecasts extend farther in the future (increasing horizon), regardless of when the forecast was produced?
```{r}
df_with_baselines |>
mutate(horizon = as.numeric(datetime - reference_datetime) / 86400) |>
select(model_id, horizon, datetime, reference_datetime, crps) |>
pivot_wider(names_from = model_id, values_from = crps) |>
na.omit() |>
pivot_longer(-c(horizon, datetime, reference_datetime), names_to = "model_id", values_to = "crps") |>
summarize(mean_crps = mean(crps), .by = c("model_id", "horizon")) |>
ggplot(aes(x = horizon, y = mean_crps, color = model_id)) +
geom_line()
```
## By reference datetime
How does forecast performance vary across the dates that the forecasts are generated, regardless of horizon?
```{r}
df_with_baselines |>
select(model_id, datetime, reference_datetime, crps) |>
pivot_wider(names_from = model_id, values_from = crps) |>
na.omit() |>
pivot_longer(-c(datetime, reference_datetime), names_to = "model_id", values_to = "crps") |>
summarize(mean_crps = mean(crps), .by = c("model_id", "reference_datetime")) |>
ggplot(aes(x = reference_datetime, y = mean_crps, color = model_id)) +
geom_line()
```
## Additional comparsions
Forecasts can be compared across `site_id` (aggregating across all `reference_datetime` and `horizon`) if there are multiple sites and `datetime` (aggregating across all `horizon`). Since CRPS is in the naive units of the variable, it can not be compared across variables.
## Reading
Lewis, A. S. L., Woelmer, W. M., Wander, H. L., Howard, D. W., Smith, J. W., McClure, R. P., et al. (2022). Increased adoption of best practices in ecological forecasting enables comparisons of forecastability. Ecological Applications, 32(2), e02500. <https://doi.org/10.1002/eap.2500>