type.f<-factor(type,label=c('nonecho bats','birds','echo bats'))
contrasts(type.f)birds echo bats nonecho bats 0 0 birds 1 0 echo bats 0 1
new.model<-lm(log(energy)~log(mass)+type.f, data=bats)This fits the model shown below.
nonecho bats: β0
birds: β0 + β2
echo bats: β0 + β3
> summary(new.model,corr=F)
Call:
lm(formula = log(energy) ~ log(mass) + type.f)Residuals:
Min 1Q Median 3Q Max
-0.23224 -0.12199 -0.03637 0.12574 0.34457Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -1.57636 0.28724 -5.488 4.96e-05 ***
log(mass) 0.81496 0.04454 18.297 3.76e-12 ***
type.fbirds 0.10226 0.11418 0.896 0.384
type.fecho bats 0.07866 0.20268 0.388 0.703
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1Residual standard error: 0.186 on 16 degrees of freedom
Multiple R-Squared: 0.9815, Adjusted R-squared: 0.9781
F-statistic: 283.6 on 3 and 16 DF, p-value: 4.464e-14
- The first hypothesis, H0: β2 = 0 , corresponds to a test of whether nonecho bats and birds have the same intercept. This test appears in the line labeled type.fbirds in the summary output.
- The second hypothesis, H0: β3 = 0, tests whether echo bats and nbats have the same intercept. This corresponds to the line labeled type.fecho bats in the summary output.

We can apply this basic formula to test H0: β2 β3 = 0, but to do so we need an estimate of β2 β3 and its standard error.

Here the ci are just numbers while the βi are the parameters of interest.


Thus we see that the terms we need define the submatrix occupying rows 3 through 4 and column 3 through 4 of this matrix.


, where m is the number of groups.
, where m is the number of groups. If you know a little linear algebra you'll recognize that the operation being described here is what's called the dot product or scalar product between two vectors. Note: This last condition needs to be modified if the groups being contrasted have unequal sample sizes. Group |
Regressor 1 |
Regressor 2 |
nonecho bats |
1 |
1 |
birds |
2 |
0 |
echo bats |
1 |
1 |
![]()
nonecho bats:
birds: ![]()
echo bats: ![]()

, where ni is the sample size of group i. The hypothesis being tested by these coefficients is less interpretable than in the balanced case. | Jack Weiss Phone: (919) 962-5930 E-Mail: jack_weiss@unc.edu Address: Curriculum in Ecology, Box 3275, University of North Carolina, Chapel Hill, 27516 Copyright © 2006 Last Revised--March 18, 2006 URL: http://www.unc.edu/courses/2006spring/ecol/145/001/docs/lectures/lecture30.htm |