Skip to content
Prev 59708 / 398502 Next

T-test syntax question

As Vito Ricci has already pointed out, the Welsh test is for two group
unpaired data with unequal variance assumption.

If you have the original data, say x and y, then you can simply do
t.test( x, y, paired=FALSE, var.equal=FALSE ).

If you do not have the original data, you can still calculate the
relevant statistics and p-value as long as you know the group length and
variance. 'stats:::t.test.default' shows you the code behind t-test. I
think the relevant bits are as follows

mx <- 0
my <- 2
mu <- 0

# You will need to fill these with your observed values
vy <- var(y)
vx <- var(x)
ny <- length(y)
ny <- length(y)


stderrx <- sqrt(vx/nx)
stderry <- sqrt(vy/ny)
stderr  <- sqrt(stderrx^2 + stderry^2)
df      <- stderr^4/(stderrx^4/(nx - 1) + stderry^4/(ny - 1))
tstat   <- (mx - my - mu)/stderr

# for two sided alternative
pval  <- 2 * pt(-abs(tstat), df)
alpha <- 1 - conf.level
cint  <- qt(1 - alpha/2, df)
cint  <- tstat + c(-cint, cint)
cint  <- mu + cint * stderr
On Wed, 2004-11-24 at 04:28, Steve Freeman wrote: