Paired t-test in R Exercises

September 21, 2016
By

(This article was first published on R-exercises, and kindly contributed to R-bloggers)

analysis-810025_960_720The 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

To leave a comment for the author, please follow the link and comment on their blog: R-exercises.

R-bloggers.com offers daily e-mail updates about R news and tutorials on topics such as: Data science, Big Data, R jobs, visualization (ggplot2, Boxplots, maps, animation), programming (RStudio, Sweave, LaTeX, SQL, Eclipse, git, hadoop, Web Scraping) statistics (regression, PCA, time series, trading) and more...



If you got this far, why not subscribe for updates from the site? Choose your flavor: e-mail, twitter, RSS, or facebook...

Comments are closed.

Search R-bloggers


Sponsors

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)