All about T-tests — demystified

Parul Singh
Analytics Vidhya
Published in
3 min readJul 19, 2020

T-test is one of the most widely used test for hypothesis testing in the world of statistics. Given the wide variety of these, it often confuses us when to use what. In this post, I have tried to cover “how, when&where” of t -tests.

T-tests are applied when there is one measurement variable in your data. Well, measurement variables are, as name implies, things you can measure. Other names for them include “numeric” or “quantitative” variables.

Without further adieu, let’s begin..

One sample t test/ Student’s t test

This test is used to find out if there is a statistically significant difference between mean of the measurement variable and its theoretical expectation.

Let me give you an example from physics to make it easy to grasp. Suppose you’ve made several observations of the mass of a new subatomic particle and now you want to know whether the mean mass from data fit the mass predicted by the Standard Model of particle physics? The null hypothesis here would be that calculated mean mass is equal to theoretical mass.

The test statistic can be calculated using :

ts=(X-μ)/(s/√n)

(where X is the sample mean, μ is the mean expected under the null hypothesis, s is the sample standard deviation and n is the sample size)

Reading from t table would require a calculated t value and degrees of freedom (here it would be n-1)

The t test assumes that the observations follow a normal distribution. A severely skewed data with less number of observations will not give reliable results for one sample t test. Therefore you might need to apply some sort of data transformations like log transformation, square root transformation to satisfy the pre-requisites.

Still, if your data is abnormal, you can use non-parametric test like Mann-Whitney test

Two sample t test

This test is used when you want to find out if there is a statistically significant difference between means of the measurement variable in the two groups. Null hypothesis in this case would be, both the means are equal.

For example, It is believed that the average amount of time boys and girls ages 7 through 11 spend playing sports each day is same. You can verify the hypothesis using this test.

The t test statistic can be calculated using :

where N is the sample size, s is the sample standard deviation, X is the sample mean

There are many assumptions involved here :

  1. Data from both the groups are independent and follow normal distribution
  2. Data between the two groups should have equal variances (homoscedasticity)

If the above assumptions aren’t met despite applying data transformations, you should consider Mann-Whitney U-test (also known as the Mann–Whitney–Wilcoxon test/ Wilcoxon rank-sum test/ Wilcoxon two-sample test) or Welch’s t–test. (I will explain these tests in my upcoming articles)

Paired t test

This test is used when you have one measurement variable and two categorical variables. One of the categorical variables should have only two categories (like male/female or before/after) so you get multiple pairs of observations. It tests whether the mean difference in the pairs is different from 0.

A good example can be clinical trial of a drug where one categorical variable depicts group of patients and other categorical variable has two values namely, “before treatment” and “after treatment”

The null hypothesis here would be , there is no significant difference in the mean of measurement variable (like blood pressure) of the patient group before and after treatment implicitly stating the drug is ineffective.

The t test statistic can be calculated using :

ts=(dₐ)/(sₐ/√n)

where dₐ is the sample mean difference and sₐ is the standard deviation of the differences.

Paired t test has only one assumption that the difference in the observations between pairs should be normally distributed. If the differences are severely non-normal, it would be better to use the Wilcoxon signed-rank test

That’s all folks!

If you like this article, make sure you hit the clap button. I will be writing about ANOVA in my next article. Stay tuned!

--

--