An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110816/1ff1c6aa/attachment.pl>
a question about lm on t-test.
12 messages · Jeff Newmiller, Lao Meng, Daniel Malter +1 more
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110815/ef6bc977/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110816/d2c2a219/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110815/47257ca7/attachment.pl>
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110816/eb487248/attachment.pl>
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110817/0ef53f93/attachment.pl>
Hi Lao, thats not the same test. The concept of linear regression applies here (and you might take any introductory at your hand to refresh that concept). The intercept is estimated from the whole sample not just group==1, dfs are 20-2, not sum(group==1)-1! best regards Am 17.08.2011 09:57, schrieb Lao Meng:
Thanks Eik.
As to your words:"The intercept in lm is tested against 0 (one sample
t-test)"
So, I perform the following test:
t.test(extra[group==1],mu=0)
Since goup1 is regarded as reference,I do the 1-sample ttest based on
group1's mean vs 0.
But the result:
t value= 1.3257
p-value = 0.2176
And t value and p value of s1 is:
t value= 1.249
p value= 0.2276
So the t value and p value are different between 1-sample ttest of
group1'mean vs 0 and s1(lm's result).
What's the reason for the difference then?
Thanks a lot for your help.
My best.
2011/8/16 Eik Vettorazzi <E.Vettorazzi at uke.uni-hamburg.de
<mailto:E.Vettorazzi at uke.uni-hamburg.de>>
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 <mailto: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
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20110818/d7253ca3/attachment.pl>
Pick up a book or the like on ordinary least squares regression, which is what lm() in its plain vanilla application does. The t-value is the estimated coefficient divided by the standard error. The standard errors of the coefficients are the diagonal entries of the variance-covariance matrix. x<-rnorm(100) y<-2+x+rnorm(100) reg<-lm(y~x) summary(reg)$coefficients sqrt(diag(vcov(reg))) See also: http://en.wikipedia.org/wiki/Ordinary_least_squares HTH, Daniel
Lao Meng wrote:
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.
-- View this message in context: http://r.789695.n4.nabble.com/a-question-about-lm-on-t-test-tp3746371p3752025.html Sent from the R help mailing list archive at Nabble.com.
That is a speciality of your model - it is actually an ANOVA-model (with 2 groups). Even so the variance of the intercept is estimated from the whole sample, not only for group==1 (thats why the statistics and p-values differ) - and that analysis is equivalent to a t-test with common variance (aka classical t-test). A different kettle of fish is a regression with continuous predictors like (s1<-summary(lm(extra~as.numeric(group),data=sleep))) where your estimates depend on the coding of group. cheers. Am 18.08.2011 08:50, schrieb Lao Meng:
Well,since the intercept is the same as mean of group1,I take it for
granted that the 1-sample ttest must test based on group==1...
If the intercept is estimated from the whole sample,why does the
intercept is the same as mean of group1?
2011/8/17 Eik Vettorazzi <E.Vettorazzi at uke.uni-hamburg.de
<mailto:E.Vettorazzi at uke.uni-hamburg.de>>
Hi Lao,
thats not the same test. The concept of linear regression applies here
(and you might take any introductory at your hand to refresh that
concept). The intercept is estimated from the whole sample not just
group==1, dfs are 20-2, not sum(group==1)-1!
best regards
Am 17.08.2011 09:57, schrieb Lao Meng:
> Thanks Eik.
> As to your words:"The intercept in lm is tested against 0 (one sample
> t-test)"
>
> So, I perform the following test:
> t.test(extra[group==1],mu=0)
>
> Since goup1 is regarded as reference,I do the 1-sample ttest based on
> group1's mean vs 0.
> But the result:
> t value= 1.3257
> p-value = 0.2176
>
> And t value and p value of s1 is:
> t value= 1.249
> p value= 0.2276
>
> So the t value and p value are different between 1-sample ttest of
> group1'mean vs 0 and s1(lm's result).
>
> What's the reason for the difference then?
>
> Thanks a lot for your help.
>
> My best.
>
>
> 2011/8/16 Eik Vettorazzi <E.Vettorazzi at uke.uni-hamburg.de
<mailto:E.Vettorazzi at uke.uni-hamburg.de>
> <mailto:E.Vettorazzi at uke.uni-hamburg.de
<mailto:E.Vettorazzi at uke.uni-hamburg.de>>>
>
> 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 <mailto:R-help at r-project.org>
<mailto:R-help at r-project.org <mailto:R-help at r-project.org>> mailing list
> > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide
> > 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
>
>
--
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
Eik Vettorazzi Department of Medical Biometry and Epidemiology University Medical Center Hamburg-Eppendorf Martinistr. 52 20246 Hamburg T ++49/40/7410-58243 F ++49/40/7410-57790
I should have written "the standard errors of the coefficients are the SQUARE ROOT of the diagonal entries of the variance-covariance matrix," as I programmed it in the code.
Daniel Malter wrote:
Pick up a book or the like on ordinary least squares regression, which is what lm() in its plain vanilla application does. The t-value is the estimated coefficient divided by the standard error. The standard errors of the coefficients are the diagonal entries of the variance-covariance matrix. x<-rnorm(100) y<-2+x+rnorm(100) reg<-lm(y~x) summary(reg)$coefficients sqrt(diag(vcov(reg))) See also: http://en.wikipedia.org/wiki/Ordinary_least_squares HTH, Daniel Lao Meng wrote:
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.
-- View this message in context: http://r.789695.n4.nabble.com/a-question-about-lm-on-t-test-tp3746371p3752068.html Sent from the R help mailing list archive at Nabble.com.