[R] a question about lm on t-test.
Eik Vettorazzi
E.Vettorazzi at uke.uni-hamburg.de
Tue Aug 16 10:23:22 CEST 2011
Hi,
you may have noticed, that your t-test and lm had not the same p-values
for the difference in means, which is calculated for group2 when you use
treatment contrasts and that is what R does by default (see
?contr.treatment). This is because R uses Welsh test by default. Pros
and cons are beyond this post, but look at
(t1<-t.test(extra~group,data=sleep,var.equal=T))
(s1<-summary(lm(extra~group,data=sleep)))
all.equal(s1$coef["group2","Pr(>|t|)"],t1$p.value)
The intercept in lm is tested against 0 (one sample t-test),
so the t-statistic is (mean-0)/sd, having n-k (sample size - number of
parameters) degrees of freedom.
cc<-s1$coef["(Intercept)",1:2]
2*(1-pt(cc[1]/cc[2],df=18))
hth.
Am 16.08.2011 07:25, schrieb Lao Meng:
> Hi all:
> I have a question about lm on t-test.
>
> data(sleep)
>
> I wanna perform t-test to test the difference between the 2 groups:
>
> I can use:
> t.test(extra~group)
>
> The t.test result shows that:t = -1.8608; mean1=0.75,mean2=2.33
>
>
> But I still wanna use:
> summary(lm(extra~group))
>
> Intercept=0.75,which is mean1,just the same as t.test.
> group2=1.58 means the difference of the 2 groups,so
> mean2=1.58+0.75=2.33,just the same as t.test.
> And some parameters of group2(t value,Pr) are the same as t.test,since
> group2 is the difference of the 2 groups.
>
> My question is:
> How the "t value" of Intercept(group1 acturally) is calculated?
>
>
> Thanks a lot.
>
> My best
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at 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.
--
Eik Vettorazzi
Institut für Medizinische Biometrie und Epidemiologie
Universitätsklinikum Hamburg-Eppendorf
Martinistr. 52
20246 Hamburg
T ++49/40/7410-58243
F ++49/40/7410-57790
More information about the R-help
mailing list