Would shifting to a four-day work week reduce commuting mileage, fuel consumption and exhaust emissions? We will use the data comparing mileage driven for four and five day work weeks that is the main example at the start of Chapter 25 of De Veaux, Velleman and Bock, Stats.: Data and Models 2nd ed., 2008, Addison Wesley, Boston.
You may either manually enter the data below, or use the following procedure to read it in:
Copy the data and paste it into an Excel or Google Spreadsheet. Save as a .csv file. ("csv" means "comma separated version")
From RStudio, upper right window, Workspace tab
> Import Dataset > From text file
Follow the directions, be sure to pay attention to the “Heading” checkbox. For further help with this technique, watch my LoadData video.
Name X5.Day X4.Day 1 Jeff 2798 2914 2 Betty 7724 6112 3 Roger 7505 6177 4 Tom 838 1102 5 Aimee 4592 3281 6 Greg 8107 4997 7 Larry G 1228 1695 8 Tad 8718 6606 9 Larry M 1097 1063 10 Leslie 8089 6392 11 Lee 3807 3362
> miles = myfile #Presuming you named your data file "myfile.csv" > attach(miles) > diff = X5.Day - X4.Day > diff
> hist(diff) > summary(diff)
This is not too far off of the assumption of normality for such a small dataset. Note that we check assumptions on the differences, not the original data. This is also how the data is entered into the t.test() command.
> t.test(diff)
Notice the output says "One-Sample t-test". This is because the differences are treated as one sample. The data may equivalently be entered with both variables, with setting the paired argument to TRUE.
> t.test(X5.day - X4.day, paired=TRUE)
Confirm that the results are the same. Notice the free confidence interval. The test is significant, indicating that more miles are traveled on the 5-day schedule, as opposed to the 4-day, confirming our suspicion.
> detach(miles)
> rm(myfile) #Clean up workspace
Exercises
1. ls there a difference in SAT performance in math vs. verbal SAT scores? 2. If it has been covered in class, check that the assumptions for the paired t-test for question 1 are satisfied.