[R] t-test problem

(Ted Harding) Ted.Harding at manchester.ac.uk
Thu Jun 17 14:43:40 CEST 2010


On 16-Jun-10 22:30:39, Worik R wrote:
> I have two pairs of related vectors
>   x1,y1
> and
>   x2,y2
> 
> I wish to do a test for differences in means of x1 and y1,
>  ditto x2 and y2.
> 
> I am getting odd results.  I am not sure I am using 'pt' properly...
> I have not included the raw vectors as they are long.
> I am interested if I am using R properly...
> 
>> c(length(x1), length(y1), length(x2), length(y2))
> [1] 3436 1619 2677 2378
> 
> First where the T-stat and the DF do not give the same result as
> 't.test' when passed into 'pt'
> 
>> t.1 <- t.test(x1, y1)
>> 2 * pt(t.1$statistic, t.1$parameter)
>        t
> 1.353946
>> t.1$p.value
> [1] 0.646054
> 
> I would have thought these would have been the same.  Like below....
> 
>> t.2 <- t.test(x2, y2)
>> 2 * pt(t.2$statistic, t.2$parameter)
>         t
> 0.8679732
>> t.2$p.value
> [1] 0.8679732
> 
> This is what I expect.
> 
> clearly I misunderstand some thing.  What is it?
> 
> cheers
> Worik

The P-value is the tail-area (or the sum of the two tail-areas
for a two-sided test). The value of pt() is the total probability
to the left of the upper tail. Taking your results above:

[1]:
  t.1 <- t.test(x1, y1)
  2 * pt(t.1$statistic, t.1$parameter)
  #        t
  #  1.353946
  t.1$p.value
  #  [1] 0.646054

The "t.1$p.value" result will (by default) be the two-tailed test,
so one tail will have probability equal to half the P-value,
while the value of pt() will be Prob(T <= t1$statistic).
Hence the former will be 2*(1 - the latter) **provided the t-statistic
is positive** -- otherwise, if the t-statistic is negative, the
former is twice the latter.

. Check:

  2*(1 - 1.353946/2)
  # [1] 0.646054

  2*(1 - 0.646054/2)
  # [1] 1.353946

So this indicates that the t-value (which you did not quote) was
positive.

[2]:
  t.2 <- t.test(x2, y2)
  2 * pt(t.2$statistic, t.2$parameter)
  #        t
  #  0.8679732
  t.2$p.value
  #  [1] 0.8679732

  2*(1 - 0.8679732/2)
  # [1] 1.132027

(so no agreement), but:

  2*(0.8679732/2)
  # 0.8679732

so here the t-value was negative. And that is the difference between
thw two cases.

Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 17-Jun-10                                       Time: 13:43:37
------------------------------ XFMail ------------------------------



More information about the R-help mailing list