#Research question: Does the weight of Village Weavers vary across years? #--------------------------------------------- # Using Village Weaver data #--------------------------------------------- # Load necessary packages library(dplyr) # for data manipulation library(ggplot2) # for data visualization library(car) # for Levene's Test weaver<-read.csv('villageweaver.csv') str(weaver) # Convert 'year' to a categorical variable (factor) weaver$year2 <- as.factor(weaver$year) str(weaver) # Check ANOVA Assumption: Before performing ANOVA, we must check: # Normality – whether weight values are normally distributed. # Homogeneity of variance – whether the spread (variance) is similar across years. # Shapiro-Wilk test for overall normality shapiro.test(weaver$weight) # Homogeneity of Variance (Levene’s Test) leveneTest(weaver$weight ~ weaver$year2) # If normally distributed, One-way ANOVA anova_model <- aov(weaver$weight ~ weaver$year2) summary(anova_model) #If not normally distributed, Kruskall-Wallis kruskal.test(weaver$weight ~ weaver$year2) # Visualise Data (Boxplot) ggplot(weaver, aes(x = year2, y = weight, fill = year2)) + geom_boxplot() + theme_classic() + labs(x = "Year", y = "Weight (g)") # To remove legend ggplot(weaver, aes(x = year2, y = weight, fill = year2)) + geom_boxplot() + theme_classic() + theme(legend.position = "none") + labs(x = "Year", y = "Weight (g)") # Using geom_violin (combines boxplot and density shape, to visualize both # spread and distribution.) ggplot(weaver, aes(x = year2, y = weight, fill = year2)) + geom_violin(trim = FALSE) + geom_boxplot(width = 0.2, fill = "white") + theme_classic() + theme(legend.position = "none") + labs(x = "Year", y = "Weight (g)")