Introduction

This report examines how caterpillar abundance varies across habitat types, using a Poisson generalised linear model and a boxplot of counts by habitat.

Packages

## Load packages  
library(dplyr)
library(ggplot2)
library(here)

Data

Import

Caterpillar counts and their associated habitat are read in from a CSV file, using here::here() so the path resolves without relying on local file paths.

## Load caterpillar abundance data (w/o local file paths)
data <- read.csv(here("caterpillar_data", "data.csv"))

Descriptive summary

The mean number of caterpillars, with standard deviation, is summarised by habitat.

## Summarise the mean number of caterpillars with error
summary_data <- data %>%
  group_by(habitat) %>%
  summarise(
    mean_count = mean(caterpillar_count),
    sd = sd(caterpillar_count),
  )

Removing erroneous records

Values from habitat D are removed, as these are known to be an error.

## Remove values from habitat D as these are an error
filtered_data <- data %>%
  filter(habitat != "D")

Statistical analysis

A Poisson generalised linear model is used to analyse caterpillar abundance by habitat.

## Run a Poisson general linear model to analyse caterpillar abundance varying with habitat. Produces numeric results in “Caterpillar Abundance”
model1 <- glm(caterpillar_count ~ habitat,
              family = poisson, data = filtered_data)

summary(model1)
## 
## Call:
## glm(formula = caterpillar_count ~ habitat, family = poisson, 
##     data = filtered_data)
## 
## Coefficients:
##             Estimate Std. Error z value Pr(>|z|)    
## (Intercept)  1.73460    0.07670  22.616  < 2e-16 ***
## habitatB     0.43636    0.09841   4.434 9.25e-06 ***
## habitatC     0.94413    0.09039  10.445  < 2e-16 ***
## habitatE     1.49488    0.08486  17.615  < 2e-16 ***
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 592.00  on 119  degrees of freedom
## Residual deviance: 113.59  on 116  degrees of freedom
## AIC: 632.93
## 
## Number of Fisher Scoring iterations: 4

Habitat significantly alters caterpillar abundance.

Visualisation

## Create figure 1, caterpillar count against habitat
figure1 <- ggplot(
  filtered_data,
  aes(x = habitat, y = caterpillar_count)
) +
  geom_boxplot() +
  theme_bw()

print(figure1)

Habitat E has the highest caterpillar count.