You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Build and save dataset of ECS values from different ECS configuraiton distirbutions as provided by S20 supplemental information.
12
+
Build and save data set of ECS values from different ECS configuration distributions as provided by S20 supplemental information.
13
13
14
14
# Building data set
15
15
16
16
Here we are building ECS data sets for each of the evidence configurations of interest. We are using data from [Sherwood et al. 2020](https://agupubs.onlinelibrary.wiley.com/doi/full/10.1029/2019RG000678) henceforth referred to as S20. The data was drawn from the supplemental information in S20 and represents ECS percentile estimates from likelihood distributions quantified in S20 for each of the five evidence configurations (each containing different combinations of lines of evidence). There are other configurations available in S20 beyond the five we have chosen here. The percentile estimates reported in this data represent the 5th, 10th, 17th, 20th, 25th, 50th, 75th, 80th, 83rd, 80th, and 95th percentile, as well as the mode and the mean.
17
17
18
-
Names of each vector list are coded to represent the evidence configuration the data are associated with.
19
-
20
18
```{r}
21
19
ecs_data_list <- list(
22
20
"Baseline" = c(
@@ -90,5 +88,5 @@ ecs_data_list <- list(
90
88
Write data frame and store in the `data` directory.
The goal of this script is to fit and easy to sample parametric distribution to the ECS values provided in S20. We will then sample the distributions, save the data, and visualize them.
13
13
14
+
## Source all setup, mapping, and helper functions stored in `sourced`
14
15
```{r}
15
-
library(MASS)
16
+
source("sourced/source_all.R")
16
17
```
17
18
18
19
# Fit Distribution to Sherwood et al. 2020 data
@@ -25,7 +26,7 @@ Some notes on `fitdistr()` usage: The function fits a maximum likelihood distrib
@@ -70,10 +71,6 @@ The result is a new list (`ecs_sample_list`) of data frames, one for each eviden
70
71
71
72
# Visualize Simulated Samples
72
73
73
-
```{r}
74
-
library(ggplot2)
75
-
```
76
-
77
74
Once the ECS samples are produced and stored in a list of data frames (`ecs_sample_list`), we visualize the sample distribution with `ggplot2`.
78
75
79
76
Before working in `ggplot2`, we build a single data frame with all samples and the name of the evidence configurations fro each sample to make it easier to plot.
Here we want to determine the optimal distribution hyperparameters for a skew normal distribution that meets specified quantile requirements. For this task we utilize the `sn` and `optimx` packages. The objective it to fit a skew normal distribution such that at quantile 5%, 50%, and 95% reflect IPCC ECS range (3, 2-5).
127
124
128
-
129
-
We need the following packages:
130
-
```{r}
131
-
# Load the required libraries
132
-
library(sn)
133
-
library(optimx)
134
-
135
-
```
136
-
137
125
## Define objective function
138
126
139
-
Define an objective function to quantify the deviation of the quantiles for the skew normal distribution from the desired IPCC values.
140
-
141
-
```{r}
142
-
# Objective function to find the optimal xi, omega, and alpha
143
-
objective_function <- function(params) {
144
-
xi <- params[1]
145
-
omega <- params[2]
146
-
alpha <- params[3]
147
-
148
-
# Calculate the quantiles for the given parameters
We define an objective function to quantify the deviation of the quantiles for the skew normal distribution from the desired IPCC values. This function is stored in `sourced/helper_functions.R`.
168
128
169
129
Here, the hyperparameters (`xi`, `omega`, and `alpha`) represent the location, scale, and shape of the skew normal distribution, respectively. The function computes quantiles for the 5th, 50th, and 95th percentiles from the skew normal distribution provided initial hyperparameters (`qsn()`). It then compares these values to the targeted IPCC values (3.0, 2.0-5.0) by calculating squared differences. This approach allows us to determine how well the hyperparameters of the skew normal distribution align with the desired percentiles.
170
130
@@ -233,7 +193,7 @@ print(likely)
233
193
```
234
194
Here we can see that the very likely distribution aligns exactly with the IPCC expectation. However, the likely range is slightly more constrained that what has been proposed by IPCC AR6.
235
195
236
-
## Visualize the distribution
196
+
## preliminary visualization of the distribution
237
197
```{r}
238
198
# convert the data to data frame
239
199
IPCC_est_df <- data.frame(ECS = data)
@@ -249,18 +209,13 @@ ECS_sn <-
249
209
xlim = c(2.0, 5.0), fill = "#F21A00", alpha = 0.5) + # Shade area between 2.0 and 5.0
Produce a figure with the ECS samples. This may serve as a good supplemental figure for the paper to show the distribution shapes for the evidence configurations from S20, based on gamma distribution assumption.
13
13
14
-
```{r}
15
-
library(tidyverse)
16
-
```
17
14
# Produce figure
18
15
19
16
We produce PDF curves in a panel using the color palette and then save the figure in the `figures` directory.
The goal of this script is to run Matilda with each of the ECS distributions we sampled prior.
13
13
14
-
```{r}
15
-
library(matilda)
16
-
options(matilda.verbose = FALSE)
17
-
library(parallel)
18
-
library(tidyverse)
19
-
```
20
-
21
14
# Using ECS samples to run Matilda
22
15
23
16
We use ECS values sampled from the estimated parametric distributions from S20 to propagate the varying levels of uncertainty associated with evidence configurations to probabilistic climate projections. This provides an opportunity to better understand how different ECS evidence configurations affect temperature trajectories from a simple carbon cycle climate model.
@@ -45,8 +38,6 @@ The result will be a new core object that can will be a required input to run th
45
38
46
39
# Generate values for other model parameters
47
40
48
-
**This needs to be edited** I think for this experiment it will be more straight forward to keep all parameters aside from ECS fixed. This will reduce the complexity that is introduced from parameter interactions and will isolate the affect of the ECS distributions from different ECS evidence configurations. Below are notes that will be edited accordingly and the code chunk in this section will be skipped.
49
-
50
41
Matilda works by running Hector multiple times to build a perturbed parameter ensemble, thus applying parameter uncertainty to model outputs. We need to produce parameter values to accompany the ECS values we sampled in previous steps of the workflow.
51
42
52
43
Parameter sets are generated in Matilda using `generate_params`. We use this function to produce `n` initial parameter sets (`init_params`). In this analysis I do not think I am going to run samples of the other parameters. Instead we can isolate the behavior of Hector to different ECS distributions by using Hector defaults for all parameters aside from ECS.
Constrained weights can be merged with the constrained results. This would produce a list (based on ECS scenario) of the constrained model ensemble and the assigned weights for each run. However, because some of the models have been filtered out during the constraint, need to re-normalize so weights sum to 1. This way we can still use the resulting ensembles to compute metrics and probabilities accurately.
@@ -278,6 +279,10 @@ weighted_ensemble <- Map(function(a, b) {
278
279
279
280
}, constrained_weights, model_result)
280
281
282
+
```
283
+
284
+
Sanity check to ensure names are correct and re-weighted ensemble sums to 1.0:
0 commit comments