The Bonferroni method, also called the Bonferroni correction, controls for Type I Error by setting the significance level for each test to ensure the familywise error rate meets the stated significance level.
$p < \frac{\alpha_{fw}}{m}$
where $\alpha_{fw}$ is the familywise alpha and $m$ is the number of tests to be conducted.
The Bonferroni method can be conservative, especially when $m$ is large, leading to more chance of a [[Type II error]].
In [[R]], use `p.adjust(p, "bonferroni")` to adjust the p-values (this simply multiplies the p-values by $m$).
```R
lmod = lm(y ~ x, data=data)
n = length(data$x)
J = length(unique(data$x))
rss = sum(resid(lmod)^2)
sighat = sqrt(rss/(n-J))
ybar <- tapply(data$y, data$x, mean)
diff <- as.numeric(c(ybar[2] - ybar[1],
ybar[3] - ybar[1],
ybar[3] - ybar[1]))
se = sighat * sqrt(1/J^2 + 1/J^2)
t = diff/se
p = 2 * (1-pt(abs(t), df=n-J))
df = data.frame(dff, t, p)
names(df) = c("diff", "t", "p")
df
```
Another option is the `multcomp` package which overrides the `pairwise.t.test`.