On Mon, 20 Sep 2010, Jabez Wilson wrote:

Hi, I am trying to reconcile anova table in R (summary(lm)) with individual 
t.test.
datafilename="http://personality-project.org/R/datasets/R.appendix1.data";
data.ex1=read.table(datafilename,header=T)   #read the data into a table
summary(lm(Alertness~Dosage,data=data.ex1))

gives:

Call:
lm(formula = Alertness ~ Dosage, data = data.ex1)

Residuals:
???? Min???????? 1Q Median???????? 3Q?????? Max
-8.500 -2.437?? 0.250?? 2.687?? 8.500

Coefficients:
?????????????????????? Estimate Std. Error t value Pr(>|t|)??????
(Intercept)???? 32.500?????????? 2.010?? 16.166 6.72e-11 ***
Dosageb???????????? -4.250?????????? 2.659?? -1.598 0.130880??????
Dosagec?????????? -13.250?????????? 3.179?? -4.168 0.000824 ***
---
Signif. codes:?? 0 ???***??? 0.001 ???**??? 0.01 ???*??? 0.05 ???.??? 0.1 ??? 
??? 1

Residual standard error: 4.924 on 15 degrees of freedom
Multiple R-squared: 0.5396,???????? Adjusted R-squared: 0.4782
F-statistic: 8.789 on 2 and 15 DF,?? p-value: 0.002977

As far as I understand it the lines "Dosageb" and "DosageC" represent the 
difference between DosageA and the other two dosages.
My question is this: are these differences and the p-values associated with 
them the same as a t.test or pairwise.t.test on these groups? If I do t.tests, 
I get different values for t and p-value from those in the anova table above.


The t tests in the table use all the data to estimate a residual variance that 
is used to calculate the standard error, whereas t.test() uses just two groups. 
 If you use pairwise.t.test() with pool.sd=TRUE you will get the same p-values.

There is another reason for the difference from t.test(), which is that t.test() does not 
assume equal variance in the outcome across groups.  If you were to use 
vcovHC(,type="HC0") from the 'sandwich' package to estimate the standard errors 
in the linear model these would also not assume equal variance.  The tests would still 
not be identical, although they would be very similar in large samples.  The reasons they 
would not be identical are
  - some differences in using n vs n-p vs n1+n2-2 in denominators
  - different approximations to the denominator degrees of freedom.


      -thomas

Thomas Lumley
Professor of Biostatistics
University of Washington, Seattle

______________________________________________
R-help@r-project.org 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