[R] The equivalence of t.test and the hypothesis testing of one way ANOVA

Nutter, Benjamin NutterB at ccf.org
Thu Nov 5 15:38:35 CET 2009


Notice also

> t.stat <- t.test(x,y, var.equal=TRUE)$statistic

> F.stat <- summary(afit)[[1]][1,4]

> t.stat^2 == F.stat 
   t 
TRUE 


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Peng Yu
Sent: Thursday, November 05, 2009 9:21 AM
To: r-help at stat.math.ethz.ch
Subject: [R] The equivalence of t.test and the hypothesis testing of one
way ANOVA

I read somewhere that t.test is equivalent to a hypothesis testing for
one way ANOVA. But I'm wondering how they are equivalent. In the
following code, the p-value by t.test() is not the same from the value
in the last command. Could somebody let me know where I am wrong?

> set.seed(0)
> N1=10
> N2=10
> x=rnorm(N1)
> y=rnorm(N2)
> t.test(x,y)

	Welch Two Sample t-test

data:  x and y
t = 1.6491, df = 14.188, p-value = 0.1211 alternative hypothesis: true
difference in means is not equal to 0
95 percent confidence interval:
 -0.2156863  1.6584968
sample estimates:
 mean of x  mean of y
 0.3589240 -0.3624813

>
> A = c(rep('x',N1),rep('y',N2))
> Y = c(x,y)
> fr = data.frame(Y=Y,A=as.factor(A))
> afit=aov(Y ~ A,fr)
>
> X=model.matrix(afit)
> B=afit$coefficients
> V=solve(t(X) %*% X)
>
> mse=tail(summary(afit)[[1]]$'Mean Sq',1)
> df=tail(summary(afit)[[1]]$'Df',1)
> t_statisitic=(B/(mse * sqrt(diag(V))))[[2]] 
> 2*(1-pt(abs(t_statisitic),df))#the p-value from aov
[1] 0.1090802
>

______________________________________________
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.


===================================

P Please consider the environment before printing this e-mail

Cleveland Clinic is ranked one of the top hospitals
in America by U.S. News & World Report (2008).  
Visit us online at http://www.clevelandclinic.org for
a complete listing of our services, staff and
locations.


Confidentiality Note:  This message is intended for use\...{{dropped:13}}




More information about the R-help mailing list