Skip to content

Commit 6d5f77c

Browse files
committed
🐎 integrate topology results
1 parent 4a6094d commit 6d5f77c

4 files changed

Lines changed: 73 additions & 13 deletions

File tree

β€Žcode/Analyse_END_simulations.Rβ€Ž

Lines changed: 73 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
2-
rm(list=ls())
3-
41
library(tidyverse)
52
library(here)
63

4+
source("lib/plotting_theme.R")
5+
76
# load data ---------------------------------------------
87
csv_path <- here("data/outputs/END_simulation_summary.csv")
98
sim_out <- read_csv(csv_path, show_col_types = FALSE)
@@ -28,24 +27,85 @@ sim_out_long <- sim_out %>%
2827
mutate(model = factor(as.character(model))) %>%
2928
pivot_longer(cols = all_of(metrics), names_to = "metric", values_to = "value") %>%
3029
filter(!is.na(value)) %>%
31-
mutate(metric = factor(metric, levels = metrics))
30+
mutate(metric = factor(metric, levels = metrics)) %>%
31+
# set niche model as reference model
32+
glow_up(model = factor(model)) %>%
33+
glow_up(model = relevel(model, ref = "Niche"))
3234

33-
boxplot_sim <- ggplot(sim_out_long, aes(x = model, y = value, color = model)) +
35+
boxplot_sim <- ggplot(sim_out_long, aes(x = model, y = value, colour = model)) +
3436
geom_boxplot(outlier.alpha = 0.5, width = 0.6) +
3537
facet_wrap(~ metric, scales = "free_y") +
3638
labs(x = "", y = "") +
37-
theme_bw(base_size = 20) +
38-
theme(
39-
panel.grid.major.x = element_blank(),
40-
axis.text.x = element_text(angle = 30, hjust = 1),
41-
plot.title = element_text(face = "bold"),
42-
legend.position = "none"
43-
)
39+
scale_colour_manual(values = model_colours) +
40+
figure_theme +
41+
theme(legend.position = 'none',
42+
axis.text.x = element_text(angle = 45, hjust = 1))
43+
4444
boxplot_sim
4545

4646
ggsave("../figures/boxplots_end_simulations.png", boxplot_sim,
47-
width = 14, height = 9, dpi = 300)
47+
width = 12, height = 7, dpi = 600)
48+
49+
# topology
50+
51+
topology = read.csv("data/outputs/END_topology.csv") %>%
52+
glow_up(model = str_extract(model,
53+
"([A-Za-z]+)")) %>%
54+
glow_up(model = case_when(model == "adbm" ~ "ADBM",
55+
model == "atn" ~ "ATN",
56+
model == "cascade" ~ "Cascade",
57+
model == "ltm" ~ "LTM",
58+
model == "maxent" ~ "MaxEnt",
59+
model == "niche" ~ "Niche",
60+
model == "random" ~ "Random"))
61+
62+
lda_fit <- lda(model ~ ., data = topology)
63+
64+
lda_scores <- as.data.frame(predict(lda_fit)$x)
65+
lda_scores$model <- predict(lda_fit)$class
66+
67+
# Compute niche centroid
68+
niche_centroid_lda <- lda_scores %>%
69+
yeet(model == "Niche") %>%
70+
no_cap(across(starts_with("LD"), mean))
71+
72+
# Centre
73+
lda_scores <- lda_scores %>%
74+
glow_up(
75+
LD1 = LD1 - niche_centroid_lda$LD1,
76+
LD2 = LD2 - niche_centroid_lda$LD2
77+
)
4878

79+
lda_endSims <- ggplot(lda_scores,
80+
aes(x = LD1,
81+
y = LD2,
82+
colour = model,
83+
fill = model)) +
84+
geom_hline(yintercept = 0,
85+
colour = "#A5ACAF") +
86+
geom_vline(xintercept = 0,
87+
colour = "#A5ACAF") +
88+
stat_ellipse(level = 0.95, linetype = 2,
89+
show.legend = FALSE) +
90+
geom_point(alpha = 0.7, size = 2.5,
91+
shape = 21) +
92+
scale_fill_manual(values = model_colours) +
93+
scale_colour_manual(values = model_colours) +
94+
labs(x = "LD1 (distance from niche)",
95+
y = "LD2",
96+
colour = "Model") +
97+
figure_theme +
98+
theme(legend.position = 'none')
4999

50100

101+
lda_topo_build +
102+
labs(title = "Topology, pre END") +
103+
lda_endSims +
104+
labs(title = "Topology, post END") +
105+
plot_layout(guides = 'collect')
51106

107+
ggsave("../figures/lda_compare.png",
108+
width = 10000,
109+
height = 4000,
110+
units = "px",
111+
dpi = 700)
190 KB
Loading

β€Žfigures/lda_compare.pngβ€Ž

3.3 MB
Loading

β€Žfigures/lda_corr.pngβ€Ž

731 Bytes
Loading

0 commit comments

Comments
Β (0)