Paired T-Test Assumptions : The Best Tutorial You Will Love - Datanovia (2024)

  • Login
  • |
  • Register

Home T-Test Essentials: Definition, Formula and Calculation Paired T-Test Assumptions

Paired T-Test Assumptions

T-Test Essentials: Definition, Formula and Calculation

This article describes the paired t-test assumptions and provides examples of R code to check whether the assumptions are met before calculating the t-test. This also referred as:

  • paired sample t test assumptions,
  • assumptions for matched pairs t test and
  • assumptions of dependent t test

The procedure of the paired t-test analysis is as follow:

  1. Calculate the difference (\(d\)) between each pair of value
  2. Compute the mean (\(m\)) and the standard deviation (\(s\)) of \(d\)
  3. Compare the average difference to 0. If there is any significant difference between the two pairs of samples, then the mean of d (\(m\)) is expected to be far from 0.


Contents:

  • Assumptions
  • Check paired t-test assumptions in R
    • Prerequisites
    • Demo data
    • Identify outliers
    • Check normality by groups
  • Related article

Related Book

Practical Statistics in R II - Comparing Groups: Numerical Variables

Assumptions

The paired samples t-test assume the following characteristics about the data:

  • the two groups are paired.
  • No significant outliers in the difference between the two related groups
  • Normality. the difference of pairs follow a normal distribution.

In this section, we’ll perform some preliminary tests to check whether these assumptions are met.

Check paired t-test assumptions in R

Prerequisites

Make sure you have installed the following R packages:

  • tidyverse for data manipulation and visualization
  • ggpubr for creating easily publication ready plots
  • rstatix provides pipe-friendly R functions for easy statistical analyses.
  • datarium: contains required data sets for this chapter.

Start by loading the following required packages:

library(tidyverse)library(ggpubr)library(rstatix)

Demo data

Here, we’ll use a demo dataset mice2 [datarium package], which contains the weight of 10 mice before and after the treatment.

# Wide formatdata("mice2", package = "datarium")head(mice2, 3)
## id before after## 1 1 187 430## 2 2 194 404## 3 3 232 406
# Transform into long data: # gather the before and after values in the same columnmice2.long <- mice2 %>% gather(key = "group", value = "weight", before, after)head(mice2.long, 3)
## id group weight## 1 1 before 187## 2 2 before 194## 3 3 before 232

First, start by computing the difference between groups:

mice2 <- mice2 %>% mutate(differences = before - after)head(mice2, 3)
## id before after differences## 1 1 187 430 -242## 2 2 194 404 -210## 3 3 232 406 -174

Identify outliers

Outliers can be easily identified using boxplot methods, implemented in the R function identify_outliers() [rstatix package].

mice2 %>% identify_outliers(differences)
## [1] id before after differences is.outlier is.extreme ## <0 rows> (or 0-length row.names)

There were no extreme outliers.

Note that, in the situation where you have extreme outliers, this can be due to: 1) data entry errors, measurement errors or unusual values.

You can include the outlier in the analysis anyway if you do not believe the result will be substantially affected. This can be evaluated by comparing the result of the t-test with and without the outlier.

It’s also possible to keep the outliers in the data and perform Wilcoxon test or robust t-test using the WRS2 package.

Check normality by groups

The normality assumption can be checked by computing the Shapiro-Wilk test for each group. If the data is normally distributed, the p-value should be greater than 0.05.

mice2 %>% shapiro_test(differences) 
## # A tibble: 1 x 3## variable statistic p## <chr> <dbl> <dbl>## 1 differences 0.968 0.867

From the output, the two p-values are greater than the significance level 0.05 indicating that the distribution of the data are not significantly different from the normal distribution. In other words, we can assume the normality.

You can also create QQ plots for each group. QQ plot draws the correlation between a given data and the normal distribution.

ggqqplot(mice2, "differences")

Paired T-Test Assumptions : The Best Tutorial You Will Love - Datanovia (8)

All the points fall approximately along the (45-degree) reference line, for each group. So we can assume normality of the data.

Note that, if your sample size is greater than 50, the normal QQ plot is preferred because at larger sample sizes the Shapiro-Wilk test becomes very sensitive even to a minor deviation from normality.

In the situation where the data are not normally distributed, it’s recommended to use the non parametric Wilcoxon test.

Related article

T-test in R



Recommended for you

This section contains best data science and self-development resources to help you on your path.

Coursera - Online Courses and Specialization

Data science

  • Course: Machine Learning: Master the Fundamentals by Stanford
  • Specialization: Data Science by Johns Hopkins University
  • Specialization: Python for Everybody by University of Michigan
  • Courses: Build Skills for a Top Job in any Industry by Coursera
  • Specialization: Master Machine Learning Fundamentals by University of Washington
  • Specialization: Statistics with R by Duke University
  • Specialization: Software Development in R by Johns Hopkins University
  • Specialization: Genomic Data Science by Johns Hopkins University

Popular Courses Launched in 2020

  • Google IT Automation with Python by Google
  • AI for Medicine by deeplearning.ai
  • Epidemiology in Public Health Practice by Johns Hopkins University
  • AWS Fundamentals by Amazon Web Services

Trending Courses

  • The Science of Well-Being by Yale University
  • Google IT Support Professional by Google
  • Python for Everybody by University of Michigan
  • IBM Data Science Professional Certificate by IBM
  • Business Foundations by University of Pennsylvania
  • Introduction to Psychology by Yale University
  • Excel Skills for Business by Macquarie University
  • Psychological First Aid by Johns Hopkins University
  • Graphic Design by Cal Arts

Amazon FBA

Amazing Selling Machine

  • Free Training - How to Build a 7-Figure Amazon FBA Business You Can Run 100% From Home and Build Your Dream Life! by ASM

Books - Data Science

Our Books

  • Practical Guide to Cluster Analysis in R by A. Kassambara (Datanovia)
  • Practical Guide To Principal Component Methods in R by A. Kassambara (Datanovia)
  • Machine Learning Essentials: Practical Guide in R by A. Kassambara (Datanovia)
  • R Graphics Essentials for Great Data Visualization by A. Kassambara (Datanovia)
  • GGPlot2 Essentials for Great Data Visualization in R by A. Kassambara (Datanovia)
  • Network Analysis and Visualization in R by A. Kassambara (Datanovia)
  • Practical Statistics in R for Comparing Groups: Numerical Variables by A. Kassambara (Datanovia)
  • Inter-Rater Reliability Essentials: Practical Guide in R by A. Kassambara (Datanovia)

Others

  • R for Data Science: Import, Tidy, Transform, Visualize, and Model Data by Hadley Wickham & Garrett Grolemund
  • Hands-On Machine Learning with Scikit-Learn, Keras, and TensorFlow: Concepts, Tools, and Techniques to Build Intelligent Systems by Aurelien Géron
  • Practical Statistics for Data Scientists: 50 Essential Concepts by Peter Bruce & Andrew Bruce
  • Hands-On Programming with R: Write Your Own Functions And Simulations by Garrett Grolemund & Hadley Wickham
  • An Introduction to Statistical Learning: with Applications in R by Gareth James et al.
  • Deep Learning with R by François Chollet & J.J. Allaire
  • Deep Learning with Python by François Chollet

Version: Français

Independent T-Test Assumptions (Prev Lesson)

(Next Lesson) How to Do a T-test in R: Calculation and Reporting

Back to T-Test Essentials: Definition, Formula and Calculation

No Comments

Give a comment

Course Curriculum

  • Types of T-Test

    3 mins

    • One Sample T-Test

      10 mins

    • Unpaired T-Test

      10 mins

      • Student's T-Test

        5 mins

      • Welch T-Test

        5 mins

    • Paired T-Test

      5 mins

  • Pairwise T-Test

    5 mins

  • T-Test Formula

    3 mins

    • One Sample T-Test Formula

      3 mins

    • Independent T-Test Formula

      3 mins

    • Paired T-Test Formula

      3 mins

  • T-Test Assumptions
    • One Sample T-Test Assumptions
    • Independent T-Test Assumptions
    • Paired T-Test Assumptions
  • How to Do a T-test in R: Calculation and Reporting
    • How To Do a One-Sample T-test in R
    • How To Do Two-Sample T-test in R
    • How to Do Paired T-test in R
  • T-test Effect Size using Cohen's d Measure

Teacher

Paired T-Test Assumptions : The Best Tutorial You Will Love - Datanovia (10)

Alboukadel Kassambara
Role : Founder of Datanovia
  • Website : https://www.datanovia.com/en
  • Experience : >10 years
  • Specialist in : Bioinformatics and Cancer Biology

Read More

Paired T-Test Assumptions : The Best Tutorial You Will Love - Datanovia (2024)
Top Articles
Latest Posts
Article information

Author: Jonah Leffler

Last Updated:

Views: 5675

Rating: 4.4 / 5 (65 voted)

Reviews: 80% of readers found this page helpful

Author information

Name: Jonah Leffler

Birthday: 1997-10-27

Address: 8987 Kieth Ports, Luettgenland, CT 54657-9808

Phone: +2611128251586

Job: Mining Supervisor

Hobby: Worldbuilding, Electronics, Amateur radio, Skiing, Cycling, Jogging, Taxidermy

Introduction: My name is Jonah Leffler, I am a determined, faithful, outstanding, inexpensive, cheerful, determined, smiling person who loves writing and wants to share my knowledge and understanding with you.