1

I have two (normally distributed) samples:

First: n=50 mean=3 sd=2

Second: n=40 mean=3.5 sd=1.9

Is this enough to perform two-sample and two-sided Student's t-test with equal variances? If yes, how can I compute p-value in R? Function t.test() accepts only original data.

Thank you in advance.

sitems
  • 3,649
  • 1
  • 25
  • 52
  • See responses on [this question](http://stats.stackexchange.com/questions/30394/how-to-perform-two-sample-t-tests-in-r-by-inputting-sample-statistics-rather-tha) – Glen_b Jul 28 '13 at 14:33

1 Answers1

4

Yes, you can. Just plug-and-chug these values into the t-test formula. I'm going to assume the samples are independent, and this is an unpaired two-tailed test:

$ t= \frac{\left | \bar{X_1} - \bar{X_2} \right |}{\sqrt{s_1^2 /n_1 + s_2^2 /n_2 }} $

Once you've calculated this t statistic, compare it against the appropriate t-value for the significance level you are testing for at $df = n_1 +n_2 - 2$. At $df = 88$, $t \geq 1.99$ gives a significance of $p \leq 0.05$ (via this t-table). In your case, $t=1.21$, so your sample means are not significantly different at the $p=0.05$ level.

If you need to calculate the exact p-value, instead of looking it up in a t-table you can use the r function for the $t$ CDF, pt(), which gives $p = 0.2288375$ for your data when you specify that you want the upper tail of the distribution (lower.tail=F) and double your result for a two-tailed test.

Here's the whole thing wrapped in a little function in case you have more similar tests to run:

homebrew_two_tailed_t_test = function(m1, m2, n1, n2, s1, s2){
  t = abs(m1-m2)/sqrt(s1^2/n1 + s2^2/n2)
  2*pt(t, n1 + n2 -2, lower.tail=F)
}

>homebrew_two_tailed_t_test(3.5, 3, 50, 40, 2, 1.9)
0.2288375
David Marx
  • 6,647
  • 1
  • 25
  • 43
  • Thank you, but what about p-value? – sitems Jul 28 '13 at 13:27
  • Reference my edited post – David Marx Jul 28 '13 at 13:33
  • Sorry, I still do not see how to compute p-value. Tables for Student test are not p-values. – sitems Jul 28 '13 at 13:38
  • The table I linked you gives the reference t-value for a given p value with the degrees of freedom of your test. Check the link. – David Marx Jul 28 '13 at 13:52
  • P-value is number between zero and one. No number from your answer satisfies this except p=0.05 but this is alpha, not exact p-value. – sitems Jul 28 '13 at 13:54
  • 1
    Assuming David Marx calculated the $t$-value and the $df$ correctly, `R` gives a p-value of: `pt(1.69, 88, lower.tail = FALSE)` = `0.04728384`. Note that this is a one-sided test, so you need to multiply it by two for the two sided test which is (non-significant): `0.0946`. – Henrik Jul 28 '13 at 14:29
  • 2
    FYI there was a slight miscalculation earlier in the t figure I gave: i had treated the standard deviations you provided as though they were variances. I updated my answer to give you the correct t and corresponding p values, and have also provided a small r snippet for you. – David Marx Jul 28 '13 at 14:40