# Re: R-alpha: R: Bug in t.test

Peter Dalgaard BSA (pd@kubism.ku.dk)
03 Oct 1996 16:47:07 +0200

```To: A.Ledford@surrey.ac.uk
Subject: Re: R-alpha: R: Bug in t.test
From: Peter Dalgaard BSA <pd@kubism.ku.dk>
Date: 03 Oct 1996 16:47:07 +0200
In-Reply-To: Anthony Ledford's message of Thu, 3 Oct 1996 13:26:28 +0100 (BST)
Message-Id: <x220fg14wk.fsf@bush.kubism.ku.dk>

Anthony Ledford <mas2al@mcs.surrey.ac.uk> writes:

> > x1 <- c(243, 251, 275, 291, 347, 354, 380, 392)
> > x2 <- c(206, 210, 226, 249, 255, 273, 289, 295, 309)
> > t.test(x1,x2)
>
> Amongst other output, this gives ....
>
> 95 percent confidence interval:
>    9.421519 110.050703
>
> In R (v0.12): The same commands give
>
> 95 percent confidence interval:
>  263.8165 369.4335

Yes. I noticed that too. Here's the trouble spot:

if (var.equal) {
<snip>
else {
<snap>
stderr <- sqrt(stderrx^2 + stderry^2)
df <- stderr^4/(stderrx^4/(nx - 1) + stderry^4/(ny - 1))
tstat <- (mx - my - mu)/stderr
}
<---------------here------------------>
}
if (alternative == "less") {
pval <- pt(tstat, df)
cint <- c(NA, mx + qt(conf.level, df) * stderr)
}
...

So we get the mean of the first group with limits based on the SE of
*differences* of means...! Plop in an
mx <- mx - my
at the point marked <--here--> and things should be OK.

Speaking of t.test, I'm having slight difficulties with the
restriction that both nx and ny should be > 2.

What if you want to use it to test whether a single observation
belongs to a larger group? (This is the way one defines reference
intervals incorporating the estimator variation in the finite base
population.)

Nothing in the theory forbids this in the equal variance case. You get
0 DF for the variance in one group, but the pooled variance is
well-defined. The Welch test will of course break down. Granted, you
don't do this every day, but in particular in a pedagogical setting,
you might want to use it for demonstration purposes, so I don't see
the point in forbidding it.

--
O__  ---- Peter Dalgaard             Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics     2200 Cph. N
(*) \(*) -- University of Copenhagen   Denmark      Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk)             FAX: (+45) 35327907
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
```