require(Sleuth3)
## Loading required package: Sleuth3
elephants <- case2201
Let’s plot the data
qplot(Age,Matings,data=elephants) + geom_smooth(method=lm)
qplot(log(Age), Matings,data=elephants) + geom_smooth(method=lm)
It looks like the residuals increase with age. Let’s visualize the residuals directly.
linear_fit <- lm(Matings~Age, data=elephants)
plot(linear_fit, 1)
That’s what we would expect from Poisson-distributed counts – the variance of \(Poisson(\lambda)\) is \(\lambda\).
fit <- glm(Matings ~ Age, family= "poisson", data= elephants)
summary(fit)
##
## Call:
## glm(formula = Matings ~ Age, family = "poisson", data = elephants)
##
## Deviance Residuals:
## Min 1Q Median 3Q Max
## -2.80798 -0.86137 -0.08629 0.60087 2.17777
##
## Coefficients:
## Estimate Std. Error z value Pr(>|z|)
## (Intercept) -1.58201 0.54462 -2.905 0.00368 **
## Age 0.06869 0.01375 4.997 5.81e-07 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## (Dispersion parameter for poisson family taken to be 1)
##
## Null deviance: 75.372 on 40 degrees of freedom
## Residual deviance: 51.012 on 39 degrees of freedom
## AIC: 156.46
##
## Number of Fisher Scoring iterations: 5