2020-09-24 10:39:48 +00:00
|
|
|
|
sum(x1_array_forward_shooting<0)
|
|
|
|
|
x3_array_forward_shooting[l]
|
|
|
|
|
x3_growth = (x3_array_forward_shooting[l]-x3_array_forward_shooting[l-1])/x3_array_forward_shooting[l-1]/(1*stepsize)
|
|
|
|
|
x3_growth
|
|
|
|
|
sum(x3_array_forward_shooting<0)
|
|
|
|
|
a1_growth = (a1_array_forward_shooting[l]-a1_array_forward_shooting[l-1])/a1_array_forward_shooting[l-1]/stepsize
|
|
|
|
|
a1_growth
|
|
|
|
|
a3_growth = (a3_array_forward_shooting[l]-a3_array_forward_shooting[l-1])/a3_array_forward_shooting[l-1]/stepsize
|
|
|
|
|
a3_growth
|
|
|
|
|
a1_array_forward_shooting[l]/x1_array_forward_shooting[l]
|
2021-03-09 17:04:26 +00:00
|
|
|
|
plot((a1_array_forward_shooting/x1_array_forward_shooting)[(l-100)-l])
|
2020-09-24 10:39:48 +00:00
|
|
|
|
# Forward shooting
|
|
|
|
|
options(digits=7)
|
|
|
|
|
## Evolution
|
|
|
|
|
x1_array_forward_shooting <- c()
|
|
|
|
|
x3_array_forward_shooting <- c()
|
|
|
|
|
a1_array_forward_shooting <- c()
|
|
|
|
|
a3_array_forward_shooting <- c()
|
|
|
|
|
s1_array_forward_shooting <- c()
|
|
|
|
|
s3_array_forward_shooting <- c()
|
|
|
|
|
x1_t = x1_init
|
|
|
|
|
x3_t = x3_init
|
|
|
|
|
#stepsize
|
|
|
|
|
comienzo = Sys.time()
|
|
|
|
|
max = max(times_forward_shooting)
|
|
|
|
|
for(t in times_forward_shooting){
|
|
|
|
|
if((100*t/max) %in% seq(from=0, to=100, by=1)){
|
|
|
|
|
cat(paste(floor(100*t/max), "%", sep=""))
|
|
|
|
|
cat("\n")
|
|
|
|
|
}
|
|
|
|
|
a1_t = a1(t)
|
|
|
|
|
a3_t = a3(t)
|
|
|
|
|
s1_t = s1(t)
|
|
|
|
|
s3_t = s3(t)
|
|
|
|
|
x1_t = x1_t*(1+r1_stepsize) + dx1(t)*stepsize
|
|
|
|
|
x3_t = x3_t*(1+r3_stepsize) + dx3(t)*stepsize
|
|
|
|
|
a1_array_forward_shooting <- c(a1_array_forward_shooting, a1_t)
|
|
|
|
|
a3_array_forward_shooting <- c(a3_array_forward_shooting, a3_t)
|
|
|
|
|
s1_array_forward_shooting <- c(s1_array_forward_shooting, s1_t)
|
|
|
|
|
s3_array_forward_shooting <- c(s3_array_forward_shooting, s3_t)
|
|
|
|
|
x1_array_forward_shooting <- c(x1_array_forward_shooting, x1_t)
|
|
|
|
|
x3_array_forward_shooting <- c(x3_array_forward_shooting, x3_t)
|
|
|
|
|
}
|
|
|
|
|
# Variables
|
|
|
|
|
η = 0.9 ## 1.1
|
|
|
|
|
ρ = 0.005
|
|
|
|
|
r_1 = 0.06
|
|
|
|
|
r_3 = -0.05
|
|
|
|
|
γ_1 = 0.03
|
|
|
|
|
γ_3 = 0.01
|
2021-03-09 17:04:26 +00:00
|
|
|
|
w_3 = 5000 ## Mean on the EA Survey 2018- ~7000
|
2020-09-24 10:39:48 +00:00
|
|
|
|
β_3 = 1 ## 1 ## 0.5 Corresponds to roughly 5 people convincing 10 other people per year on a 50k year budget
|
|
|
|
|
## Dramatic if beta = 0.5, w_3 = 1000
|
|
|
|
|
λ_1 = 0.5
|
|
|
|
|
λ_3 = 0.5
|
|
|
|
|
δ_3 = 0.44
|
|
|
|
|
## k1_forward_shooting
|
|
|
|
|
k1_forward_shooting = 3*10^(-7) ## 1*10^(-7) fails. 2*10^(-7) fails
|
|
|
|
|
k1_reverse_shooting = k1_forward_shooting
|
|
|
|
|
## Artfully guessed, such that s1 < 1
|
|
|
|
|
stepsize = 0.1
|
|
|
|
|
## stepsize = 0.1 => seconds (7s).
|
|
|
|
|
## stepsize = 0.01 => minutes (3 mins).
|
|
|
|
|
r1_stepsize = ((1+r_1)^stepsize)-1
|
|
|
|
|
r3_stepsize = ((1+r_3)^stepsize)-1
|
|
|
|
|
first = 0
|
|
|
|
|
last = 1000
|
|
|
|
|
times_forward_shooting = seq(from=first, to=last, by=stepsize)
|
|
|
|
|
times_reverse_shooting = seq(from=last, to=first, by=-stepsize)
|
|
|
|
|
### Initial conditions. Correspond to "year 0".
|
|
|
|
|
x1_init = 10^10 ## 1 billion? 15 billion? 100 billion? Too much?
|
|
|
|
|
x3_init = 10^5
|
|
|
|
|
# Forward shooting
|
|
|
|
|
options(digits=7)
|
|
|
|
|
## Evolution
|
|
|
|
|
x1_array_forward_shooting <- c()
|
|
|
|
|
x3_array_forward_shooting <- c()
|
|
|
|
|
a1_array_forward_shooting <- c()
|
|
|
|
|
a3_array_forward_shooting <- c()
|
|
|
|
|
s1_array_forward_shooting <- c()
|
|
|
|
|
s3_array_forward_shooting <- c()
|
|
|
|
|
x1_t = x1_init
|
|
|
|
|
x3_t = x3_init
|
|
|
|
|
#stepsize
|
|
|
|
|
comienzo = Sys.time()
|
|
|
|
|
max = max(times_forward_shooting)
|
|
|
|
|
for(t in times_forward_shooting){
|
|
|
|
|
if((100*t/max) %in% seq(from=0, to=100, by=1)){
|
|
|
|
|
cat(paste(floor(100*t/max), "%", sep=""))
|
|
|
|
|
cat("\n")
|
|
|
|
|
}
|
|
|
|
|
a1_t = a1(t)
|
|
|
|
|
a3_t = a3(t)
|
|
|
|
|
s1_t = s1(t)
|
|
|
|
|
s3_t = s3(t)
|
|
|
|
|
x1_t = x1_t*(1+r1_stepsize) + dx1(t)*stepsize
|
|
|
|
|
x3_t = x3_t*(1+r3_stepsize) + dx3(t)*stepsize
|
|
|
|
|
a1_array_forward_shooting <- c(a1_array_forward_shooting, a1_t)
|
|
|
|
|
a3_array_forward_shooting <- c(a3_array_forward_shooting, a3_t)
|
|
|
|
|
s1_array_forward_shooting <- c(s1_array_forward_shooting, s1_t)
|
|
|
|
|
s3_array_forward_shooting <- c(s3_array_forward_shooting, s3_t)
|
|
|
|
|
x1_array_forward_shooting <- c(x1_array_forward_shooting, x1_t)
|
|
|
|
|
x3_array_forward_shooting <- c(x3_array_forward_shooting, x3_t)
|
|
|
|
|
}
|
|
|
|
|
fin = Sys.time()
|
|
|
|
|
fin-comienzo
|
|
|
|
|
## Checking condition
|
|
|
|
|
options(digits=22)
|
|
|
|
|
l = length(times_forward_shooting)
|
|
|
|
|
x1_array_forward_shooting[l]
|
|
|
|
|
x1_growth = (x1_array_forward_shooting[l]-x1_array_forward_shooting[l-1])/x1_array_forward_shooting[l-1]/(1*stepsize)
|
|
|
|
|
x1_growth
|
|
|
|
|
sum(x1_array_forward_shooting<0)
|
|
|
|
|
x3_array_forward_shooting[l]
|
|
|
|
|
x3_growth = (x3_array_forward_shooting[l]-x3_array_forward_shooting[l-1])/x3_array_forward_shooting[l-1]/(1*stepsize)
|
|
|
|
|
x3_growth
|
|
|
|
|
sum(x3_array_forward_shooting<0)
|
|
|
|
|
a1_growth = (a1_array_forward_shooting[l]-a1_array_forward_shooting[l-1])/a1_array_forward_shooting[l-1]/stepsize
|
|
|
|
|
a1_growth
|
|
|
|
|
a3_growth = (a3_array_forward_shooting[l]-a3_array_forward_shooting[l-1])/a3_array_forward_shooting[l-1]/stepsize
|
|
|
|
|
a3_growth
|
|
|
|
|
a1_array_forward_shooting[l]/x1_array_forward_shooting[l]
|
2021-03-09 17:04:26 +00:00
|
|
|
|
plot((a1_array_forward_shooting/x1_array_forward_shooting)[(l-100)-l])
|
2020-09-24 10:39:48 +00:00
|
|
|
|
# Plotting
|
|
|
|
|
## install.packages("tidyverse") <- Not totally necessary.
|
|
|
|
|
## install.packages("ggplot2")
|
|
|
|
|
## install.packages("ggsci")
|
|
|
|
|
library(ggplot2)
|
|
|
|
|
library(ggsci)
|
|
|
|
|
## General variables
|
|
|
|
|
saveplots=TRUE
|
|
|
|
|
times = times_forward_shooting
|
|
|
|
|
## Also for reverse shooting plots; time in reverse shooting is inverted
|
|
|
|
|
shootingtype="reverse"#"forward"#
|
|
|
|
|
shootingtype="forward"#"reverse"#
|
|
|
|
|
directory = paste("/home/nuno/Documents/core/SRF/BackShooting/RCode/plots/satisfactory3/", shootingtype, "shooting", "/", last, "years", sep="")
|
|
|
|
|
directory
|
|
|
|
|
setwd(directory)
|
|
|
|
|
if(shootingtype=="forward"){
|
|
|
|
|
x1_array_plotting <- x1_array_forward_shooting
|
|
|
|
|
x3_array_plotting <- x3_array_forward_shooting
|
|
|
|
|
a1_array_plotting <- a1_array_forward_shooting
|
|
|
|
|
a3_array_plotting <- a3_array_forward_shooting
|
|
|
|
|
s1_array_plotting <- s1_array_forward_shooting
|
|
|
|
|
s3_array_plotting <- s3_array_forward_shooting
|
|
|
|
|
} else if(shootingtype=="reverse"){
|
|
|
|
|
x1_array_plotting <- x1_array_reverse_shooting
|
|
|
|
|
x3_array_plotting <- x3_array_reverse_shooting
|
|
|
|
|
a1_array_plotting <- a1_array_reverse_shooting
|
|
|
|
|
a3_array_plotting <- a3_array_reverse_shooting
|
|
|
|
|
s1_array_plotting <- s1_array_reverse_shooting
|
|
|
|
|
s3_array_plotting <- s3_array_reverse_shooting
|
|
|
|
|
}
|
|
|
|
|
height = 5
|
|
|
|
|
width = floor(height*(1+sqrt(5))/2)
|
|
|
|
|
imagenumbercounter = 1
|
|
|
|
|
saveplot = function(imagename){
|
|
|
|
|
if(saveplots){
|
|
|
|
|
ggsave(paste(imagenumbercounter,"_", imagename, "_",shootingtype, "shooting",".png", sep =""), units="in", width=width, height=height)
|
|
|
|
|
imagenumbercounter <<- imagenumbercounter+1
|
2021-03-09 17:04:26 +00:00
|
|
|
|
## https-//stackoverflow.com/questions/1236620/global-variables-in-r
|
2020-09-24 10:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options(digits=1) ## Just for display
|
|
|
|
|
xs <- list()
|
|
|
|
|
xs$values <- c(x1_array_plotting, x3_array_plotting)
|
|
|
|
|
xs$var <- c(rep("x1", length(x1_array_plotting)), rep("x3", length(x3_array_plotting)))
|
|
|
|
|
xs$times = rep(times,2)
|
|
|
|
|
xs <- as.data.frame(xs)
|
|
|
|
|
title_text = "Evolution of state variables"
|
|
|
|
|
(ggplot(data = xs, aes(x = times, y= values, color = var)) +
|
|
|
|
|
geom_line(size = 0.5)
|
|
|
|
|
+ labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Capital and labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.box="vertical"
|
|
|
|
|
)
|
|
|
|
|
+ scale_color_lancet(
|
|
|
|
|
breaks=c("x1", "x3"),
|
|
|
|
|
labels=c("Capital", "Labor")
|
|
|
|
|
)
|
|
|
|
|
+ scale_y_continuous(breaks = seq(min(x1_array_plotting), max(x1_array_plotting), length.out=5))
|
|
|
|
|
)
|
2021-03-09 17:04:26 +00:00
|
|
|
|
## x1 and x3- log plot
|
2020-09-24 10:39:48 +00:00
|
|
|
|
title_text = "Evolution of state variables"
|
|
|
|
|
(ggplot(data = xs, aes(x = times, y= values, color = var)) +
|
|
|
|
|
geom_line(size = 0.5)
|
|
|
|
|
+labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
subtitle="(logarithmic scale)",
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Capital and labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.box="vertical"
|
|
|
|
|
)
|
|
|
|
|
+ scale_color_lancet(
|
|
|
|
|
breaks=c("x1", "x3"),
|
|
|
|
|
labels=c("Capital", "Labor")
|
|
|
|
|
)
|
|
|
|
|
+ scale_y_continuous(trans = 'log2')
|
|
|
|
|
)
|
|
|
|
|
saveplot("StateVariablesX1X3logplot")
|
|
|
|
|
## Only x3
|
|
|
|
|
equis3 <- list()
|
|
|
|
|
equis3$values <- c(x3_array_plotting)
|
|
|
|
|
equis3$times = times
|
|
|
|
|
equis3 <- as.data.frame(equis3)
|
|
|
|
|
title_text = "Evolution of movement size"
|
|
|
|
|
(ggplot(data = equis3, aes(x = times, y= values))
|
|
|
|
|
+geom_line(size = 0.5)
|
|
|
|
|
+labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.box="vertical"
|
|
|
|
|
)
|
|
|
|
|
##+ scale_color_lancet()
|
|
|
|
|
)
|
|
|
|
|
saveplot("StateVariableX3")
|
|
|
|
|
## s1, s3, s4
|
|
|
|
|
sigmas <- list()
|
|
|
|
|
s4_array_plotting=1-s1_array_plotting-s3_array_plotting
|
|
|
|
|
sigmas$values <- c(s1_array_plotting, s3_array_plotting,s4_array_plotting)
|
|
|
|
|
sigmas$fraction <- c(rep("s1", length(s1_array_plotting)), rep("s3", length(s3_array_plotting)),rep("s4", length(s3_array_plotting)))
|
|
|
|
|
sigmas$times = rep(times,3)
|
|
|
|
|
sigmas <- as.data.frame(sigmas)
|
|
|
|
|
title_text = "Evolution of labor fractions"
|
|
|
|
|
(ggplot(data = sigmas, aes(x = times, y= values, color = fraction)) +
|
|
|
|
|
geom_line(size = 0.5)
|
|
|
|
|
+labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Fraction of total labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.direction="vertical"
|
|
|
|
|
)
|
|
|
|
|
+ scale_color_lancet(
|
|
|
|
|
breaks=c("s1", "s3", "s4"),
|
|
|
|
|
labels=c("Direct work", "Movement building", "Money-making")
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
# Variables
|
|
|
|
|
η = 0.9 ## 1.1
|
|
|
|
|
ρ = 0.005
|
|
|
|
|
r_1 = 0.06
|
|
|
|
|
r_3 = -0.02
|
|
|
|
|
γ_1 = 0.03
|
|
|
|
|
γ_3 = 0.01
|
2021-03-09 17:04:26 +00:00
|
|
|
|
w_3 = 5000 ## Mean on the EA Survey 2018- ~7000
|
2020-09-24 10:39:48 +00:00
|
|
|
|
β_3 = 1 ## 1 ## 0.5 Corresponds to roughly 5 people convincing 10 other people per year on a 50k year budget
|
|
|
|
|
## Dramatic if beta = 0.5, w_3 = 1000
|
|
|
|
|
λ_1 = 0.5
|
|
|
|
|
λ_3 = 0.5
|
|
|
|
|
δ_3 = 0.44
|
|
|
|
|
## k1_forward_shooting
|
|
|
|
|
k1_forward_shooting = 3*10^(-7) ## 1*10^(-7) fails. 2*10^(-7) fails
|
|
|
|
|
k1_reverse_shooting = k1_forward_shooting
|
|
|
|
|
## Artfully guessed, such that s1 < 1
|
|
|
|
|
stepsize = 0.1
|
|
|
|
|
## stepsize = 0.1 => seconds (7s).
|
|
|
|
|
## stepsize = 0.01 => minutes (3 mins).
|
|
|
|
|
r1_stepsize = ((1+r_1)^stepsize)-1
|
|
|
|
|
r3_stepsize = ((1+r_3)^stepsize)-1
|
|
|
|
|
first = 0
|
|
|
|
|
last = 1000
|
|
|
|
|
times_forward_shooting = seq(from=first, to=last, by=stepsize)
|
|
|
|
|
times_reverse_shooting = seq(from=last, to=first, by=-stepsize)
|
|
|
|
|
### Initial conditions. Correspond to "year 0".
|
|
|
|
|
x1_init = 10^10 ## 1 billion? 15 billion? 100 billion? Too much?
|
|
|
|
|
x3_init = 10^5
|
|
|
|
|
# Forward shooting
|
|
|
|
|
options(digits=7)
|
|
|
|
|
## Evolution
|
|
|
|
|
x1_array_forward_shooting <- c()
|
|
|
|
|
x3_array_forward_shooting <- c()
|
|
|
|
|
a1_array_forward_shooting <- c()
|
|
|
|
|
a3_array_forward_shooting <- c()
|
|
|
|
|
s1_array_forward_shooting <- c()
|
|
|
|
|
s3_array_forward_shooting <- c()
|
|
|
|
|
x1_t = x1_init
|
|
|
|
|
x3_t = x3_init
|
|
|
|
|
#stepsize
|
|
|
|
|
comienzo = Sys.time()
|
|
|
|
|
max = max(times_forward_shooting)
|
|
|
|
|
for(t in times_forward_shooting){
|
|
|
|
|
if((100*t/max) %in% seq(from=0, to=100, by=1)){
|
|
|
|
|
cat(paste(floor(100*t/max), "%", sep=""))
|
|
|
|
|
cat("\n")
|
|
|
|
|
}
|
|
|
|
|
a1_t = a1(t)
|
|
|
|
|
a3_t = a3(t)
|
|
|
|
|
s1_t = s1(t)
|
|
|
|
|
s3_t = s3(t)
|
|
|
|
|
x1_t = x1_t*(1+r1_stepsize) + dx1(t)*stepsize
|
|
|
|
|
x3_t = x3_t*(1+r3_stepsize) + dx3(t)*stepsize
|
|
|
|
|
a1_array_forward_shooting <- c(a1_array_forward_shooting, a1_t)
|
|
|
|
|
a3_array_forward_shooting <- c(a3_array_forward_shooting, a3_t)
|
|
|
|
|
s1_array_forward_shooting <- c(s1_array_forward_shooting, s1_t)
|
|
|
|
|
s3_array_forward_shooting <- c(s3_array_forward_shooting, s3_t)
|
|
|
|
|
x1_array_forward_shooting <- c(x1_array_forward_shooting, x1_t)
|
|
|
|
|
x3_array_forward_shooting <- c(x3_array_forward_shooting, x3_t)
|
|
|
|
|
}
|
|
|
|
|
fin = Sys.time()
|
|
|
|
|
fin-comienzo
|
|
|
|
|
## Checking condition
|
|
|
|
|
options(digits=22)
|
|
|
|
|
l = length(times_forward_shooting)
|
|
|
|
|
x1_array_forward_shooting[l]
|
|
|
|
|
x1_growth = (x1_array_forward_shooting[l]-x1_array_forward_shooting[l-1])/x1_array_forward_shooting[l-1]/(1*stepsize)
|
|
|
|
|
x1_growth
|
|
|
|
|
sum(x1_array_forward_shooting<0)
|
|
|
|
|
x3_array_forward_shooting[l]
|
|
|
|
|
x3_growth = (x3_array_forward_shooting[l]-x3_array_forward_shooting[l-1])/x3_array_forward_shooting[l-1]/(1*stepsize)
|
|
|
|
|
x3_growth
|
|
|
|
|
sum(x3_array_forward_shooting<0)
|
|
|
|
|
a1_growth = (a1_array_forward_shooting[l]-a1_array_forward_shooting[l-1])/a1_array_forward_shooting[l-1]/stepsize
|
|
|
|
|
a1_growth
|
|
|
|
|
a3_growth = (a3_array_forward_shooting[l]-a3_array_forward_shooting[l-1])/a3_array_forward_shooting[l-1]/stepsize
|
|
|
|
|
a3_growth
|
|
|
|
|
a1_array_forward_shooting[l]/x1_array_forward_shooting[l]
|
2021-03-09 17:04:26 +00:00
|
|
|
|
plot((a1_array_forward_shooting/x1_array_forward_shooting)[(l-100)-l])
|
2020-09-24 10:39:48 +00:00
|
|
|
|
# Plotting
|
|
|
|
|
## install.packages("tidyverse") <- Not totally necessary.
|
|
|
|
|
## install.packages("ggplot2")
|
|
|
|
|
## install.packages("ggsci")
|
|
|
|
|
library(ggplot2)
|
|
|
|
|
library(ggsci)
|
|
|
|
|
## General variables
|
|
|
|
|
saveplots=TRUE
|
|
|
|
|
times = times_forward_shooting
|
|
|
|
|
## Also for reverse shooting plots; time in reverse shooting is inverted
|
|
|
|
|
shootingtype="reverse"#"forward"#
|
|
|
|
|
shootingtype="forward"#"reverse"#
|
|
|
|
|
directory = paste("/home/nuno/Documents/core/SRF/BackShooting/RCode/plots/satisfactory3/", shootingtype, "shooting", "/", last, "years", sep="")
|
|
|
|
|
directory
|
|
|
|
|
setwd(directory)
|
|
|
|
|
if(shootingtype=="forward"){
|
|
|
|
|
x1_array_plotting <- x1_array_forward_shooting
|
|
|
|
|
x3_array_plotting <- x3_array_forward_shooting
|
|
|
|
|
a1_array_plotting <- a1_array_forward_shooting
|
|
|
|
|
a3_array_plotting <- a3_array_forward_shooting
|
|
|
|
|
s1_array_plotting <- s1_array_forward_shooting
|
|
|
|
|
s3_array_plotting <- s3_array_forward_shooting
|
|
|
|
|
} else if(shootingtype=="reverse"){
|
|
|
|
|
x1_array_plotting <- x1_array_reverse_shooting
|
|
|
|
|
x3_array_plotting <- x3_array_reverse_shooting
|
|
|
|
|
a1_array_plotting <- a1_array_reverse_shooting
|
|
|
|
|
a3_array_plotting <- a3_array_reverse_shooting
|
|
|
|
|
s1_array_plotting <- s1_array_reverse_shooting
|
|
|
|
|
s3_array_plotting <- s3_array_reverse_shooting
|
|
|
|
|
}
|
|
|
|
|
height = 5
|
|
|
|
|
width = floor(height*(1+sqrt(5))/2)
|
|
|
|
|
imagenumbercounter = 1
|
|
|
|
|
saveplot = function(imagename){
|
|
|
|
|
if(saveplots){
|
|
|
|
|
ggsave(paste(imagenumbercounter,"_", imagename, "_",shootingtype, "shooting",".png", sep =""), units="in", width=width, height=height)
|
|
|
|
|
imagenumbercounter <<- imagenumbercounter+1
|
2021-03-09 17:04:26 +00:00
|
|
|
|
## https-//stackoverflow.com/questions/1236620/global-variables-in-r
|
2020-09-24 10:39:48 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
options(digits=1) ## Just for display
|
|
|
|
|
xs <- list()
|
|
|
|
|
xs$values <- c(x1_array_plotting, x3_array_plotting)
|
|
|
|
|
xs$var <- c(rep("x1", length(x1_array_plotting)), rep("x3", length(x3_array_plotting)))
|
|
|
|
|
xs$times = rep(times,2)
|
|
|
|
|
xs <- as.data.frame(xs)
|
|
|
|
|
title_text = "Evolution of state variables"
|
|
|
|
|
(ggplot(data = xs, aes(x = times, y= values, color = var)) +
|
|
|
|
|
geom_line(size = 0.5)
|
|
|
|
|
+ labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Capital and labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.box="vertical"
|
|
|
|
|
)
|
|
|
|
|
+ scale_color_lancet(
|
|
|
|
|
breaks=c("x1", "x3"),
|
|
|
|
|
labels=c("Capital", "Labor")
|
|
|
|
|
)
|
|
|
|
|
+ scale_y_continuous(breaks = seq(min(x1_array_plotting), max(x1_array_plotting), length.out=5))
|
|
|
|
|
)
|
|
|
|
|
saveplot("StateVariablesX1X3")
|
2021-03-09 17:04:26 +00:00
|
|
|
|
## x1 and x3- log plot
|
2020-09-24 10:39:48 +00:00
|
|
|
|
title_text = "Evolution of state variables"
|
|
|
|
|
(ggplot(data = xs, aes(x = times, y= values, color = var)) +
|
|
|
|
|
geom_line(size = 0.5)
|
|
|
|
|
+labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
subtitle="(logarithmic scale)",
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Capital and labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.box="vertical"
|
|
|
|
|
)
|
|
|
|
|
+ scale_color_lancet(
|
|
|
|
|
breaks=c("x1", "x3"),
|
|
|
|
|
labels=c("Capital", "Labor")
|
|
|
|
|
)
|
|
|
|
|
+ scale_y_continuous(trans = 'log2')
|
|
|
|
|
)
|
|
|
|
|
saveplot("StateVariablesX1X3logplot")
|
|
|
|
|
## Only x3
|
|
|
|
|
equis3 <- list()
|
|
|
|
|
equis3$values <- c(x3_array_plotting)
|
|
|
|
|
equis3$times = times
|
|
|
|
|
equis3 <- as.data.frame(equis3)
|
|
|
|
|
title_text = "Evolution of movement size"
|
|
|
|
|
(ggplot(data = equis3, aes(x = times, y= values))
|
|
|
|
|
+geom_line(size = 0.5)
|
|
|
|
|
+labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.box="vertical"
|
|
|
|
|
)
|
|
|
|
|
##+ scale_color_lancet()
|
|
|
|
|
)
|
|
|
|
|
saveplot("StateVariableX3")
|
|
|
|
|
## s1, s3, s4
|
|
|
|
|
sigmas <- list()
|
|
|
|
|
s4_array_plotting=1-s1_array_plotting-s3_array_plotting
|
|
|
|
|
sigmas$values <- c(s1_array_plotting, s3_array_plotting,s4_array_plotting)
|
|
|
|
|
sigmas$fraction <- c(rep("s1", length(s1_array_plotting)), rep("s3", length(s3_array_plotting)),rep("s4", length(s3_array_plotting)))
|
|
|
|
|
sigmas$times = rep(times,3)
|
|
|
|
|
sigmas <- as.data.frame(sigmas)
|
|
|
|
|
title_text = "Evolution of labor fractions"
|
|
|
|
|
(ggplot(data = sigmas, aes(x = times, y= values, color = fraction)) +
|
|
|
|
|
geom_line(size = 0.5)
|
|
|
|
|
+labs(
|
|
|
|
|
title=title_text,
|
|
|
|
|
#subtitle="n =303",
|
|
|
|
|
x="Year since start",
|
|
|
|
|
y="Fraction of total labor"
|
|
|
|
|
#caption="@EA Mental Health Survey"
|
|
|
|
|
)
|
|
|
|
|
+theme(
|
|
|
|
|
legend.title = element_blank(),
|
|
|
|
|
#plot.subtitle = element_text(hjust = 0.5),
|
|
|
|
|
plot.title = element_text(hjust = 0.5),
|
|
|
|
|
#axis.text.y = element_blank(),
|
|
|
|
|
legend.position="bottom",
|
|
|
|
|
legend.direction="vertical"
|
|
|
|
|
)
|
|
|
|
|
+ scale_color_lancet(
|
|
|
|
|
breaks=c("s1", "s3", "s4"),
|
|
|
|
|
labels=c("Direct work", "Movement building", "Money-making")
|
|
|
|
|
)
|
|
|
|
|
)
|