Load the necessary libraries
library(tidyverse)
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag(): dplyr, stats
Here is a modified example from Quinn and Keough (2002). Day and Quinn (1989) described an experiment that examined how rock surface type affected the recruitment of barnacles to a rocky shore. The experiment had a single factor, surface type, with 4 treatments or levels: algal species 1 (ALG1), algal species 2 (ALG2), naturally bare surfaces (NB) and artificially scraped bare surfaces (S). There were 5 replicate plots for each surface type and the response (dependent) variable was the number of newly recruited barnacles on each plot after 4 weeks.
Format of day.csv data files
TREAT | BARNACLE |
---|---|
ALG1 | 27 |
.. | .. |
ALG2 | 24 |
.. | .. |
NB | 9 |
.. | .. |
S | 12 |
.. | .. |
TREAT | Categorical listing of surface types. ALG1 = algal species 1, ALG2 = algal species 2, NB = naturally bare surface, S = scraped bare surface. |
BARNACLE | The number of newly recruited barnacles on each plot after 4 weeks. |
day = read_csv('data/day.csv', trim_ws=TRUE)
## Parsed with column specification:
## cols(
## TREAT = col_character(),
## BARNACLE = col_integer()
## )
glimpse(day)
## Observations: 20
## Variables: 2
## $ TREAT <chr> "ALG1", "ALG1", "ALG1", "ALG1", "ALG1", "ALG2", "ALG2...
## $ BARNACLE <int> 27, 19, 18, 23, 25, 24, 33, 27, 26, 32, 9, 13, 17, 14...
Model formula: \[ y_i \sim{} \mathcal{Pois}(\lambda_i)\\ \mu_i = \boldsymbol{\beta} \bf{X_i} \]
where \(\boldsymbol{\beta}\) is a vector of effects parameters and \(\bf{X}\) is a model matrix representing the intercept and treatment contrasts for the effects of Treatment on barnacle recruitment.
Quinn, G. P., and K. J. Keough. 2002. Experimental Design and Data Analysis for Biologists. London: Cambridge University Press.