Paired t-test in R Exercises
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
The paired samples t test is used to check if there are any differences in the mean of the same sample at two different time points. For example a medical researcher collects data on the same patients before and after a therapy. A paired t test will show if the therapy improves patient outcomes.
There are several assumptions that need to be satisfied so that results of a paired t test are valid. They are listed below
- The measured variable is continuous
- The differences between the two groups are approximately normally distributed
- We should not have any outliers in our data
- An adequate sample size is required
For this exercise we will use the anorexia data set available in package MASS. The data set contains weights of girls before and after anorexia treatment. Our interest is to know if the treatment caused any change in weight.
Solutions to these exercises can be found here
Exercise 1
Load the data and inspect its structure
Exercise 2
Generate descriptive statistics on weight before treatment
Exercise 3
Generate descriptive statistics on weight after treatment
Exercise 4
Create a new variable that contains the differences in weight before and after treatment
Exercise 5
Create a boxplot to identify any outliers
Exercise 6
Create a histogram with a normal curve to visually inspect normality
Exercise 7
Perform a normality test on the differences
Exercise 8
Perform a power analysis to assess sample adequacy
Exercise 9
Perform a paired t test
Exercise 10
Interpret the results
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.