Skip to content
Snippets Groups Projects
Commit ae5c766b authored by marius-lucas braun's avatar marius-lucas braun
Browse files

improved CO2 target plots

parent 7a0e4c9e
No related branches found
No related tags found
No related merge requests found
File added
File added
File added
File added
File added
File added
No preview for this file type
{ {
"R": { "R": {
"Version": "4.0.3", "Version": "4.3.2",
"Repositories": [ "Repositories": [
{ {
"Name": "REPO_NAME", "Name": "REPO_NAME",
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
"Packages": { "Packages": {
"MASS": { "MASS": {
"Package": "MASS", "Package": "MASS",
"Version": "7.3-53", "Version": "7.3-60",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
...@@ -22,15 +22,16 @@ ...@@ -22,15 +22,16 @@
"stats", "stats",
"utils" "utils"
], ],
"Hash": "d1bc1c8e9c0ace57ec9ffea01021d45f" "Hash": "a56a6365b3fa73293ea8d084be0d9bb0"
}, },
"Matrix": { "Matrix": {
"Package": "Matrix", "Package": "Matrix",
"Version": "1.2-18", "Version": "1.6-1.1",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R", "R",
"grDevices",
"graphics", "graphics",
"grid", "grid",
"lattice", "lattice",
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
"stats", "stats",
"utils" "utils"
], ],
"Hash": "5eefb6f276ded77fad5fff409e4f0557" "Hash": "4767d80e0dcdf2ee70bd5ed1e1d37c4a"
}, },
"R6": { "R6": {
"Package": "R6", "Package": "R6",
...@@ -107,7 +108,7 @@ ...@@ -107,7 +108,7 @@
}, },
"boot": { "boot": {
"Package": "boot", "Package": "boot",
"Version": "1.3-25", "Version": "1.3-28.1",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
...@@ -115,7 +116,7 @@ ...@@ -115,7 +116,7 @@
"graphics", "graphics",
"stats" "stats"
], ],
"Hash": "bd51734a754b6c2baf28b2d1ebc11e91" "Hash": "9a052fbcbe97a98ceb18dbfd30ebd96e"
}, },
"cli": { "cli": {
"Package": "cli", "Package": "cli",
...@@ -140,13 +141,13 @@ ...@@ -140,13 +141,13 @@
}, },
"codetools": { "codetools": {
"Package": "codetools", "Package": "codetools",
"Version": "0.2-16", "Version": "0.2-19",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
"R" "R"
], ],
"Hash": "89cf4b8207269ccf82fbeb6473fd662b" "Hash": "c089a619a7fae175d149d89164f8c7d8"
}, },
"colorspace": { "colorspace": {
"Package": "colorspace", "Package": "colorspace",
...@@ -405,7 +406,7 @@ ...@@ -405,7 +406,7 @@
}, },
"lattice": { "lattice": {
"Package": "lattice", "Package": "lattice",
"Version": "0.20-41", "Version": "0.21-9",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
...@@ -416,7 +417,7 @@ ...@@ -416,7 +417,7 @@
"stats", "stats",
"utils" "utils"
], ],
"Hash": "fbd9285028b0263d76d18c95ae51a53d" "Hash": "5558c61e0136e247252f5f952cdaad6a"
}, },
"lifecycle": { "lifecycle": {
"Package": "lifecycle", "Package": "lifecycle",
...@@ -443,7 +444,7 @@ ...@@ -443,7 +444,7 @@
}, },
"mgcv": { "mgcv": {
"Package": "mgcv", "Package": "mgcv",
"Version": "1.8-33", "Version": "1.9-0",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
...@@ -456,7 +457,7 @@ ...@@ -456,7 +457,7 @@
"stats", "stats",
"utils" "utils"
], ],
"Hash": "4794fe2a7f2a8190c52e87658b8a3d79" "Hash": "f55d28806bb2238d6aaceb58d82edaaa"
}, },
"moments": { "moments": {
"Package": "moments", "Package": "moments",
...@@ -478,7 +479,7 @@ ...@@ -478,7 +479,7 @@
}, },
"nlme": { "nlme": {
"Package": "nlme", "Package": "nlme",
"Version": "3.1-149", "Version": "3.1-163",
"Source": "Repository", "Source": "Repository",
"Repository": "CRAN", "Repository": "CRAN",
"Requirements": [ "Requirements": [
...@@ -488,7 +489,7 @@ ...@@ -488,7 +489,7 @@
"stats", "stats",
"utils" "utils"
], ],
"Hash": "7c24ab3a1e3afe50388eb2d893aab255" "Hash": "8d1938040a05566f4f7a14af4feadd6b"
}, },
"openxlsx": { "openxlsx": {
"Package": "openxlsx", "Package": "openxlsx",
......
...@@ -15,6 +15,7 @@ library(moments) ...@@ -15,6 +15,7 @@ library(moments)
library(confintr) library(confintr)
library(stringr) library(stringr)
library(dplyr) library(dplyr)
library(tibble)
font_import() font_import()
loadfonts(device = "win") loadfonts(device = "win")
...@@ -25,99 +26,139 @@ rm(list = ls()) ...@@ -25,99 +26,139 @@ rm(list = ls())
set.seed(127) set.seed(127)
# create elasticity, policy and income group names # create elasticity, policy and income group names
elasticities = c("esubd", "esubm", "esubva") params = c(
#"esubd",
#"esubm",
#"esubva",
"CO2factor"
)
policies = c("policy", "cbam") policies = c("policy", "cbam")
inc_groups = c("lo", "mi", "hi") inc_groups = c("lo", "mi", "hi")
for(i in 1:length(elasticities)) { for(i in 1:length(params)) {
# load welfare effects data frame # load welfare effects data frame
welf_name = paste("welf", elasticities[i], sep = "_") welf_name = paste("welf", params[i], sep = "_")
assign( assign(
x = welf_name, x = welf_name,
value = readRDS( value = readRDS(
paste0("prepared/", welf_name, ".rds") paste0("prepared/", welf_name, ".rds")
) )
) )
# create subdirectory for figures
dir.create(
file.path("figures", params[i]),
showWarnings = F
)
# compute bootstrap 95% confidence intervals # create plots
# and create histograms
for(j in 1:length(policies)) { for(j in 1:length(policies)) {
for(k in 1:length(inc_groups)) { for(k in 1:length(inc_groups)) {
# get welfare effect from dataframe
welf_effect_name = paste( welf_effect_name = paste(
policies[j], inc_groups[k], sep = "_" policies[j], inc_groups[k], sep = "_"
) )
welf_effect = (get(welf_name))[welf_effect_name] welf_effect = (get(welf_name))[welf_effect_name]
# compute bootstrap 95% confidence intervals # if parameter is CO2factor: line plot, else histogram
ci_value = ci_mean( plot_type = ifelse(params[i] == "CO2factor", "plot", "hist")
welf_effect[, ],
type = "bootstrap",
boot_type = "perc",
R = 1000
)
# create histogram with mean and 95% confidence intervals # create plot name
plot_name = paste("hist", plot_name = paste(
elasticities[i], plot_type,
welf_effect_name, params[i],
sep = "_" welf_effect_name,
) sep = "_"
plot_value = ggplot( )
data = get(welf_name),
aes(x = welf_effect[, ])) + # if parameter is CO2factor: create line plot
# histogram if(params[i] == "CO2factor") {
geom_histogram( plot_value = ggplot(
aes(y = after_stat(density)), data = get(welf_name)
color = "black", ) +
fill = "#AFC4DE", # line plot
bins = 15 geom_line(
aes(
x = CO2factor,
y = welf_effect[, ],
group = 1
),
color = "#36638B",
linewidth = 1
) + ) +
# mean scale_x_reverse(limits = c(NA, 0.8)) +
geom_vline( # label axes
xintercept = mean(welf_effect[, ]), labs(
color = "#36638B", x = "CO2 target",
linetype = "dashed", y = "Welfare change / %"
size = 1
) + ) +
# lower bound of 95% confidence intervals theme_minimal(base_size = 18.5)
geom_vline( } else { # else: create histogram with mean and 95% confidence intervals
xintercept = ci_value$interval[1], # compute bootstrap 95% confidence intervals
color = "black", ci_value = ci_mean(
linetype = "dashed", welf_effect[, ],
size = 1 type = "bootstrap",
boot_type = "perc",
R = 1000
)
plot_value = ggplot(
data = get(welf_name),
aes(x = welf_effect[, ])
) +
# histogram
geom_histogram(
aes(y = after_stat(density)),
color = "black",
fill = "#AFC4DE",
bins = 15
) +
# mean
geom_vline(
xintercept = mean(welf_effect[, ]),
color = "#36638B",
linetype = "dashed",
linewidth = 1
) + ) +
# lower bound of 95% confidence intervals # lower bound of 95% confidence intervals
geom_vline( geom_vline(
xintercept = ci_value$interval[2], xintercept = ci_value$interval[1],
color = "black", color = "black",
linetype = "dashed", linetype = "dashed",
size = 1 linewidth = 1
) + ) +
# label axes # lower bound of 95% confidence intervals
labs( geom_vline(
x = "Welfare change / %", xintercept = ci_value$interval[2],
y = "Density" color = "black",
linetype = "dashed",
linewidth = 1
) + ) +
# Kernel density estimation # label axes
geom_density( labs(
alpha = 0.2, x = "Welfare change / %",
color = "#36638B", y = "Density"
size = 1
) + ) +
theme_minimal(base_size = 18.5) # Kernel density estimation
geom_density(
alpha = 0.2,
color = "#36638B",
linewidth = 1
) +
theme_minimal(base_size = 18.5)
}
# save histogram as PDF # save histogram as PDF
ggsave( ggsave(
paste( file.path(
"figures", "figures",
elasticities[i], params[i],
paste0(plot_name, ".pdf"), paste0(plot_name, ".pdf")
sep = "/") )
) )
} }
} }
} }
rm(i, j, k, welf_effect_name, welf_effect, welf_name, rm(i, j, k, welf_effect_name, welf_effect, welf_name,
ci_value, plot_name, plot_value, elasticities, ci_value, plot_name, plot_value, params,
inc_groups, policies) inc_groups, policies)
\ No newline at end of file
...@@ -125,6 +125,10 @@ welf_output = foreach( ...@@ -125,6 +125,10 @@ welf_output = foreach(
"/", "/",
simplify = T simplify = T
)[, 1] )[, 1]
welf = welf %>%
tibble::rownames_to_column(var = "CO2factor") %>%
arrange(desc(CO2factor))
welf$CO2factor = as.numeric(welf$CO2factor)
} }
# name welfare effects data frame # name welfare effects data frame
......
...@@ -20,7 +20,7 @@ renv::init(bare = TRUE) ...@@ -20,7 +20,7 @@ renv::init(bare = TRUE)
# Install the packages # Install the packages
install.packages(c( install.packages(c(
"ggplot2", "readr", "extrafont", "openxlsx", "Rcpp", "tictoc", "moments", "ggplot2", "readr", "extrafont", "openxlsx", "Rcpp", "tictoc", "moments",
"confintr", "dplyr", "stringr", "foreach", "doSNOW", "parallel" "confintr", "dplyr", "stringr", "foreach", "doSNOW", "parallel", "tibble"
)) ))
# Take a snapshot of the renv # Take a snapshot of the renv
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment