---
title: "Poisson Elephants"
output: html_document
---

```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```

```{r include=FALSE, message=FALSE}
require(ggplot2)
```

```{r}
require(Sleuth3)
elephants <- case2201
```

Let's plot the data
```{r}
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.

```{r}
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$.

```{r}
fit <- glm(Matings ~ Age, family= "poisson", data= elephants)
summary(fit)


