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

Haesmaenn says

Hey,

nitpick: for the t-test the two samples do not have to occur in different points of time . Counter example: two samples of production errors of two factory machines that were running simultaneously.

Keter says

Haesmaenn,

You mentioned two machines here thus an example of two sample t-test. For a paired t-test, think of a scenario where you assess students’knowledge before some training then again after the training, or patients before and after treatment. For your case, the machines are independent even though they run at the same time. Hence a t-test is not applicable under such a scenario.

Keter

J. E. Helmreich says

There is a nice graphic for dependent sample analysis in the package granova or the more refined granovaGG.

Keter says

I have concerns about how exercise 8 has been done.

This is power analysis and the intention is to determine if we have sufficient power to infer that the differences is due to the treatment and not due to chance. Now, if that is the case then this means that we need to make sure that we use information from the data we have at hand to establish whether we have enough data to detect the difference we are seeing. Given that this is the case, I wish to point out that in the study, the effect size is 0.35 (= mean difference/sd), however, there is a use of 0.5 as the effect size which is higher than that of the study thus inflating the power.

Finally, I want to believe that this is for reasons of demonstration only. This is because we have three different treatments used. So if we need to perform a paired t-test then we should do so for each of the three treatments (a very inefficient approach). For this, I would recommend an ANCOVA (i.e summary( lm( Postwt ~ Prewt + Treat, data = anorexia ) ) ).

Keter

Sammy Ngugi says

Keter

Calculating an effect size is more involving than you suggested. You require background knowledge of the area you are studying. The objectives of the study and practical significance also have to be factored in when identifying the ES. Please look at the discussion of effect size in this peer reviewed paper http://jpepsy.oxfordjournals.org/content/34/9/917.full

Keter says

It goes without saying that assessment of power for repeated measures studies differs from that of a paired t-test with only one exposure.