[R] t.test()
Peter Dalgaard
p.dalgaard at biostat.ku.dk
Thu Nov 23 14:46:00 CET 2006
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.)
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
--
O__ ---- Peter Dalgaard Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907
More information about the R-help
mailing list