@@ -27,7 +27,7 @@ df <- read_csv("data/outputs/topology.csv") %>%
2727 na.omit() %> %
2828 # set niche model as reference model
2929 glow_up(model = factor (model )) %> %
30- glow_up(model = relevel(model , ref = " ADBM " ))
30+ glow_up(model = relevel(model , ref = " Niche " ))
3131
3232# Dependent variable matrix for multivariate tests
3333# Assuming columns 2 onwards are your topological metrics
@@ -64,7 +64,7 @@ scores$model <- df$model
6464
6565# Compute niche centroid
6666niche_centroid <- scores %> %
67- yeet(model == " ADBM " ) %> %
67+ yeet(model == " Niche " ) %> %
6868 no_cap(across(starts_with(" Can" ), mean ))
6969
7070# Center all scores on niche
@@ -79,9 +79,11 @@ loadings_df <- as.data.frame(cda$structure[, 1:2]) %>%
7979 rownames_to_column(" Metric" ) %> %
8080 rename(CV1 = Can1 , CV2 = Can2 ) %> %
8181 glow_up(Level = case_when(
82- Metric %in% c(" complexity" , " connectance" , " trophic_level" ) ~ " Macro" ,
83- Metric %in% c(" generality" , " vulnerability" ) ~ " Micro" ,
84- TRUE ~ " Meso"
82+ Metric %in% c(" complexity" , " connectance" , " trophic_level" , " ChLen" ) ~ " Macro" ,
83+ Metric %in% c(" generality" ) ~ " Role" ,
84+ Metric %in% c(" vulnerability" , " top" ) ~ " Heterogeneity" ,
85+ Metric %in% c(" distance" ) ~ " Path" ,
86+ TRUE ~ " Scaling"
8587 ))
8688
8789# CDA Loadings Plot
@@ -94,7 +96,7 @@ ggplot(loadings_df, aes(x = CV1, y = CV2)) +
9496 arrow = arrow(length = unit(0.2 , " cm" )), linewidth = 1 ) +
9597 geom_text_repel(aes(label = Metric )) +
9698 coord_equal(xlim = c(- 1 , 1 ), ylim = c(- 1 , 1 )) +
97- scale_colour_manual(values = c(" #006D75" , " #2F2F2F" , " #EA7200" )) +
99+ scale_colour_manual(values = c(" #006D75" , " #2F2F2F" , " #EA7200" , " #B2B4B2 " , " #FFB81C " )) +
98100 figure_theme
99101
100102ggsave(" ../figures/lda_corr.png" ,
@@ -144,7 +146,7 @@ lda_scores$model <- df$model
144146
145147# Compute niche centroid
146148niche_centroid_lda <- lda_scores %> %
147- yeet(model == " ADBM " ) %> %
149+ yeet(model == " Niche " ) %> %
148150 no_cap(across(starts_with(" LD" ), mean ))
149151
150152# Centre
@@ -216,13 +218,16 @@ emm_df <- emm_df %>%
216218 TRUE ~ as.character(metric )
217219 )) %> %
218220 mutate(level = case_when(
219- metric %in% c(" complexity" , " connectance" , " trophic_level" ) ~ " Macro" ,
220- metric %in% c(" generality" , " vulnerability" ) ~ " Micro" ,
221- TRUE ~ " Meso"
221+ metric %in% c(" complexity" , " connectance" , " trophic_level" , " S2" , " S1" , " ChLen" ) ~ " Macro" ,
222+ metric %in% c(" generality" ) ~ " Role" ,
223+ metric %in% c(" vulnerability" , " top" ) ~ " Heterogeneity" ,
224+ metric %in% c(" distance" ) ~ " Path" ,
225+ metric %in% c(" centrality" ) ~ " Hubs" ,
226+ TRUE ~ " Scaling"
222227 ))
223228
224229# --- 2. Create Categorized Plot List ---
225- levs <- c(" Macro" , " Meso " , " Micro " )
230+ levs <- c(" Macro" , " Role " , " Heterogeneity " , " Path " , " Scaling " )
226231plot_list_emm <- vector(" list" , length = 3 )
227232
228233for (i in seq_along(levs )) {
@@ -256,8 +261,55 @@ for (i in seq_along(levs)) {
256261
257262# --- 3. Patchwork Assembly ---
258263# Adjusting heights to accommodate the number of facets in each level
259- (plot_list_emm [[1 ]] / plot_list_emm [[2 ]] / plot_list_emm [[3 ]]) +
260- plot_layout(heights = c(2 , 2 , 1 ), guides = " collect" )
264+ (plot_list_emm [[1 ]] / (plot_list_emm [[2 ]] + plot_list_emm [[4 ]]) /
265+ plot_list_emm [[3 ]] / plot_list_emm [[5 ]])+
266+ plot_layout(heights = c(3 , 1 , 1 , 1 ), guides = " collect" )
261267
262268# Save
263269ggsave(" ../figures/emm_summary.png" , width = 9 , height = 12 , dpi = 400 )
270+
271+ # =========================
272+ # 5. Standard Errors
273+ # =========================
274+
275+ sims <-
276+ read_csv(" data/outputs/topology.csv" ) %> %
277+ na.omit() %> %
278+ pivot_longer(- c(model ),
279+ names_to = " metric" ) %> %
280+ squad_up(model , metric )
281+
282+ # use Niche model as reference point
283+ ref_stats <- sims %> %
284+ yeet(model == " Niche" ) %> %
285+ squad_up(metric ) %> %
286+ no_cap(mu_ref = mean(value ),
287+ sd_ref = sd(value ))
288+
289+ comparison <- sims %> %
290+ squad_up(model , metric ) %> %
291+ no_cap(mu_model = mean(value , na.rm = TRUE )) %> %
292+ left_join(ref_stats , by = " metric" ) %> %
293+ glow_up(z = (mu_model - mu_ref ) / sd_ref )
294+
295+ ggplot(comparison %> %
296+ yeet(metric != " richness" )) +
297+ geom_hline(yintercept = 2 ,
298+ linetype = " dashed" ,
299+ colour = shark_silver ) +
300+ geom_hline(yintercept = - 2 ,
301+ linetype = " dashed" ,
302+ colour = shark_silver ) +
303+ geom_point(aes(x = metric ,
304+ y = z ,
305+ colour = model ),
306+ alpha = 0.7 ) +
307+ scale_colour_manual(values = model_colours ) +
308+ labs(x = " Model" ,
309+ y = " Normalised Error (niche as reference)" ) +
310+ figure_theme +
311+ theme(panel.grid.major = element_blank(),
312+ strip.text = ggtext :: element_markdown())
313+
314+
315+
0 commit comments