Show
What is paired samples t-test?The paired samples t-test is used to compare the means between two related groups of samples. In this case, you have two values (i.e., pair of values) for the same samples. This article describes how to compute paired samples t-test using R software. As an example of data, 20 mice received a treatment X during 3 months. We want to know whether the treatment X has an impact on the weight of the mice. To answer to this question, the weight of the 20 mice has been measured before and after the treatment. This gives us 20 sets of values before treatment and 20 sets of values after treatment from measuring twice the weight of the same mice. In such situations, paired t-test can be used to compare the mean weights before and after treatment. Paired t-test analysis is performed as follow:
Paired t-test can be used only when the difference \(d\) is normally distributed. This can be checked using Shapiro-Wilk test.
Research questions and statistical hypothesesTypical research questions are:
In statistics, we can define the corresponding null hypothesis (\(H_0\)) as follow:
The corresponding alternative hypotheses (\(H_a\)) are as follow:
Note that:
Formula of paired samples t-testt-test statistisc value can be calculated using the following formula: \[ t = \frac{m}{s/\sqrt{n}} \] where,
We can compute the p-value corresponding to the absolute value of the t-test statistics (|t|) for the degrees of freedom (df): \(df = n - 1\). If the p-value is inferior or equal to 0.05, we can conclude that the difference between the two paired samples are significantly different. Visualize your data and compute paired t-test in RR function to compute paired t-testTo perform paired samples t-test comparing the means of two paired samples (x & y), the R function t.test() can be used as follow:
Import your data into R
Here, we’ll use an example data set, which contains the weight of 10 mice before and after the treatment.
We want to know, if there is any significant difference in the mean weights after treatment? Check your data
Compute summary statistics (mean and sd) by groups using the dplyr package.
Visualize your data using box plotsTo use R base graphs read this: R base graphs. Here, we’ll use the ggpubr R package for an easy ggplot2-based data visualization.
Paired Samples T-test in R Box plots show you the increase, but lose the paired information. You can use the function plot.paired() [in pairedData package] to plot paired data (“before - after” plot).
Paired Samples T-test in R Preleminary test to check paired t-test assumptionsAssumption 1: Are the two samples paired? Yes, since the data have been collected from measuring twice the weight of the same mice. Assumption 2: Is this a large sample? No, because n < 30. Since the sample size is not large enough (less than 30), we need to check whether the differences of the pairs follow a normal distribution. How to check the normality? Use Shapiro-Wilk normality test as described at: Normality Test in R.
From the output, the p-value is greater than the significance level 0.05 implying that the distribution of the differences (d) are not significantly different from normal distribution. In other words, we can assume the normality. Note that, if the data are not normally distributed, it’s recommended to use the non parametric paired two-samples Wilcoxon test. Compute paired samples t-testQuestion : Is there any significant changes in the weights of mice after treatment? 1) Compute paired t-test - Method 1: The data are saved in two different numeric vectors.
2) Compute paired t-test - Method 2: The data are saved in a data frame.
As you can see, the two methods give the same results. In the result above :
Note that:
Interpretation of the resultThe p-value of the test is 6.210^{-9}, which is less than the significance level alpha = 0.05. We can then reject null hypothesis and conclude that the average weight of the mice before treatment is significantly different from the average weight after treatment with a p-value = 6.210^{-9}. Access to the values returned by t.test() functionThe result of t.test() function is a list containing the following components:
The format of the R code to use for getting these values is as follow:
Online paired t-test calculatorYou can perform paired-samples t-test, online, without any installation by clicking the following link: InfosThis analysis has been performed using R software (ver. 3.2.4). Enjoyed this article? I’d be very grateful if you’d help it spread by emailing it to a friend, or sharing it on Twitter, Facebook or Linked In. Show me some love with the like buttons below... Thank you and please don't forget to share and comment below!! Avez vous aimé cet article? Je vous serais très reconnaissant si vous aidiez à sa diffusion en l'envoyant par courriel à un ami ou en le partageant sur Twitter, Facebook ou Linked In. Montrez-moi un peu d'amour avec les like ci-dessous ... Merci et n'oubliez pas, s'il vous plaît, de partager et de commenter ci-dessous! Is a one sample tA Paired t-test Is Just A 1-Sample t-Test
As we saw above, a 1-sample t-test compares one sample mean to a null hypothesis value. A paired t-test simply calculates the difference between paired observations (e.g., before and after) and then performs a 1-sample t-test on the differences.
Are t tests paired or unpaired?A paired t-test is designed to compare the means of the same group or item under two separate scenarios. An unpaired t-test compares the means of two independent or unrelated groups. In an unpaired t-test, the variance between groups is assumed to be equal. In a paired t-test, the variance is not assumed to be equal.
How do you create a paired samples tYou will want to include three main things about the Paired Samples T-Test when communicating results to others.. Test type and use. You want to tell your reader what type of analysis you conducted. ... . Significant differences between conditions. ... . Report your results in words that people can understand.. Is tThe most frequently used t-tests are one-sample and two-sample tests: A one-sample location test of whether the mean of a population has a value specified in a null hypothesis. A two-sample location test of the null hypothesis such that the means of two populations are equal.
|