3.9. Extra Practice#

This is meant to help you practise the same core skills you developed in the previous exercises. Completing these exercises are optional and only meant to provide a little extra practice if you want.

3.9.1. Set up Python Libraries#

As usual you will need to run this code block to import the relevant Python libraries

# Set-up Python libraries - you need to run this but you don't need to change it
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
import pandas as pd
import seaborn as sns
sns.set_theme(style='white')
import statsmodels.api as sm
import statsmodels.formula.api as smf

3.9.2. 1. Does a New Year mean more exercise?#

A researcher investigates whether making a New Year’s resolution leads to an increase in exercise behaviour.

Participants report the average number of minutes they spend exercising per week at two time points:

  • December, before the New Year

  • January, after the New Year

Exercise time is measured in minutes per week, with higher values indicating more exercise.

a) Load the data into a Pandas dataframe

resolution = pd.read_csv("https://raw.githubusercontent.com/SageBoettcher/StatsCourseBook_2026/main/data/new_years_resolution.csv")

resolution
ParticipantID Resolution ExerciseMinutes_December ExerciseMinutes_January
0 1 No 148.7 121.4
1 2 Yes 159.3 182.9
2 3 Yes 110.8 139.8
3 4 No 104.9 99.2
4 5 Yes 101.6 140.1
5 6 Yes 64.4 97.0
6 7 No 68.6 71.8
7 8 Yes 187.9 220.8
8 9 Yes 66.7 56.2
9 10 No 130.6 163.2
10 11 No 156.3 165.3
11 12 Yes 114.3 138.8
12 13 Yes 91.8 136.9
13 14 No 154.0 171.1
14 15 Yes 134.5 156.7
15 16 No 115.2 125.4
16 17 No 94.2 120.9
17 18 Yes 127.0 169.7
18 19 No 141.3 141.1
19 20 Yes 148.4 193.9
20 21 Yes 95.9 139.7
21 22 Yes 73.4 98.7
22 23 Yes 112.4 160.6
23 24 Yes 115.8 144.0
24 25 Yes 192.3 228.8
25 26 No 65.5 69.6
26 27 No 177.2 157.1
27 28 Yes 131.3 212.0
28 29 No 98.1 102.5
29 30 Yes 89.6 71.6
30 31 Yes 139.4 194.4
31 32 Yes 143.3 229.6
32 33 No 148.2 134.1
33 34 No 156.0 148.0
34 35 No 175.0 167.6
35 36 No 200.0 197.6
36 37 No 135.6 123.6
37 38 Yes 216.9 237.0
38 39 Yes 125.8 135.0
39 40 No 83.6 133.7
40 41 No 37.5 53.8
41 42 No 62.7 65.6
42 43 No 80.4 97.1
43 44 No 157.4 104.2
44 45 No 49.8 101.2
45 46 No 117.2 100.8
46 47 Yes 137.9 221.8
47 48 Yes 160.5 218.7
48 49 No 203.1 206.6
49 50 Yes 163.5 190.2

b) Plot the raw data for December and January exercise time, and plot the distribution of the paired differences. Comment on both plots.

You may find it helpful to add a Diff column to the dataset

#Your code here

c) Conduct a suitable \(t\)-test to assess whether exercise increases after the New Year. For this you should:

  • State the null and alternative hypotheses.

  • Report relevant descriptive statistics

  • Carry out an appropriate \(t\)-test using the built-in function from scipy.stats,

  • State your conclusion in words

#Your code here

3.9.3. 2. Did it matter whether a person made a resolution?#

The researcher also wanted to determine whether the increase in exercise after the New Year depended on whether a participant had made a New Year’s resolution.

In particular, they asked whether people who made a resolution to exercise more showed a greater increase in weekly exercise time than those who did not. This question compares independent groups and can be addressed by comparing exercise behaviour (or the change in exercise) between the two groups.

a) Plot the data and comment on what an appropriate test would be then carry out this test

#your code here

b) Conduct a suitable \(t\)-test to assess whether people who made a resolution showed a greater increase after the New Year. For this you should:

  • State the null and alternative hypotheses.

  • Report relevant descriptive statistics.

  • Carry out an appropriate \(t\)-test using the built-in function from scipy.stats, with suitable option choices.

  • State your conclusion in words.

#your code here