## Paired Sample TTests

TTests are inferential statistical tests that allow you to draw conclusions about data. There are three types of ttests and they are used in very specific situations.

Paired (or dependent) sample t-tests are used when you want to compare two dependent, or related samples. For instance, if you measure fitness test scores for a single group of participants at two different points in time. Another dependent example would be having a single group of participants perform an experimental task in two different conditions. Another way to think of it would be that in paired, or dependent tests, all participants take part in all conditions - whether it is the same test separated by time or two conditions.

For example, as a researcher you have a new diet you want to put people on to see if it results in a loss in the amount of calories consumed on a daily basis. You measure the average daily calories consumed at the start and end of the diet. The data is HERE.

Load the data in R in a new variable called

The column for time is a factor, or independent variable. In R, you need to define factors as factors. Let's do this:

Note, this was not necessary in Lesson 5A as there was only one set of data for one group.

Also look at the subject column. You will note that the subject numbers 1 to 50 are repeated - that is a clear indicator this is a paired or dependent design.

Now, lets run a paired samples ttest to compare the average amount of calories consumed at the two time points.

Note the notation here, the code would translate to "Let's run a ttest where we examine caloriedata$calories as a function of caloriedata$time - by the way, its a paired/dependent samples ttest.

To see the results of the ttest, simple type:

You should find that the result of the ttest is p = 0.02704.

Make sure you understand what degrees of freedom are. For a dependent samples ttest the degrees of freedom are: df = n -1.

Review. If you want to see the means of the data (or other descriptives) for the actual conditions - not the difference scores which are in the analysis results, you could do something like:

The assignment questions for the sections 5A, 5B, and 5C can be found at the end of section 5C.

Paired (or dependent) sample t-tests are used when you want to compare two dependent, or related samples. For instance, if you measure fitness test scores for a single group of participants at two different points in time. Another dependent example would be having a single group of participants perform an experimental task in two different conditions. Another way to think of it would be that in paired, or dependent tests, all participants take part in all conditions - whether it is the same test separated by time or two conditions.

For example, as a researcher you have a new diet you want to put people on to see if it results in a loss in the amount of calories consumed on a daily basis. You measure the average daily calories consumed at the start and end of the diet. The data is HERE.

Load the data in R in a new variable called

**caloriedata**. Note that the data has three columns, the first coding the subject number, the second coding the time point (1 = pretest, 2 = posttest), and the third the caloric intake measured at the time point. Let's give the columns in the table names:**names(caloriedata) = c('subject','time','calories')**The column for time is a factor, or independent variable. In R, you need to define factors as factors. Let's do this:

**caloriedata$time = factor(caloriedata$time)**Note, this was not necessary in Lesson 5A as there was only one set of data for one group.

Also look at the subject column. You will note that the subject numbers 1 to 50 are repeated - that is a clear indicator this is a paired or dependent design.

Now, lets run a paired samples ttest to compare the average amount of calories consumed at the two time points.

**analysis = t.test(caloriedata$calories ~ caloriedata$time, paired = TRUE)**Note the notation here, the code would translate to "Let's run a ttest where we examine caloriedata$calories as a function of caloriedata$time - by the way, its a paired/dependent samples ttest.

To see the results of the ttest, simple type:

**print(analysis)**You should find that the result of the ttest is p = 0.02704.

Make sure you understand what degrees of freedom are. For a dependent samples ttest the degrees of freedom are: df = n -1.

Review. If you want to see the means of the data (or other descriptives) for the actual conditions - not the difference scores which are in the analysis results, you could do something like:

**mean(caloriedata$calories[caloriedata$time == 1])**__Assignment Question__The assignment questions for the sections 5A, 5B, and 5C can be found at the end of section 5C.