t-Test
The t-test is a statistical test procedure that tests whether there is a significant difference between the means of two groups.
The two groups could be, for example, patients who received drug A once and drug B once, and you want to know if there is a difference in blood pressure between these two groups.
Types of t-test
There are three different types of t-tests. The one sample t-test, the independent-sample t-test and the paired-sample t-test.
One sample t-Test
When do we use the one sample t-test (simple t-test)? We use the one sample t-test when we want to compare the mean of a sample with a known reference mean.
Example of a one sample t-test
A manufacturer of chocolate bars claims that its chocolate bars weigh 50 grams on average. To verify this, a sample of 30 bars is taken and weighed. The mean value of this sample is 48 grams.
We can now perform a one sample t-test to see if the mean of 48 grams is significantly different from the claimed 50 grams.
t-test for independent samples
When to use the t-test for independent samples? We use the t-test for independent samples when we want to compare the means of two independent groups or samples. We want to know if there is a significant difference between these means.
Example of a t-test for independent samples
We would like to compare the effectiveness of two painkillers, drug A and drug B.
To do this, we randomly divide 60 test subjects into two groups. The first group receives drug A, the second group receives drug B. With an independent t-test we can now test whether there is a significant difference in pain relief between the two drugs.
Paired samples t-Test
When to use the t-test for dependent samples (paired t-test)? The t-test for dependent samples is used to compare the means of two dependent groups.
Example of the t-test for paired samples
We want to know how effective a diet is. To do this, we weigh 30 people before the diet and exactly the same people after the diet.
Now we can see for each person how big the weight difference is between before and after. With a dependent t-test we can now check whether there is a significant difference.
Dependent vs. independent sample
In a dependent sample (paired sample), the measured values are available in pairs. The pairs are created, for example, by repeated measurements on the same persons. Independent samples (unpaired sample) result from persons and measurements that are independent of each other.
Tip
The t-test for dependent samples is very similar to the t-test for one sample. We can also think of the t-test for dependent samples as having a sample that was measured at two different times. As shown in the following image, we then calculate the difference between the paired values and get a value for one sample.
Once we get -5, once +2, once -1 and so on. Now we want to check whether the mean of the just calculated differences deviates from a reference value. In this case, zero. And that is exactly what the t-test does for a sample.
Assumptions
What are the assumptions to be able to calculate a t-test in the first place? First, of course, we must have a suitable sample.
- For the one sample t-test we need a sample and a reference value.
- In an independent t-test, we need two independent samples.
- And with the paired t-test, we need a dependent sample.
The variable for which it is to be tested whether there is a difference between the means must be metric. Metric variables are e.g. age, body weight, income. A non-metric variable is, for example, a person's school-leaving qualification (Secondary School, High School,...).
Furthermore, the metric variable must be normally distributed in all three variants of the t-test.
You can find out how to test whether your data are normally distributed in the tutorial on testing for normal distribution.
For the dependent t-test, the variances in the two groups must still be approximately equal. You can check whether the variances are equal with the Levene test.
Hypotheses
So what are the hypotheses for the t-test? Let's start with the one sample t-test.
t-test for one sample
In the one sample t-test, the null hypothesis and the alternative hypothesis are:
- Null hypothesis: The sample mean is equal to the given reference value (so there is no difference).
- Alternative hypothesis: The sample mean is not equal to the given reference value (so there is a difference).
t-test for independent samples
What about the t-test for independent samples? In the independent t-test, hypotheses are:
- Null hypothesis: The means in the two groups are equal (so there is no difference between the two groups).
- Alternative hypothesis: The mean values in the two groups are not equal (i.e. there is a difference between the two groups).
t-test for paired samples
And finally, the t-test for paired samples. In the paired t-test, the hypotheses are:
- Null hypothesis: The mean of the differences between the pairs is zero.
- Alternative hypothesis: The mean of the differences between the pairs is non-zero.
Why do we need a t-test?
Let's say we have made a hypothesis:
There is a difference in the duration of studying between men and women in Germany.
Our basic population is therefore all graduates of a degree programme in Germany. Since we cannot, of course, survey all graduates, we draw a sample that is as representative as possible.
With the t-test we now test the null hypothesis that there is no difference in the population.
If there is no difference in the population, then we will certainly still see a difference in study duration in the sample. It would be very unlikely that we would draw a sample where the difference is exactly zero.
In simple terms, we now want to know at what difference, measured in the sample, we can say that the length of study of men and women is significantly different. And this is exactly what the t-test answers.
Calculate t-test
How do you calculate a t-test? First the t-value is needed:
To calculate the t-value, we need two values. First, we need the difference of the means and second, the standard deviation from the mean. This value is called the standard error.
In the sample t-test, we calculate the difference between the sample mean and the known reference mean. s is the standard deviation of the data collected and n is the number of cases.
s divided by the square root of n is then the standard deviation from the mean or the standard error.
In the t-test for independent samples, the difference is simply calculated from the difference of the two sample means.
To calculate the standard error, we need the standard deviation and the number of cases of the first and the second sample.
Depending on whether we can assume equal or unequal variances for our data, there are different formulas for the standard error. More on this in the tutorial on the t-test for independent samples.
With a paired samples t-test, we only need to calculate the difference of the paired values and calculate the mean from this. The standard error is then the same as in the t-test for one sample.
Interpret t-value
Regardless of which t-test we calculate, the t-value becomes larger the greater the difference between the means. In the same way, the t-value becomes smaller when the difference between the means is smaller.
Also, the t-value becomes smaller if we have a larger dispersion of the mean values. So the greater the scatter of the data, the less a given mean difference matters!
The t-value and the null hypothesis
We now want to use the t-test to find out whether we reject the null hypothesis or not. To do this, we can use the t-value in two ways. Either we read the so-called critical t-value from a table or we simply calculate the p-value with the help of the t-value.
Let's start with the method involving the critical t-value, which we can read from a table. To do this, we first need the table of critical t-values, which we can find on datatab.net, under "Tutorials" and "t-distribution". Let's start with the two-sided case first, which is a one-sided or directed hypothesis. Below we see the table.
First we have to determine which significance level we want to use. Here we choose a significance level of 0.05, i.e. 5%. Then we have to look in the column at 1-0.05, so at 0.95.
Now we need the degrees of freedom. In the one sample t-test and the dependent-sample t-test, the degrees of freedom are simply the number of cases minus 1. So if we have a sample of 10 people, we have 9 degrees of freedom. In the independent samples t-test, we add the number of people from the two samples and calculate minus 2 because we have two samples. It should be noted that the degrees of freedom can also be determined in other ways, depending on whether one assumes equal or unequal variance.
So if we have a significance level of 5% and 9 degrees of freedom, we get a critical t-value of 2.262.
On the one hand, we have now calculated a t-value with the t-test, and then we have the critical t-value. If the calculated t-value is greater than the critical t-value, we reject the null hypothesis. Suppose we have calculated a t-value of 2.5. This value is greater than 2.262 and thus the two means are so far apart that we can reject the null hypothesis.
On the other hand, we can also calculate the p-value for the t-value we calculated. If we enter 2.5 for the t-value and 9 for the degrees of freedom at the green marked region of the image, we get a p-value of 0.034. The p-value is smaller than 0.05 and thus we also reject the null hypothesis in this way.
As a check, if we enter the t-value of 2.262, we get exactly a p-value of 0.05, which is exactly the limit.
Calculate the t-Test with DATAtab
If you want to calculate a t-test with DATAtab, all you have to do is copy your own data into the table, click on "Hypothesis Test" and then select the desired variables.
For example, if you want to check whether gender has an influence on income, simply click on both variables and a t-test for independent samples is automatically calculated. You can then read the p-value at the bottom.
If you are still unsure how to interpret the results, you can simply click on "Interpretation in words":
Directed and undirected hypothesis
The final question that now arises is what is the difference between a one tailed or directed hypothesis and a two tailed or undirected hypothesis. In the undirected case, the alternative hypothesis is that there is a difference between, e.g. men's and women's wages.
In this case, we are not interested in which of the two earns more, we only want to know whether there is a difference or not. With a directed hypothesis, we are also interested in the direction of the difference. The alternative hypothesis is then, for example, men earn more than women or women earn more than men.
If we look at this graphically with the t-distribution, we see that in the two-sided case we have one range on the left and one on the right. We want to reject the null hypothesis if we are in either of them. At a significance level of 5%, both ranges have a probability of 2.5%, so together they have 5%.
When we test a one-sided t-test, we only reject the null hypothesis if we are in this range, always depending on the sign (the side) we are testing. In that case, With a significance level of 5%, the entire 5% then falls within this range.
Statistics made easy
- many illustrative examples
- ideal for exams and theses
- statistics made easy on 412 pages
- 5rd revised edition (April 2024)
- Only 8.99 €
"Super simple written"
"It could not be simpler"
"So many helpful examples"