# [R] Don't understand removing constant on 1-way ANOVA

From: Brian McGill <brian.mcgill_at_mcgill.ca>
Date: Thu, 07 Feb 2008 17:56:07 -0500

I have a simple cooked up example below but it behaves the same on a more complex real example.

How can a model that gets the same parameter estimates on the same data leading to the same residuals get different r2/F/p-value?

I suspect it depends on the difference in the model.matrix (see below) but this just confused me how it got the same parameter estimates without really clearing up why the r2's are different.

Any help on this is greatly appreciated!

> x<-as.factor(c(1,1,1,2,2,2))
> y<-c(1.1,1.0,0.9,2.0,2.1,1.9)
> summary(lm(y~x))

Call:
lm(formula = y ~ x)

Residuals:

1 2 3 4 5 6   1.000e-01 -4.980e-16 -1.000e-01 8.538e-18 1.000e-01 -1.000e-01

Coefficients:

```             Estimate Std. Error t value Pr(>|t|)
(Intercept)  1.00000    0.05774   17.32 6.52e-05 ***
x2           1.00000    0.08165   12.25 0.000255 ***
```
```---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.1 on 4 degrees of freedom
Multiple R-Squared: 0.974,      Adjusted R-squared: 0.9675
F-statistic:   150 on 1 and 4 DF,  p-value: 0.0002552

> summary(lm(y~x-1))

Call:
lm(formula = y ~ x - 1)

Residuals:
1          2          3          4          5          6
1.000e-01  5.027e-16 -1.000e-01  4.405e-20  1.000e-01 -1.000e-01

Coefficients:
Estimate Std. Error t value Pr(>|t|)
x1  1.00000    0.05774   17.32 6.52e-05 ***
x2  2.00000    0.05774   34.64 4.14e-06 ***
---
Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1

Residual standard error: 0.1 on 4 degrees of freedom
Multiple R-Squared: 0.9973,     Adjusted R-squared: 0.996
F-statistic:   750 on 2 and 4 DF,  p-value: 7.073e-06

> m2nc=lm(y~x-1)
> m2wc=lm(y~x)

> resid(m2nc)

1             2             3             4             5
6
1.000000e-01  5.026734e-16 -1.000000e-01  4.404571e-20  1.000000e-01
-1.000000e-01

> resid(m2wc)

1             2             3             4             5
6
1.000000e-01 -4.980012e-16 -1.000000e-01  8.538092e-18  1.000000e-01
-1.000000e-01

> model.matrix(m2nc)

x1 x2
1  1  0
2  1  0
3  1  0
4  0  1
5  0  1
6  0  1
attr(,"assign")
[1] 1 1
attr(,"contrasts")
attr(,"contrasts")\$x
[1] "contr.treatment"

> model.matrix(m2wc)

(Intercept) x2
1           1  0
2           1  0
3           1  0
4           1  1
5           1  1
6           1  1
attr(,"assign")
[1] 0 1
attr(,"contrasts")
attr(,"contrasts")\$x
[1] "contr.treatment"

Brian McGill
Dept of Biology
McGill University
Stewart Biology Bldg
1205 ave Docteur Penfield
Montreal, QC H3A 1B1

(514) 398-6417

http://www.brianmcgill.org
mail_at_brianmcgill.org

[[alternative HTML version deleted]]

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
and provide commented, minimal, self-contained, reproducible code.
```
Received on Thu 07 Feb 2008 - 23:00:31 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 08 Feb 2008 - 07:30:12 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.