# [R] T-test syntax question

Adaikalavan Ramasamy ramasamy at cancer.org.uk
Wed Nov 24 11:55:32 CET 2004

```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:
> Hi.
>
> I'd like to do a t-test to compare the Delta values of items with Crit=1
> with Delta values of items with Crit=0. What is the t.test syntax?
>
> It should produce a result like this below (I can't get in touch with the
> person who originally did this for me)
>
>     Welch Two Sample t-test
>
> data:  t1\$Delta by Crit
> t = -3.4105, df = 8.674, p-value = 0.008173 alternative hypothesis: true
> difference in means is not equal to 0
> 95 percent confidence interval:
>  -0.04506155 -0.00899827
> sample estimates:
> mean in group FALSE  mean in group TRUE
>          0.03331391          0.06034382
>
> Thanks.
>
> ------------------------------------
> Steven F. Freeman * Center for Organizational Dynamics * University of
> Pennsylvania * (215) 898-6967 * Fax: (215) 898-8934 * Cell: (215) 802-4680 *
> stfreema at sas.upenn.edu * http://center.grad.upenn.edu/faculty/freeman.html
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
--
Adaikalavan Ramasamy                    ramasamy at cancer.org.uk
Centre for Statistics in Medicine       http://www.ihs.ox.ac.uk/csm/
Cancer Research UK                      Tel : 01865 226 677
Old Road Campus, Headington, Oxford     Fax : 01865 226 962

```

More information about the R-help mailing list