}
output_directory = paste0("../threshold-dependent-drives/data/s_", letter, "/", drive,"/")
# Store observed invasion thresholds and predicted invasion thresholds (for s_g > 0 only)
b_values = c(1, 0.5, 0.2, 0.05)
output_directory
phat.observed = rep(-1, 4)
# First, get baseline invasion threshold, phat
b = 1
b1 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
prediction = NULL
res.b1 = fit.p0.logistic(data = b1, drive = drive, add_critical_p0_line = T,
text_size = text_size, prediction = NULL,linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
phat = res.b1$critical_p0
if (cost.in.germination){
phat.predicted[1] = phat
}
phat.observed[1] = phat
plot.b1 = res.b1$plot
b = 0.5
res.b1$plot
b = 0.5
b0.5 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
tau = average_seedbank_duration(L = b0.5$L[1], d = b0.5$d[1], b = b, m = b0.5$m[1], q = b0.5$q[1])
predicted.threshold = tau*phat
if (cost.in.germination){
phat.predicted[2] = predicted.threshold
}
res.b0.5 = fit.p0.logistic(data = b0.5, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = ifelse(cost.in.germination,predicted.threshold, NULL),
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
prediction = ifelse(cost.in.germination,predicted.threshold, NULL)
prediction
cost.in.germination
predicted.threshold
ifelse(cost.in.germination,predicted.threshold, NULL),
ifelse(cost.in.germination,predicted.threshold, NULL)
res.b0.5 = fit.p0.logistic(data = b0.5, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = ifelse(cost.in.germination==T,predicted.threshold, NULL),
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
prediction = ifelse(cost.in.germination==T,predicted.threshold, NULL)
cost.in.germination
ifelse(1==2, print("hey"), print("no"))
if (cost.in.germination){
predicted.threshold = tau*phat
phat.predicted[2] = predicted.threshold
} else {
predicted.threshold = NULL
}
res.b0.5 = fit.p0.logistic(data = b0.5, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = predicted.threshold,
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
res.b0.5$plot
b = 0.2
b0.2 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
tau = average_seedbank_duration(L = b0.2$L[1], d = b0.2$d[1], b = b, m = b0.2$m[1], q = b0.2$q[1])
if (cost.in.germination){
predicted.threshold = tau*phat
phat.predicted[3] = predicted.threshold
} else {
predicted.threshold = NULL
}
res.b0.2 = fit.p0.logistic(data = b0.2, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = ifelse(cost.in.germination,predicted.threshold, NULL),
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
res.b0.2 = fit.p0.logistic(data = b0.2, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = predicted.threshold,
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
res.b0.2$plot
b = 0.05
b0.05 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
tau = average_seedbank_duration(L = b0.05$L[1], d = b0.05$d[1], b = b, m = b0.05$m[1], q = b0.05$q[1])
tau = average_seedbank_duration(L = b0.05$L[1], d = b0.05$d[1], b = b, m = b0.05$m[1], q = b0.05$q[1])
if (cost.in.germination){
predicted.threshold = tau*phat
phat.predicted[4] = predicted.threshold
} else {
predicted.threshold = NULL
}
res.b0.05 = fit.p0.logistic(data = b0.05, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = predicted.threshold,
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
res.b0.05$plot
make_threshold_panels_and_summary_plot = function(drive, s, cost.in.germination = T, text_size = 15,
title = "",linewidth = 0.75,
point_size = 0.7, point_alpha = 0.8, margin = 0.1){
# For a given drive and fitness cost, generate the 4 panel plots ("p0" vs "Rate drive spread") for b = 1, 0.5, 0.2, and 0.05. Also create 1 summary plot of "b" vs "observed effective invasion threshold"
# Arguments:
#   drive: one of "cain", "clvr", "clvr-male-suppression", "clvr-female-suppression", and "cain-male-suppression"
#   s: fitness cost
#   cost.in.germination: T if s_g > 0 and s_s = 0. F if s_s > 0 and s_g = 0.
#   text_size: size of all text
#   linewidth: width of logistic curve
#   point_size: size of points
#   point_alpha: transparency of points
#   margin: padding around axes
if (drive %in% c("cain", "clvr")){
p0.max = 1
suppression = F
} else {
p0.max = 0.5
suppression = T
}
# if cost.in.germination, s_g otherwise s_s
if (cost.in.germination){
letter = "g"
} else {
letter = "s"
}
output_directory = paste0("../threshold-dependent-drives/data/s_", letter, "/", drive,"/")
# Store observed invasion thresholds and predicted invasion thresholds (for s_g > 0 only)
b_values = c(1, 0.5, 0.2, 0.05)
if (cost.in.germination){
phat.predicted = rep(-1, 4)
}
phat.observed = rep(-1, 4)
# First, get baseline invasion threshold, phat
b = 1
b1 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
prediction = NULL
res.b1 = fit.p0.logistic(data = b1, drive = drive, add_critical_p0_line = T,
text_size = text_size, prediction = NULL,linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
phat = res.b1$critical_p0
if (cost.in.germination){
phat.predicted[1] = phat
}
phat.observed[1] = phat
plot.b1 = res.b1$plot
b = 0.5
b0.5 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
tau = average_seedbank_duration(L = b0.5$L[1], d = b0.5$d[1], b = b, m = b0.5$m[1], q = b0.5$q[1])
if (cost.in.germination){
predicted.threshold = tau*phat
phat.predicted[2] = predicted.threshold
} else {
predicted.threshold = NULL
}
res.b0.5 = fit.p0.logistic(data = b0.5, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = predicted.threshold,
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
plot.b0.5 = res.b0.5$plot
phat.observed[2] = res.b0.5$critical_p0
b = 0.2
b0.2 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
tau = average_seedbank_duration(L = b0.2$L[1], d = b0.2$d[1], b = b, m = b0.2$m[1], q = b0.2$q[1])
if (cost.in.germination){
predicted.threshold = tau*phat
phat.predicted[3] = predicted.threshold
} else {
predicted.threshold = NULL
}
res.b0.2 = fit.p0.logistic(data = b0.2, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = predicted.threshold,
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
plot.b0.2 = res.b0.2$plot
phat.observed[3] = res.b0.2$critical_p0
b = 0.05
b0.05 = read_csv(paste0(output_directory, drive,"-b",b,"-s_",letter,s,".csv")) %>%
arrange(p0) %>%
filter(p0 <= p0.max)
tau = average_seedbank_duration(L = b0.05$L[1], d = b0.05$d[1], b = b, m = b0.05$m[1], q = b0.05$q[1])
if (cost.in.germination){
predicted.threshold = tau*phat
phat.predicted[4] = predicted.threshold
} else {
predicted.threshold = NULL
}
res.b0.05 = fit.p0.logistic(data = b0.05, drive = drive, add_critical_p0_line = T,
text_size = text_size,
prediction = predicted.threshold,
linewidth = linewidth,
point_size = point_size, point_alpha = point_alpha,
margin = margin)
plot.b0.05 = res.b0.05$plot
phat.observed[4] = res.b0.05$critical_p0
# panel plot column
panel.column = plot_grid(plot.b1,NULL, plot.b0.5, NULL, plot.b0.2, NULL, plot.b0.05, ncol = 1, align = "hv",
rel_heights = c(1,-0.1,1,-0.1,1,-0.1,1))
# summary plot
b_ticks = seq(0.2, 1, by = 0.2)
blabels = paste0(b_ticks)
y_tick_marks = seq(0, 1, by = 0.25)
ymax = 1; ymin = 0
if (suppression){
ymax = 0.49
y_tick_marks = seq(0, 0.5, by = 0.25)
}
nb = length(b_ticks)
ny = length(y_tick_marks)
point_size = 1.6 # increase
if (cost.in.germination){
summary = tibble(b = b_values, phat = phat.observed, phat_predicted = phat.predicted )
plt = ggplot(data = summary, mapping = aes(x = b, y = phat)) +
geom_point(color = "blue", size = point_size*1.2) +
geom_line(size = linewidth, color = "blue") +
geom_point(mapping = aes(x = b, y = phat_predicted), color = "red",
shape = 17, size = point_size) +
geom_line(mapping = aes(x = b, y = phat_predicted), size = linewidth, linetype = "dashed",
color = "red") +
scale_x_continuous(breaks = b_ticks, labels = blabels, limits = c(0.0,1)) +
scale_y_continuous(breaks = y_tick_marks) +
ylab(TeX(r"(\textit{$\hat{p}_e$})")) +
xlab("b") +
theme(text = element_text(size=text_size),
plot.title = element_text(size=text_size),
plot.subtitle = element_text(size = text_size),
axis.text = element_text(color="black",size=text_size),
legend.text = element_text(size=text_size),
axis.text.x = element_text(angle = 0)) +
coord_cartesian(xlim = c(0.05, 1), ylim = c(ymin,ymax))
} else {
summary = tibble(b = b_values, phat = phat.observed)
plt = ggplot(data = summary, mapping = aes(x = b, y = phat)) +
geom_point(color = "blue", size = point_size*1.2) +
geom_line(size = linewidth, color = "blue") +
scale_x_continuous(breaks = b_ticks, labels = blabels, limits = c(0.0,1)) +
scale_y_continuous(breaks = y_tick_marks) +
ylab(TeX(r"(\textit{$\hat{p}_e$})")) +
xlab("b") +
theme(text = element_text(size=text_size),
plot.title = element_text(size=text_size),
plot.subtitle = element_text(size = text_size),
axis.text = element_text(color="black",size=text_size),
legend.text = element_text(size=text_size),
axis.text.x = element_text(angle = 0)) +
coord_cartesian(xlim = c(0.05, 1), ylim = c(ymin,ymax))
}
plots = list(panel.column = panel.column, summary = plt)
return(plots)
}
drive = "cain"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
plots$panel.column
plots$summary
rm(s_g)
drive = "cain"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = T,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_g = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = T,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
drive = "cain"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = T,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = T,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
drive = "cain"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
drive = "cain-male-suppression"
text.size = 15
s_g = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_g, cost.in.germination = T,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_g-",s_g,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_g-",s_g,"-summary.pdf"),
height = 5, width = 5)
s_g = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_g, cost.in.germination = T,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_g-",s_g,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_g-",s_g,"-summary.pdf"),
height = 5, width = 5)
s_g = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_g, cost.in.germination = T,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_g-",s_g,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_g-",s_g,"-summary.pdf"),
height = 5, width = 5)
rm(s_g)
drive = "clvr"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
drive = "clvr-male-suppression"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
drive = "clvr-female-suppression"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
drive = "cain-male-suppression"
text.size = 15
s_s = 0.05
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.1
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
s_s = 0.25
plots = make_threshold_panels_and_summary_plot(drive = drive, s = s_s, cost.in.germination = F,
text_size = text.size)
ggsave(plot = plots$panel.column,
filename = paste0(drive,"-s_s-",s_s,"-pincrease-panels.pdf"),
height = 20, width = 5)
ggsave(plot = plots$summary,
filename = paste0(drive,"-s_s-",s_s,"-summary.pdf"),
height = 5, width = 5)
