I am playing with the a 1-way anova with and without the "-1" option.

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

 From what I can tell:
1) the estimated means of the different levels are correctly estimated 
either way (although reported as means with the -1 and as contrasts without 
the -1 as expected)
2) the residuals are identical (in this contrived example they differ 
slightly due to numeric instability but in a more real-world example they 
truly are identical)
3) BUT the r2/F/p-value are different (in my real-world example they are 
drastically different)

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
CANADA

(514) 398-6417

http://www.brianmcgill.org
[EMAIL PROTECTED]

        [[alternative HTML version deleted]]

______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to