[R] t.test()

Prof Brian Ripley ripley at stats.ox.ac.uk
Thu Nov 23 15:03:39 CET 2006


On Thu, 23 Nov 2006, Peter Dalgaard wrote:

> Robin Hankin <r.hankin at noc.soton.ac.uk> writes:
>
>> Hi
>>
>> I have a vector x of length n.   I am interested in x[1]
>> being different from the other observations (ie x[-1]).
>>
>> My null hypothesis  is that x[1]
>> is drawn from a Gaussian distribution of the same
>> mean as observations x[-1], which are assumed
>> to be iid Gaussian.   The (unknown) variance
>> of x[1] is assumed to be the same as the
>> variance of x[-1].
>>
>>
>> This should be an unpaired t-test.
>>
>> But
>>
>>
>> > x <- c(23,25,29,27,30,30)
>> > t.test(x=x[1] , y=x[-1])
>> Error in t.test.default(x = x[1], y = x[-1]) :
>>          not enough 'x' observations
>> >
>>
>>
>>
>> What arguments do I need to send to t.test() to test my null?
>
>
> You can't. Shouldn't be too much of a problem to modify t.test.default
> to stop it complaining. (It's not quite enough to remove the check for
> nx < 2, though. You also need to deal with var(x) being NA if x has
> length one.)

And the check is correct if var.equal=FALSE, the default. I've got a 
modification for the case var.equal=TRUE running, and will patch R 
shortly.

> Alternatively, just write up the formula for the t statistic:
>
>> x <- c(23,25,29,27,30,30)
>> (x[1]-mean(x[-1]))/sqrt(var(x[-1])*(1+1/(length(x)-1)))
> [1] -2.189595
>> 2*pt(-2.1896,4)
> [1] 0.09373392
>
>
>

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595



More information about the R-help mailing list