# Load dataset and required packages
woodpecker.data <- read.csv("/RLMM_and_hedgesg_data.csv")
library(esvis)
library(dplyr)


# Effect size calculation (Hedges' g) for principal components
hedgesG_PC1 <- as.data.frame(esvis::hedg_g(data = woodpecker.data, formula = RC1 ~ spp))
hedgesG_PC2 <- as.data.frame(esvis::hedg_g(data = woodpecker.data, formula = RC2 ~ spp))
hedgesG_PC3 <- as.data.frame(esvis::hedg_g(data = woodpecker.data, formula = RC3 ~ spp))


# Data formatting and filtering of redundant pairwise comparisons
names(hedgesG_PC1)[1:2] <- c("especie1", "especie2")
names(hedgesG_PC2)[1:2] <- c("especie1", "especie2")
names(hedgesG_PC3)[1:2] <- c("especie1", "especie2")

hpc1_pos <- hedgesG_PC1 %>% filter(hedg_g >= 0)
hpc2_pos <- hedgesG_PC2 %>% filter(hedg_g >= 0)
hpc3_pos <- hedgesG_PC3 %>% filter(hedg_g >= 0)


# Export final effect size matrices
write.csv(hpc1_pos, " /hedgespc1spp-positivos.csv", row.names = FALSE)
write.csv(hpc2_pos, Ò/hedgespc2spp-positivos.csv", row.names = FALSE)
write.csv(hpc3_pos, "/ hedgespc3spp-positivos.csv", row.names = FALSE)
