library(readxl)
ant <- read_excel("stat data .xlsx", sheet = "Sheet2")

str(ant)
## Classes 'tbl_df', 'tbl' and 'data.frame':    48 obs. of  3 variables:
##  $ Location : num  1 1 1 1 1 1 2 2 2 2 ...
##  $ Abundance: num  2 4 2 4 1 3 1 5 3 4 ...
##  $ Density  : chr  "LOW" "HIGH" "LOW" "HIGH" ...
density <- as.factor(ant$Density)



species <- ant$Abundance
location <- ant$Location

Boxplot

boxplot(species ~ density)

ANOVA

ant.aov <- aov(species ~ density, data = ant)
summary(ant.aov)
##             Df Sum Sq Mean Sq F value   Pr(>F)    
## density      1  60.75   60.75   56.74 1.46e-09 ***
## Residuals   46  49.25    1.07                     
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(ant.aov)

library(emmeans)

comp <- emmeans(ant.aov, "density")
plot(comp)

pairs(comp)
##  contrast   estimate    SE df t.ratio p.value
##  HIGH - LOW     2.25 0.299 46 7.533   <.0001

This shows that the number of species is significantly different in areas of low and high plant density, with a very low p-value of < .0001.

TukeyHSD(ant.aov)
##   Tukey multiple comparisons of means
##     95% family-wise confidence level
## 
## Fit: aov(formula = species ~ density, data = ant)
## 
## $density
##           diff      lwr      upr p adj
## LOW-HIGH -2.25 -2.85125 -1.64875     0
plot(TukeyHSD(ant.aov))

## Two-Way ANOVA

twoway.aov <- aov(species ~ density + location, data = ant)
summary(twoway.aov)
##             Df Sum Sq Mean Sq F value  Pr(>F)    
## density      1  60.75   60.75  56.159 1.9e-09 ***
## location     1   0.57    0.57   0.528   0.471    
## Residuals   45  48.68    1.08                    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
plot(twoway.aov)

mod.aov <- aov(density ~ species, data = ant)
## Warning in model.response(mf, "numeric"): using type = "numeric" with a
## factor response will be ignored
## Warning in Ops.factor(y, z$residuals): '-' not meaningful for factors