# What statistical analysis to run for count data in R?

I am working with deer count data across three years where counts were taken in the spring and fall seasons. Basically, I want to compare counts taken in spring to counts taken in the fall, to see if the number of deer observed differs between the seasons. The count surveys were all done at the same location and multiple surveys were done in each season of each year. The program I'm using is R.

This sounds like a relatively simple stats question to me, but I'm new to R and am not sure what kind of a statistical analysis I should run. Any advice would be greatly appreciated!

Edit for clarity: There is only one location. All surveys were conducted on the same ranch along the same stretch of road.

• Sounds like a job for a generalized linear model with Poisson or Negative Binomial dependent variable (the first example in ?glm is asuch a thing) and seasonal dummies effects. Do you need help with the GLM part or the model specification part (or both)? Apr 3, 2016 at 22:58
• Ah, with multiple surveys per location too. Not such a simple stats question, but perfectly doable. Apr 3, 2016 at 23:02

I'd recommend starting off using a Poisson regression model, which is well suited for count models. Since you seem to have multiple counts at different locations, you will need to use a method that takes into account the correlation of these observations within their clusters? I would suggest using a Generalized Estimating Equations (GEE) approach or a mixed model approach. If you aren't interested in examining differences between measurement sites, then I'd recommend going with GEE since it offers population average estimates. There are plenty of posts on Cross-Validated that describe GEE and mixed models.

• +1 for the mixed model suggestion. Specifically, in lme4 mod <- glmer(count ~ (1 | location) + year + season, family=poisson) would seem to be a reasonable starting point. Apr 3, 2016 at 23:32
• There is only one location. All surveys were conducted on the same ranch along the same stretch of road. Would the Poisson regression model still be a good starting place? Apr 6, 2016 at 0:42
• I see. That makes the reasonable starting model simpler, say: mod <- glm(count ~ year + season, family=poisson). Pretty much as per @antoni-parellada's second answer actually. Apr 6, 2016 at 2:41
• Of course. Multiple locations doesn't mean you need to stop using Poisson. You should see if a Poisson models fits well. If so, great. If not, you might need to think about more flexible models like a negative binomial regression (Poisson is a special case of this). Apr 10, 2016 at 2:30

One simplified approach would entail pooling the counts for spring over the three-year interval, and the counts for fall over the same three years, separately. You can approach this as a goodness-of-fit (GoF) chi-squared test. The idea is that the number of counts would (under the null hypothesis of no difference between seasons) follow a uniform distribution across seasons.

For instance,

counts = c(spring = 453, fall = 324)
chisq.test(counts, p = c(0.5,0.5), correct = F)

Chi-squared test for given probabilities

data:  counts
X-squared = 21.417, df = 1, p-value = 3.695e-06


A more complete approach would entail setting up a Poisson regression model in which the explanatory variables are season and year:

counts = c(139, 111, 152, 92, 162, 121)
year = rep(c("'14","'15","'16"), 2)
season = rep(c("spring","fall"), 3)
dat = data.frame(counts, year, season)
summary(glm(counts ~ year + season, family=poisson))

Call:
glm(formula = counts ~ year + season, family = poisson)

Deviance Residuals:
1        2        3        4        5        6
0.3707  -0.2671  -0.5720  -0.4440   0.2243   0.6644

Coefficients:
Estimate Std. Error z value Pr(>|z|)
(Intercept)   4.56772    0.07828  58.348  < 2e-16 ***
year'15       0.16705    0.08940   1.869   0.0617 .
year'16       0.16705    0.08940   1.869   0.0617 .
seasonspring  0.33515    0.07276   4.606  4.1e-06 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

(Dispersion parameter for poisson family taken to be 1)

Null deviance: 27.3707  on 5  degrees of freedom
Residual deviance:  1.2248  on 2  degrees of freedom
AIC: 49.333

Number of Fisher Scoring iterations: 3

• This is a great answer. However, I don't see how adjusting for time effects is helpful. The goal is to estimate seasonal differences in deer sightings in one jurisdiction. The common yearly shocks experienced in one location is, by definition, common to all seasons in that year. I would assume in this setting you could obtain the same result by using one seasonal dummy. Any thoughts? May 6, 2021 at 4:36
• @ThomasBilach I was trying (and still am) to teach myself these concepts with the advantage of the immediate feedback that coding provides, but I can't provide you with personal experience, and I am currently exploring other areas to delve into your thoughtful comment. Please feel free to share this and other thoughts in a separate answer, or to edit mine as you see fit. Best wishes. May 21, 2021 at 14:40

There is a debate in biology and ecology studies about transformation (e.g. log-transform) or model reformation (GLM) in dealing with count data. It really depends on the outcome you want to achieve and the cost (error) you can bear. If you want to visualize the data using the boxplot and avoid outliers, I would recommend transforming the data. If you want to develop statistical models, GLM models are recommended. Please keep in mind count data are nonparametric data, a t-test is not recommended. Please also refer to this paper and this page. It has a good description of the history of the debate I mentioned at the beginning.

A basic statistical test you can do is the unpaired t-test. This will give you t-value and a confidence interval (default 95%) to determine if there is a "true" difference between the number of deer in spring versus fall. R code below:

t.test(spring_deer_count, fall_deer_count)


If your t-value falls outside the confidence interval, you can safely reject the null hypothesis and accept the alternative hypothesis.

• Assuming that every year is equivalent and collapsing their counts seems a little strong (and inefficient), no? Apr 3, 2016 at 23:00
• Why do you recommend a t-test for count data? Apr 4, 2016 at 8:09