# What exactly does scipy.stats.ttest_ind test?

From the description: "This is a two-sided test for the null hypothesis that 2 independent samples have identical average (expected) values."

Taken literally, this seems to be saying that we're testing $H_0: \bar{x} = \bar{y}$, but since we know both $\bar{x}$ and $\bar{y}$, it doesn't make sense.

Therefore I'm thinking what they really mean is that the Null Hypothesis is that both samples come from the same distribution, or that the mean of the respective populations is the same. Is that correct?

The quoted sentence:

This is a two-sided test for the null hypothesis that 2 independent samples have identical average (expected) values.

is a reference to the population means not the sample means; it is otherwise misleading and should certainly be clearer but they do t least say "(expected) values", which can only be a reference to population means from which the samples were drawn.

However, you were understandably misled by it and if a student wrote that I would certainly mark it wrong (since it does seem to suggest that it is the sample means being tested for equality, just as it did to you).

Therefore I'm thinking what they really mean is that the Null Hypothesis is that both samples come from the same distribution. Is that correct?

Usually the hypothesis that people wish to test with this hypothesis test is $H_0: \mu_X=\mu_Y$, but when accompanied by the assumptions of the usual equal variance two sample t-test, that's the same as saying they come from the same distribution. The assumption of equal variances is the default for the scipy implementation of this test, but set otherwise it doesn't assume equal variances and then the null doesn't imply that distributions are the same.

That's true of many of the commonly used hypothesis tests -- that the null (when combined with the assumptions) amounts to assuming equal distributions.

• Thank you, I didn't know that expected value could only be used in reference to a population. I guess it makes sense since EV is defined as $x \cdot P(X = x)$ and you can't speak of $P(X = x)$ just given a sample. Is it ok to think of populations as Random Variables, then? Or is it not ok because for example in a population you could be sampling without replacement? – jeremy radcliff Sep 18 '16 at 23:50
• "...but set otherwise it doesn't assume equal variances and then the null doesn't imply that distributions are the same.". What is the Null Hypothesis in such a case? – jeremy radcliff Sep 18 '16 at 23:54
• Values sampled from a population can sometimes be regarded as random variables; you often see statements like "Let $X_1, X_2, ,,,, X_n$ be a set of independent identically distributed values drawn from some distribution $F$"... if your population has distribution $F$ and you're using random sampling, the above statement is talking about the random variables representing your (future) first observation, second observation and so on. – Glen_b Sep 18 '16 at 23:55
• @jeremyradcliff In that case the null is just as stated -- it's still equality of means. – Glen_b Sep 18 '16 at 23:56
• Ah...yes of course (re: "still equality of means"), equal distributions in the first case because equal means + equal SD's are sufficient to determine that they are equal distributions. Thanks again. – jeremy radcliff Sep 18 '16 at 23:58

A bit more exact, see the docs you quoted

equal_var : bool, optional

If True (default), perform a standard independent 2 sample test that assumes equal population variances [R263]. If False, perform Welch’s t-test, which does not assume equal population variance [R264].

So it either performs student's or Welch's t-test for independent samples. BTW, Welch's test is recommended as of When conducting a t-test why would one prefer to assume (or test for) equal variances rather than always use a Welch approximation of the df?.