0% found this document useful (0 votes)
404 views

An Introduction To T-Tests - Definitions, Formula and Examples

A t-test is used to compare the means of two groups and determine if they are statistically different. The document discusses the assumptions, types (one-sample, two-sample, paired), and directions (one-tailed, two-tailed) of t-tests. It provides the t-test formula and explains how to perform a t-test in statistical software and interpret the output, including the t-value, p-value, degrees of freedom, and confidence interval. An example compares the petal lengths of two iris species and finds a statistically significant difference between the means.

Uploaded by

Bonny Ogwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
404 views

An Introduction To T-Tests - Definitions, Formula and Examples

A t-test is used to compare the means of two groups and determine if they are statistically different. The document discusses the assumptions, types (one-sample, two-sample, paired), and directions (one-tailed, two-tailed) of t-tests. It provides the t-test formula and explains how to perform a t-test in statistical software and interpret the output, including the t-value, p-value, degrees of freedom, and confidence interval. An example compares the petal lengths of two iris species and finds a statistically significant difference between the means.

Uploaded by

Bonny Ogwal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

 Table of contents

An Introduction to T-Tests | Definitions, Formula and


Examples

Published on
January 31, 2020
by
Rebecca Bevans.
Revised on
July 9, 2022.

A t-test is a statistical test that is used to compare the means of two groups. It is often used
in hypothesis testing to determine whether a process or treatment actually has an effect on
the population of interest, or whether two groups are different from one another.

You want to know whether the mean petal length of iris flowers differs according to
their species. You find two different species of irises growing in a garden and measure
25 petals of each species. You can test the difference between these two groups using
a t-test and null and alterative hypotheses.

The null hypothesis (H0) is that the true difference between these group means is
zero.
The alternate hypothesis (Ha) is that the true difference is different from zero.

https://www.scribbr.com/statistics/t-test/ 1/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

When to use a t-test


 Table of contents
A t-test can only be used when comparing the means of two groups (a.k.a. pairwise
comparison). If you want to compare more than two groups, or if you want to do multiple
pairwise comparisons, use an ANOVA test or a post-hoc test.

The t-test is a parametric test of difference, meaning that it makes the same assumptions
about your data as other parametric tests. The t-test assumes your data:

1. are independent
2. are (approximately) normally distributed.
3. have a similar amount of variance within each group being compared (a.k.a.
homogeneity of variance)

If your data do not fit these assumptions, you can try a nonparametric alternative to the t-
test, such as the Wilcoxon Signed-Rank test for data with unequal variances.

What type of t-test should I use?


When choosing a t-test, you will need to consider two things: whether the groups being
compared come from a single population or two different populations, and whether you want
to test the difference in a specific direction.

One-sample, two-sample, or paired t-test?


If the groups come from a single population (e.g. measuring before and after an
experimental treatment), perform a paired t-test.
If the groups come from two different populations (e.g. two different species, or people
from two separate cities), perform a two-sample t-test (a.k.a. independent t-test).
If there is one group being compared against a standard value (e.g. comparing the
acidity of a liquid to a neutral pH of 7), perform a one-sample t-test.

One-tailed or two-tailed t-test?


If you only care whether the two populations are different from one another, perform a
two-tailed t-test.
If you want to know whether one population mean is greater than or less than the other,
perform a one-tailed t-test.

https://www.scribbr.com/statistics/t-test/ 2/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

In your test of whether petal length differs by species:


 Table of contents
Your observations come from two separate populations (separate species), so
you perform a two-sample t-test.
You don’t care about the direction of the difference, only whether there is a
difference, so you choose to use a two-tailed t-test.

Receive feedback on language, structure and


formatting
Professional editors proofread and edit your paper by focusing on:

 Academic style
 Vague sentences
 Grammar
 Style consistency

See an example

Performing a t-test
The t-test estimates the true difference between two group means using the ratio of the
difference in group means over the pooled standard error of both groups. You can calculate it
manually using a formula, or use statistical analysis software.

T-test formula
The formula for the two-sample t-test (a.k.a. the Student’s t-test) is shown below.

   

In this formula, t is the t-value, x1 and x2 are the means of the two groups being compared, s2
is the pooled standard error of the two groups, and n1 and n2 are the number of observations
in each of the groups.

https://www.scribbr.com/statistics/t-test/ 3/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

A larger t-value shows that the difference between group means is greater than the pooled
standard error, indicating
 Table of contentsa more significant difference between the groups.

You can compare your calculated t-value against the values in a critical value chart to
determine whether your t-value is greater than what would be expected by chance. If so, you
can reject the null hypothesis and conclude that the two groups are in fact different.

T-test function in statistical software


Most statistical software (R, SPSS, etc.) includes a t-test function. This built-in function will
take your raw data and calculate the t-value. It will then compare it to the critical value, and
calculate a p-value. This way you can quickly see whether your groups are statistically
different.

In your comparison of flower petal lengths, you decide to perform your t-test using R. The
code looks like this:

t.test(Petal.Length ~ Species, data = flower.data)

Download the data set to practice by yourself.

 Sample data set

Interpreting test results


If you perform the t-test for your flower hypothesis in R, you will receive the following output:

The output provides:


https://www.scribbr.com/statistics/t-test/ 4/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

1. An explanation of what is being compared, called data in the output table.


2. The t-value:
 Table -33.719. Note that it’s negative; this is fine! In most cases, we only care
of contents
about the absolute value of the difference, or the distance from 0. It doesn’t matter
which direction.
3. The degrees of freedom: 30.196. Degrees of freedom is related to your sample size, and
shows how many ‘free’ data points are available in your test for making comparisons.
The greater the degrees of freedom, the better your statistical test will work.
4. The p-value: 2.2e-16 (i.e. 2.2 with 15 zeros in front). This describes the probability that
you would see a t-value as large as this one by chance.
5. A statement of the alternate hypothesis (Ha). In this test, the Ha is that the difference is
not 0.
6. The 95% confidence interval. This is the range of numbers within which the true
difference in means will be 95% of the time. This can be changed from 95% if you want a
larger or smaller interval, but 95% is very commonly used.
7. The mean petal length for each group.

From the output table, we can see that the difference in means for our sample data is
−4.084 (1.456 − 5.540), and the confidence interval shows that the true difference in
means is between −3.836 and −4.331. So, 95% of the time, the true difference in
means will be different from 0. Our p-value of 2.2e–16 is much smaller than 0.05, so we
can reject the null hypothesis of no difference and say with a high degree of
confidence that the true difference in means is not equal to zero.

Presenting the results of a t-test


When reporting your t-test results, the most important values to include are the t-value, the
p-value, and the degrees of freedom for the test. These will communicate to your audience
whether the difference between the two groups is statistically significant (a.k.a. that it is
unlikely to have happened by chance).

You can also include the summary statistics for the groups being compared, namely the mean
and standard deviation. In R, the code for calculating the mean and the standard deviation
from the data looks like this:

https://www.scribbr.com/statistics/t-test/ 5/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

flower.data %>%

 Table of contents
group_by(Species) %>%

summarize(mean_length = mean(Petal.Length),

sd_length = sd(Petal.Length))

In our example, you would report the results like this:

The difference in petal length between iris species 1 (Mean = 1.46; SD = 0.206) and iris
species 2 (Mean = 5.54; SD = 0.569) was significant (t (30) = −33.7190; p < 2.2e-16).

Frequently asked questions about t-tests

What is a t-test? 

What does a t-test measure? 

Which t-test should I use? 

What is the difference between a one-sample t-test and a paired t-test? 

Can I use a t-test to measure the difference among several groups? 

Is this article helpful?

1447
213

https://www.scribbr.com/statistics/t-test/ 6/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

 Table of contents

Rebecca Bevans
Rebecca is working on her PhD in soil ecology and spends her free time writing. She's very
happy to be able to nerd out about statistics with all of you.

Other students also liked

Choosing the Right Statistical Test | Types & Examples


Your choice of statistical test depends on the types of variables you're dealing with and whether your data meets
certain assumptions.

2183

Hypothesis Testing | A Step-by-Step Guide with Easy Examples


Hypothesis testing is a formal procedure for investigating our ideas about the world. It allows you to statistically test
your predictions.

1598

Test statistics | Definition, Interpretation, and Examples


The test statistic is a number, calculated from a statistical test, used to find if your data could have occurred under
the null hypothesis.

https://www.scribbr.com/statistics/t-test/ 7/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

177

 Table of contents

Scribbr
Our editors
Jobs
FAQ
Partners

Our services
Plagiarism Checker
Proofreading Services
Citation Checker
APA Citation Generator
MLA Citation Generator
Knowledge Base

Contact
[email protected]
 +1 (510) 822-8066






4.9

Terms of use

https://www.scribbr.com/statistics/t-test/ 8/9
7/26/22, 10:41 AM An Introduction to T-Tests | Definitions, Formula and Examples

Privacy Policy

 Table of contents Happiness Guarantee

https://www.scribbr.com/statistics/t-test/ 9/9

You might also like