Last updated: 2021-09-26

Checks: 7 0

Knit directory: emlr_obs_analysis/

This reproducible R Markdown analysis was created with workflowr (version 1.6.2). The Checks tab describes the reproducibility checks that were applied when the results were created. The Past versions tab lists the development history.


Great! Since the R Markdown file has been committed to the Git repository, you know the exact version of the code that produced these results.

Great job! The global environment was empty. Objects defined in the global environment can affect the analysis in your R Markdown file in unknown ways. For reproduciblity it’s best to always run the code in an empty environment.

The command set.seed(20210412) was run prior to running the code in the R Markdown file. Setting a seed ensures that any results that rely on randomness, e.g. subsampling or permutations, are reproducible.

Great job! Recording the operating system, R version, and package versions is critical for reproducibility.

Nice! There were no cached chunks for this analysis, so you can be confident that you successfully produced the results during this run.

Great job! Using relative paths to the files within your workflowr project makes it easier to run your code on other machines.

Great! You are using Git for version control. Tracking code development and connecting the code version to the results is critical for reproducibility.

The results in this page were generated with repository version b93e153. See the Past versions tab to see a history of the changes made to the R Markdown and HTML files.

Note that you need to be careful to ensure that all relevant files for the analysis have been committed to Git prior to generating the results (you can use wflow_publish or wflow_git_commit). workflowr only checks the R Markdown file, but you know if there are other scripts or data files that it depends on. Below is the status of the Git repository when the results were generated:


Ignored files:
    Ignored:    .Rhistory
    Ignored:    .Rproj.user/
    Ignored:    data/
    Ignored:    output/Gruber_2019_comparison/
    Ignored:    output/publication/

Untracked files:
    Untracked:  code/classic_slab_inventories.Rmd

Unstaged changes:
    Modified:   code/Workflowr_project_managment.R

Note that any generated files, e.g. HTML, png, CSS, etc., are not included in this status report because it is ok for generated content to have uncommitted changes.


These are the previous versions of the repository in which changes were made to the R Markdown (analysis/classic_budgets.Rmd) and HTML (docs/classic_budgets.html) files. If you’ve configured a remote Git repository (see ?wflow_git_remote), click on the hyperlinks in the table below to view the files as they were in that past version.

File Version Author Date Message
Rmd b93e153 jens-daniel-mueller 2021-09-26 filter MLR_basins
html 23cc3a7 jens-daniel-mueller 2021-09-26 Build site.
Rmd ed88932 jens-daniel-mueller 2021-09-26 filter MLR basins
html 0c6be7e jens-daniel-mueller 2021-09-24 Build site.
Rmd 6a79fd0 jens-daniel-mueller 2021-09-24 consider ensemble selection across all analysis
html a324ace jens-daniel-mueller 2021-09-24 Build site.
Rmd c43a6a9 jens-daniel-mueller 2021-09-24 revised ensemble selection
html f54d5db jens-daniel-mueller 2021-09-24 Build site.
Rmd 76c942b jens-daniel-mueller 2021-09-24 1990 as start year 1 for classic runs
html 31c33cb jens-daniel-mueller 2021-09-23 Build site.
Rmd 9b1df4d jens-daniel-mueller 2021-09-23 1994 vs 2014 added
html ec4f702 jens-daniel-mueller 2021-09-22 Build site.
html 6525680 jens-daniel-mueller 2021-09-21 Build site.
html 6bf38c9 jens-daniel-mueller 2021-09-21 Build site.
html 63911d0 jens-daniel-mueller 2021-09-21 Build site.
html 499c9d5 jens-daniel-mueller 2021-09-21 Build site.
html 271a3ac jens-daniel-mueller 2021-09-21 Build site.
html 35ad8b5 jens-daniel-mueller 2021-09-20 Build site.
Rmd 919f74b jens-daniel-mueller 2021-09-20 rebuildt with canyon b cleaning analysis

1 Global

1.1 Read files

# identify required version IDs

Version_IDs_1 <- list.files(path = "/nfs/kryo/work/jenmueller/emlr_cant/observations",
                            pattern = "v_10")

Version_IDs_2 <- list.files(path = "/nfs/kryo/work/jenmueller/emlr_cant/observations",
                            pattern = "v_20")

Version_IDs_3 <- list.files(path = "/nfs/kryo/work/jenmueller/emlr_cant/observations",
                            pattern = "v_30")

# Version_IDs <- c(Version_IDs_1, Version_IDs_2)
Version_IDs <- c(Version_IDs_1, Version_IDs_2, Version_IDs_3)
# rm(Version_IDs_1, Version_IDs_2)
rm(Version_IDs_1, Version_IDs_2, Version_IDs_3)

for (i_Version_IDs in Version_IDs) {
  # i_Version_IDs <- Version_IDs[1]
  
  print(i_Version_IDs)
  
  path_version_data     <-
    paste(path_observations,
          i_Version_IDs,
          "/data/",
          sep = "")
  
  # load and join data files
  
  dcant_budget_global <-
    read_csv(paste(path_version_data,
                   "dcant_budget_global.csv",
                   sep = ""))
  
  dcant_budget_global_mod_truth <-
    read_csv(paste(
      path_version_data,
      "dcant_budget_global_mod_truth.csv",
      sep = ""
    ))
  
  dcant_budget_global_bias <-
    read_csv(paste(path_version_data,
                   "dcant_budget_global_bias.csv",
                   sep = ""))
  
  dcant_budget_global <- bind_rows(dcant_budget_global,
                                      dcant_budget_global_mod_truth)
  
  dcant_budget_global <- dcant_budget_global %>%
    mutate(Version_ID = i_Version_IDs)
  
  dcant_budget_global_bias <- dcant_budget_global_bias %>%
    mutate(Version_ID = i_Version_IDs)

  params_local <-
    read_rds(paste(path_version_data,
                   "params_local.rds",
                   sep = ""))
  
  params_local <- bind_cols(
    Version_ID = i_Version_IDs,
    MLR_basins = params_local$MLR_basins,
    tref1 = params_local$tref1,
    tref2 = params_local$tref2,
    gap_filling = params_local$gap_filling,
    rarefication = params_local$rarefication,
    rarefication_threshold = params_local$rarefication_threshold,
    MLR_predictors = str_c(params_local$MLR_predictors, collapse = "+"),
    vif_max = params_local$vif_max
  )
  
  tref <- read_csv(paste(path_version_data,
                         "tref.csv",
                         sep = ""))
  
  params_local <- params_local %>%
    mutate(
      median_year_1 = sort(tref$median_year)[1],
      median_year_2 = sort(tref$median_year)[2],
      duration = median_year_2 - median_year_1,
      period = paste(median_year_1, "-", median_year_2)
    )
  
  if (exists("dcant_budget_global_all")) {
    dcant_budget_global_all <-
      bind_rows(dcant_budget_global_all, dcant_budget_global)
  }
  
  if (!exists("dcant_budget_global_all")) {
    dcant_budget_global_all <- dcant_budget_global
  }
  
  if (exists("dcant_budget_global_bias_all")) {
    dcant_budget_global_bias_all <-
      bind_rows(dcant_budget_global_bias_all,
                dcant_budget_global_bias)
  }

  if (!exists("dcant_budget_global_bias_all")) {
    dcant_budget_global_bias_all <- dcant_budget_global_bias
  }
  
  if (exists("params_local_all")) {
    params_local_all <- bind_rows(params_local_all, params_local)
  }
  
  if (!exists("params_local_all")) {
    params_local_all <- params_local
  }
  
  
}
[1] "v_1001"
[1] "v_1002"
[1] "v_1003"
[1] "v_1004"
[1] "v_1005"
[1] "v_1006"
[1] "v_1007"
[1] "v_2001"
[1] "v_2002"
[1] "v_2003"
[1] "v_2004"
[1] "v_2005"
[1] "v_2006"
[1] "v_2007"
[1] "v_3001"
[1] "v_3002"
[1] "v_3003"
[1] "v_3004"
[1] "v_3005"
[1] "v_3006"
[1] "v_3007"
rm(
  dcant_budget_global,
  dcant_budget_global_bias,
  dcant_budget_global_mod_truth,
  params_local,
  tref
)

dcant_budget_global_all <- full_join(dcant_budget_global_all,
                                     params_local_all)

dcant_budget_global_bias_all <-
  full_join(dcant_budget_global_bias_all,
            params_local_all)
dcant_budget_global_all <- dcant_budget_global_all %>%
  filter(estimate == "dcant", 
         method == "total") %>% 
  select(-c(estimate, method)) %>% 
  rename(dcant = value)

dcant_budget_global_all_depth <- dcant_budget_global_all

dcant_budget_global_all <- dcant_budget_global_all %>%
  filter(inv_depth == params_global$inventory_depth_standard)

dcant_budget_global_bias_all <- dcant_budget_global_bias_all %>%
  filter(estimate == "dcant") %>%
  select(-c(estimate))

dcant_budget_global_bias_all_depth <- dcant_budget_global_bias_all

dcant_budget_global_bias_all <- dcant_budget_global_bias_all %>%
  filter(inv_depth == params_global$inventory_depth_standard)
MLR_basins_in <- c("1", "2", "AIP", "SO", "5")

dcant_budget_global_all <- dcant_budget_global_all %>% 
  filter(MLR_basins %in% MLR_basins_in)

dcant_budget_global_bias_all <- dcant_budget_global_bias_all  %>% 
  filter(MLR_basins %in% MLR_basins_in)

1.2 Thresholds

global_bias_rel_max <- 12
regional_bias_rel_max <- 20

1.3 Individual cases

1.3.1 Absoulte values

dcant_budget_global_all %>%
  ggplot(aes(period, dcant, col = MLR_basins)) +
  geom_point() +
  scale_color_brewer(palette = "Set1", name = "basin\nseparation") +
  facet_grid(. ~ data_source)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

1.3.2 Biases

dcant_budget_global_bias_all %>%
  ggplot(aes(period, dcant_bias, col = MLR_basins)) +
  geom_hline(yintercept = 0) +
  scale_color_brewer(palette = "Set1", name = "basin\nseparation") +
  geom_point()

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
dcant_budget_global_bias_all %>%
  ggplot() +
  geom_tile(aes(y = 0, height = global_bias_rel_max * 2,
                x = "1994 - 2014", width = Inf,
                fill = "bias\nthreshold"), alpha = 0.5) +
  geom_hline(yintercept = 0) +
  scale_fill_manual(values = "grey70", name = "") +
  scale_color_brewer(palette = "Set1", name = "basin\nseparation") +
  labs(y = expression(Delta ~ C[ant] ~ bias)) +
  theme(axis.title.x = element_blank()) +
  geom_point(aes(period, dcant_bias_rel, col = MLR_basins))

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

1.4 Ensemble

ensemble_MLR_basins_global <- dcant_budget_global_bias_all %>% 
  filter(dcant_bias_rel < global_bias_rel_max) %>% 
  count(MLR_basins) %>% 
  filter(n == 3) %>% 
  pull(MLR_basins)

ensemble_MLR_basins_global
[1] "2"   "5"   "AIP" "SO" 
dcant_budget_global_ensemble <- dcant_budget_global_all %>% 
  filter(data_source %in% c("mod", "obs"),
         MLR_basins %in% ensemble_MLR_basins_global) %>% 
  group_by(data_source, period) %>% 
  summarise(dcant_mean = mean(dcant),
            dcant_sd = sd(dcant),
            dcant_range = max(dcant)- min(dcant)) %>% 
  ungroup()

1.4.1 Mean

dcant_budget_global_ensemble %>%
  ggplot(aes(period, dcant_mean)) +
  geom_pointrange(aes(ymax = dcant_mean + dcant_sd,
                      ymin = dcant_mean - dcant_sd),
                  shape = 21) +
  facet_grid(. ~ data_source)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

1.4.2 Mean bias

dcant_budget_global_ensemble_bias <- full_join(
  dcant_budget_global_ensemble %>%
    filter(data_source == "mod") %>% 
    select(period, dcant_mean, dcant_sd),
  dcant_budget_global_all %>%
    filter(data_source == "mod_truth",
           MLR_basins == "2") %>% 
    select(period, dcant)
)

dcant_budget_global_ensemble_bias <- dcant_budget_global_ensemble_bias %>% 
  mutate(dcant_mean_bias = dcant_mean - dcant,
         dcant_mean_bias_rel = 100 * dcant_mean_bias / dcant)

dcant_budget_global_ensemble_bias %>%
  ggplot(aes(period, dcant_mean_bias)) +
  geom_hline(yintercept = 0) +
  geom_point()

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
dcant_budget_global_ensemble_bias %>%
  ggplot(aes(period, dcant_mean_bias_rel)) +
  geom_hline(yintercept = 0) +
  geom_point()

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

1.4.3 SD vs bias

dcant_budget_global_ensemble_bias %>% 
  ggplot(aes(dcant_mean_bias, dcant_sd, col = period)) +
  geom_point() +
  xlim(0, NA) +
  ylim(0, NA)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

1.5 Vertical patterns

1.5.1 Absoulte values

dcant_budget_global_all_depth %>%
  filter(MLR_basins %in% ensemble_MLR_basins_global) %>% 
  group_by(data_source) %>%
  group_split() %>%
  # head(1) %>%
  map(
    ~  ggplot(data = .x,
              aes(dcant, MLR_basins, fill=period)) +
      geom_vline(xintercept = 0) +
      geom_col(position = "dodge") +
      scale_fill_brewer(palette = "Dark2") +
      facet_grid(inv_depth ~ .) +
      labs(title = paste("data_source:", unique(.x$data_source)))
  )
[[1]]

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

[[2]]

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

[[3]]

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

1.5.2 Biases

dcant_budget_global_bias_all_depth %>%
    filter(MLR_basins %in% ensemble_MLR_basins_global) %>% 
  ggplot(aes(dcant_bias, MLR_basins, fill=period)) +
  geom_vline(xintercept = 0) +
  geom_col(position = "dodge") +
  scale_fill_brewer(palette = "Dark2") +
  facet_grid(inv_depth ~ .)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
dcant_budget_global_bias_all_depth %>%
    filter(MLR_basins %in% ensemble_MLR_basins_global) %>% 
  ggplot(aes(dcant_bias_rel, MLR_basins, fill = period)) +
  geom_vline(xintercept = 0) +
  geom_col(position = "dodge") +
  scale_fill_brewer(palette = "Dark2") +
  facet_grid(inv_depth ~ .)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
rm(dcant_budget_global_all,
   dcant_budget_global_all_depth,
   dcant_budget_global_bias_all,
   dcant_budget_global_bias_all_depth,
   dcant_budget_global_ensemble,
   dcant_budget_global_ensemble_bias,
   params_local_all)

2 Regional

2.1 Read files

# Version_IDs <- Version_IDs[1:length(Version_IDs)-1]

for (i_Version_IDs in Version_IDs) {
  # i_Version_IDs <- Version_IDs[1]
  
  print(i_Version_IDs)
  
  path_version_data     <-
    paste(path_observations,
          i_Version_IDs,
          "/data/",
          sep = "")
  
  # load and join data files
  
  dcant_budget_basin_AIP <-
    read_csv(paste(path_version_data,
                   "dcant_budget_basin_AIP.csv",
                   sep = ""))
  
  dcant_budget_basin_AIP_mod_truth <-
    read_csv(paste(
      path_version_data,
      "dcant_budget_basin_AIP_mod_truth.csv",
      sep = ""
    ))
  
  dcant_budget_basin_AIP_bias <-
    read_csv(paste(path_version_data,
                   "dcant_budget_basin_AIP_bias.csv",
                   sep = ""))
  
  dcant_budget_basin_AIP <- bind_rows(dcant_budget_basin_AIP,
                                      dcant_budget_basin_AIP_mod_truth)
  
  dcant_budget_basin_AIP <- dcant_budget_basin_AIP %>%
    mutate(Version_ID = i_Version_IDs)
  
  dcant_budget_basin_AIP_bias <- dcant_budget_basin_AIP_bias %>%
    mutate(Version_ID = i_Version_IDs)
  
  params_local <-
    read_rds(paste(path_version_data,
                   "params_local.rds",
                   sep = ""))
  
  params_local <- bind_cols(
    Version_ID = i_Version_IDs,
    MLR_basins = params_local$MLR_basins,
    tref1 = params_local$tref1,
    tref2 = params_local$tref2,
    gap_filling = params_local$gap_filling,
    rarefication = params_local$rarefication,
    rarefication_threshold = params_local$rarefication_threshold,
    MLR_predictors = str_c(params_local$MLR_predictors, collapse = "+"),
    vif_max = params_local$vif_max
  )
  
  tref <- read_csv(paste(path_version_data,
                         "tref.csv",
                         sep = ""))
  
  params_local <- params_local %>%
    mutate(
      median_year_1 = sort(tref$median_year)[1],
      median_year_2 = sort(tref$median_year)[2],
      duration = median_year_2 - median_year_1,
      period = paste(median_year_1, "-", median_year_2)
    )
  
  if (exists("dcant_budget_basin_AIP_all")) {
    dcant_budget_basin_AIP_all <-
      bind_rows(dcant_budget_basin_AIP_all, dcant_budget_basin_AIP)
  }
  
  if (!exists("dcant_budget_basin_AIP_all")) {
    dcant_budget_basin_AIP_all <- dcant_budget_basin_AIP
  }
  
  if (exists("dcant_budget_basin_AIP_bias_all")) {
    dcant_budget_basin_AIP_bias_all <-
      bind_rows(dcant_budget_basin_AIP_bias_all,
                dcant_budget_basin_AIP_bias)
  }
  
  if (!exists("dcant_budget_basin_AIP_bias_all")) {
    dcant_budget_basin_AIP_bias_all <- dcant_budget_basin_AIP_bias
  }
  
  if (exists("params_local_all")) {
    params_local_all <- bind_rows(params_local_all, params_local)
  }
  
  if (!exists("params_local_all")) {
    params_local_all <- params_local
  }
  
  
}
[1] "v_1001"
[1] "v_1002"
[1] "v_1003"
[1] "v_1004"
[1] "v_1005"
[1] "v_1006"
[1] "v_1007"
[1] "v_2001"
[1] "v_2002"
[1] "v_2003"
[1] "v_2004"
[1] "v_2005"
[1] "v_2006"
[1] "v_2007"
[1] "v_3001"
[1] "v_3002"
[1] "v_3003"
[1] "v_3004"
[1] "v_3005"
[1] "v_3006"
[1] "v_3007"
rm(
  dcant_budget_basin_AIP,
  dcant_budget_basin_AIP_bias,
  dcant_budget_basin_AIP_mod_truth,
  params_local,
  tref
)

dcant_budget_basin_AIP_all <- full_join(dcant_budget_basin_AIP_all,
                                        params_local_all)

dcant_budget_basin_AIP_bias_all <-
  full_join(dcant_budget_basin_AIP_bias_all,
            params_local_all)
dcant_budget_basin_AIP_all <- dcant_budget_basin_AIP_all %>%
  filter(estimate == "dcant", 
         method == "total") %>% 
  select(-c(estimate, method)) %>% 
  rename(dcant = value)

dcant_budget_basin_AIP_all_depth <- dcant_budget_basin_AIP_all

dcant_budget_basin_AIP_all <- dcant_budget_basin_AIP_all %>%
  filter(inv_depth == params_global$inventory_depth_standard)

dcant_budget_basin_AIP_bias_all <- dcant_budget_basin_AIP_bias_all %>%
  filter(estimate == "dcant") %>% 
  select(-c(estimate))

dcant_budget_basin_AIP_bias_all_depth <- dcant_budget_basin_AIP_bias_all

dcant_budget_basin_AIP_bias_all <- dcant_budget_basin_AIP_bias_all %>%
  filter(inv_depth == params_global$inventory_depth_standard)
dcant_budget_basin_AIP_all <- dcant_budget_basin_AIP_all %>% 
  filter(MLR_basins %in% MLR_basins_in)

dcant_budget_basin_AIP_bias_all <- dcant_budget_basin_AIP_bias_all  %>% 
  filter(MLR_basins %in% MLR_basins_in)

2.2 Individual cases

2.2.1 Absoulte values

dcant_budget_basin_AIP_all %>%
  ggplot(aes(period, dcant, col=MLR_basins)) +
  geom_point() +
  facet_grid(basin_AIP ~ data_source)

Version Author Date
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

2.2.2 Biases

dcant_budget_basin_AIP_bias_all %>%
  ggplot(aes(period, dcant_bias, col=MLR_basins)) +
  geom_hline(yintercept = 0) +
  geom_point() +
  facet_grid(basin_AIP ~ .)

Version Author Date
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
dcant_budget_basin_AIP_bias_all %>%
  ggplot(aes(period, dcant_bias_rel, col=MLR_basins)) +
  geom_hline(yintercept = 0) +
  geom_point() +
  facet_grid(basin_AIP ~ .)

Version Author Date
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
dcant_budget_basin_AIP_bias_all %>%
  ggplot() +
  geom_tile(aes(y = 0, height = regional_bias_rel_max * 2,
                x = "1994 - 2014", width = Inf,
                fill = "bias\nthreshold"), alpha = 0.5) +
  geom_hline(yintercept = 0) +
  scale_fill_manual(values = "grey70", name = "") +
  scale_color_brewer(palette = "Set1", name = "basin\nseparation") +
  labs(y = expression(Delta ~ C[ant] ~ bias)) +
  theme(axis.title.x = element_blank()) +
  geom_point(aes(period, dcant_bias_rel, col = MLR_basins)) +
  facet_grid(basin_AIP ~ .)

Version Author Date
a324ace jens-daniel-mueller 2021-09-24

2.3 Ensemble

dcant_budget_basin_AIP_bias_all %>% 
  filter(dcant_bias_rel < regional_bias_rel_max) %>% 
  distinct(period, MLR_basins, basin_AIP)
# A tibble: 44 × 3
   basin_AIP MLR_basins period     
   <chr>     <chr>      <chr>      
 1 Indian    1          2004 - 2014
 2 Pacific   1          2004 - 2014
 3 Atlantic  1          2004 - 2014
 4 Indian    2          2004 - 2014
 5 Pacific   2          2004 - 2014
 6 Atlantic  2          2004 - 2014
 7 Indian    AIP        2004 - 2014
 8 Pacific   AIP        2004 - 2014
 9 Atlantic  AIP        2004 - 2014
10 Indian    5          2004 - 2014
# … with 34 more rows
ensemble_MLR_basins_regional <- dcant_budget_basin_AIP_bias_all %>% 
  filter(dcant_bias_rel < regional_bias_rel_max) %>% 
  count(MLR_basins) %>% 
  filter(n == 9) %>% 
  pull(MLR_basins)


ensemble_MLR_basins_regional <-
  intersect(ensemble_MLR_basins_global, ensemble_MLR_basins_regional)

ensemble_MLR_basins_regional
[1] "2"   "5"   "AIP" "SO" 
dcant_budget_basin_AIP_ensemble <- dcant_budget_basin_AIP_all %>% 
  filter(data_source %in% c("mod", "obs"),
         MLR_basins %in% ensemble_MLR_basins_global,
         MLR_basins %in% ensemble_MLR_basins_regional) %>% 
  group_by(basin_AIP, data_source, period) %>% 
  summarise(dcant_mean = mean(dcant),
            dcant_sd = sd(dcant),
            dcant_range = max(dcant)- min(dcant)) %>% 
  ungroup()

2.3.1 Mean

dcant_budget_basin_AIP_ensemble %>%
  ggplot(aes(period, dcant_mean, col=basin_AIP)) +
  geom_pointrange(aes(ymax = dcant_mean + dcant_sd,
                      ymin = dcant_mean - dcant_sd),
                  shape = 21) +
  facet_grid(. ~ data_source)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

2.3.2 Mean bias

dcant_budget_basin_AIP_ensemble_bias <- full_join(
  dcant_budget_basin_AIP_ensemble %>%
    filter(data_source == "mod") %>% 
    select(basin_AIP, period, dcant_mean, dcant_sd),
  dcant_budget_basin_AIP_all %>%
    filter(data_source == "mod_truth",
           MLR_basins == "2") %>% 
    select(basin_AIP, period, dcant)
)

dcant_budget_basin_AIP_ensemble_bias <- dcant_budget_basin_AIP_ensemble_bias %>% 
  mutate(dcant_mean_bias = dcant_mean - dcant,
         dcant_mean_bias_rel = 100 * dcant_mean_bias / dcant)


dcant_budget_basin_AIP_ensemble_bias %>%
  ggplot(aes(period, dcant_mean_bias, col = basin_AIP)) +
  geom_hline(yintercept = 0) +
  geom_point()

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
dcant_budget_basin_AIP_ensemble_bias %>%
  ggplot(aes(period, dcant_mean_bias_rel, col = basin_AIP)) +
  geom_hline(yintercept = 0) +
  geom_point()

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24

2.3.3 SD vs bias

dcant_budget_basin_AIP_ensemble_bias %>% 
  ggplot(aes(dcant_mean_bias, dcant_sd, col=basin_AIP)) +
  geom_point() +
  facet_grid(. ~ period) +
  xlim(0, NA) +
  ylim(0, NA)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

2.4 Vertical patterns

2.4.1 Absoulte values

unique(
dcant_budget_basin_AIP_all_depth$MLR_basins)
[1] "1"      "2"      "AIP"    "5"      "SO"     "SO_5"   "SO_AIP"
dcant_budget_basin_AIP_all_depth %>%
  filter(
    MLR_basins %in% ensemble_MLR_basins_global,
    MLR_basins %in% ensemble_MLR_basins_regional
  ) %>%
  group_by(data_source) %>%
  group_split() %>%
  head(1) %>%
  map(
    ~  ggplot(data = .x,
              aes(dcant, MLR_basins, fill = basin_AIP)) +
      geom_vline(xintercept = 0) +
      geom_col() +
      scale_fill_brewer(palette = "Dark2") +
      facet_grid(inv_depth ~ period) +
      labs(title = paste("data_source:", unique(.x$data_source)))
  )
[[1]]

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

2.4.2 Biases

dcant_budget_basin_AIP_bias_all_depth %>%
  filter(
    MLR_basins %in% ensemble_MLR_basins_global,
    MLR_basins %in% ensemble_MLR_basins_regional
  ) %>%
  ggplot(aes(dcant_bias, MLR_basins, fill = basin_AIP)) +
  geom_vline(xintercept = 0) +
  geom_col() +
  scale_fill_brewer(palette = "Dark2") +
  facet_grid(inv_depth ~ period)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20
dcant_budget_basin_AIP_bias_all_depth %>%
  filter(
    MLR_basins %in% ensemble_MLR_basins_global,
    MLR_basins %in% ensemble_MLR_basins_regional
  ) %>%
  ggplot(aes(dcant_bias_rel, MLR_basins, fill = basin_AIP)) +
  geom_vline(xintercept = 0) +
  geom_col() +
  scale_fill_brewer(palette = "Dark2") +
  facet_grid(inv_depth ~ period)

Version Author Date
23cc3a7 jens-daniel-mueller 2021-09-26
a324ace jens-daniel-mueller 2021-09-24
f54d5db jens-daniel-mueller 2021-09-24
31c33cb jens-daniel-mueller 2021-09-23
35ad8b5 jens-daniel-mueller 2021-09-20

3 Write ensemble members

ensemble_MLR_basins_regional %>% 
  write_rds("data/ensemble_members.rds")

sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-pc-linux-gnu (64-bit)
Running under: openSUSE Leap 15.2

Matrix products: default
BLAS:   /usr/local/R-4.0.3/lib64/R/lib/libRblas.so
LAPACK: /usr/local/R-4.0.3/lib64/R/lib/libRlapack.so

locale:
 [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
 [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
 [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
 [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
 [9] LC_ADDRESS=C               LC_TELEPHONE=C            
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
 [1] ggforce_0.3.3   metR_0.9.0      scico_1.2.0     patchwork_1.1.1
 [5] collapse_1.5.0  forcats_0.5.0   stringr_1.4.0   dplyr_1.0.5    
 [9] purrr_0.3.4     readr_1.4.0     tidyr_1.1.3     tibble_3.1.3   
[13] ggplot2_3.3.5   tidyverse_1.3.0 workflowr_1.6.2

loaded via a namespace (and not attached):
 [1] httr_1.4.2               sass_0.4.0               jsonlite_1.7.1          
 [4] modelr_0.1.8             bslib_0.2.5.1            assertthat_0.2.1        
 [7] highr_0.8                blob_1.2.1               cellranger_1.1.0        
[10] yaml_2.2.1               pillar_1.6.2             backports_1.1.10        
[13] lattice_0.20-41          glue_1.4.2               RcppEigen_0.3.3.7.0     
[16] digest_0.6.27            RColorBrewer_1.1-2       promises_1.1.1          
[19] polyclip_1.10-0          checkmate_2.0.0          rvest_0.3.6             
[22] colorspace_2.0-2         htmltools_0.5.1.1        httpuv_1.5.4            
[25] Matrix_1.2-18            pkgconfig_2.0.3          broom_0.7.9             
[28] haven_2.3.1              scales_1.1.1             tweenr_1.0.2            
[31] whisker_0.4              later_1.2.0              git2r_0.27.1            
[34] farver_2.0.3             generics_0.1.0           ellipsis_0.3.2          
[37] withr_2.3.0              cli_3.0.1                magrittr_1.5            
[40] crayon_1.3.4             readxl_1.3.1             evaluate_0.14           
[43] fs_1.5.0                 fansi_0.4.1              MASS_7.3-53             
[46] xml2_1.3.2               RcppArmadillo_0.10.1.2.0 tools_4.0.3             
[49] data.table_1.14.0        hms_0.5.3                lifecycle_1.0.0         
[52] munsell_0.5.0            reprex_0.3.0             compiler_4.0.3          
[55] jquerylib_0.1.4          rlang_0.4.11             grid_4.0.3              
[58] rstudioapi_0.13          labeling_0.4.2           rmarkdown_2.10          
[61] gtable_0.3.0             DBI_1.1.0                R6_2.5.0                
[64] lubridate_1.7.9          knitr_1.33               utf8_1.1.4              
[67] rprojroot_2.0.2          stringi_1.5.3            parallel_4.0.3          
[70] Rcpp_1.0.5               vctrs_0.3.8              dbplyr_1.4.4            
[73] tidyselect_1.1.0         xfun_0.25