[R] t.test()
Robin Hankin
r.hankin at noc.soton.ac.uk
Fri Nov 24 10:28:03 CET 2006
On 23 Nov 2006, at 13:46, 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]).
>>
[snip]
>>
>> What arguments do I need to send to t.test() to test my null?
>
>
[snip]
> 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)))
>
The "gotcha" in Peter Dalgaard's formula is that the maximum
likelihood estimate for the
variance, with a sample size of one, is zero. This is why var[x[1]]
doesn't appear.
[R reports var(1) as NA because it uses the unbiased formula with
(n-1) on the denominator,
as documented]
Last night I derived the likelihood test for testing my null. Consider
H1: x~N(mu_x,s^2); y~N(mu_y,s^2)
H2: x,y~N(mu,s^2)
The support gained by allowing the two means to differ [ie compare H2
to H1] is:
\[
E=
\frac{n}{2}\ln\left(
\frac{\sum(z_i-\overline{z})^2}{
\sum(x_i-\overline{x})^2+
\sum(y_i-\overline{y})^2
}\right)
\]
where z=c(x,y) is both sets of observations taken together. This
formula supposes one
uses the appropriate maximum likelihood estimate for the (common)
variance. Note that
the MLE for the variance is different on H1 and H2.
Thus if E > 2 we can reject H2 and if !(E <2) we can accept (sic) H2.
Robin Hankin
Uncertainty Analyst
National Oceanography Centre, Southampton
European Way, Southampton SO14 3ZH, UK
tel 023-8059-7743
More information about the R-help
mailing list