2.12. 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.
2.12.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
2.12.2. 1. Does Lunch Improve Decision Making#
A behavioural scientist investigates whether being fed improves decision-making.
Participants complete a decision-making task twice on the same day:
Before lunch
After lunch
Scores reflect task performance (higher scores indicate better decisions).
a) Comment on the design of the study
< Comment here>
c) Load the data into a Pandas dataframe
decision = pd.read_csv("https://raw.githubusercontent.com/SageBoettcher/StatsCourseBook_2026/main/data/decision_making_lunch_study.csv")
decision
| ParticipantID | LunchOption | BeforeLunchScore | AfterLunchScore | |
|---|---|---|---|---|
| 0 | 1 | Veg | 57.1 | 59.200000 |
| 1 | 2 | Veg | 58.6 | 60.100000 |
| 2 | 3 | Meat | 63.4 | 67.100000 |
| 3 | 4 | Meat | 70.9 | 73.000000 |
| 4 | 5 | Meat | 67.0 | 71.000000 |
| 5 | 6 | Veg | 64.5 | 68.300000 |
| 6 | 7 | Veg | 57.1 | 62.900000 |
| 7 | 8 | Veg | 60.0 | 66.900000 |
| 8 | 9 | Meat | 63.8 | 67.300000 |
| 9 | 10 | Veg | 69.2 | 70.500000 |
| 10 | 11 | Meat | 51.4 | 67.200000 |
| 11 | 12 | Meat | 54.6 | 56.800000 |
| 12 | 13 | Meat | 61.9 | 63.500000 |
| 13 | 14 | Veg | 53.0 | 55.300000 |
| 14 | 15 | Meat | 65.3 | 68.700000 |
| 15 | 16 | Meat | 59.6 | 61.600000 |
| 16 | 17 | Veg | 58.5 | 68.200000 |
| 17 | 18 | Veg | 56.9 | 57.700000 |
| 18 | 19 | Meat | 56.8 | 63.300000 |
| 19 | 20 | Veg | 58.1 | 64.100000 |
| 20 | 21 | Veg | 57.9 | 62.700000 |
| 21 | 22 | Veg | 68.1 | 72.600000 |
| 22 | 23 | Meat | 62.8 | 65.800000 |
| 23 | 24 | Meat | 59.2 | 60.000000 |
| 24 | 25 | Meat | 58.8 | 61.300000 |
| 25 | 26 | Veg | 55.1 | 60.800000 |
| 26 | 27 | Meat | 64.5 | 66.400000 |
| 27 | 28 | Meat | 52.1 | 56.500000 |
| 28 | 29 | Veg | 63.9 | 64.800000 |
| 29 | 30 | Veg | 62.0 | 67.300000 |
| 30 | 31 | Veg | 47.6 | 68.000000 |
| 31 | 32 | Veg | 39.7 | 35.500000 |
| 32 | 33 | Veg | 42.7 | 45.300000 |
| 33 | 34 | Veg | 42.2 | 49.500000 |
| 34 | 35 | Meat | 42.4 | 36.400000 |
| 35 | 36 | Veg | 42.5 | 36.500000 |
| 36 | 37 | Meat | 50.8 | 58.500000 |
| 37 | 38 | Meat | 47.4 | 48.800000 |
| 38 | 39 | Veg | 53.1 | 58.100000 |
| 39 | 40 | Meat | 48.7 | 46.500000 |
| 40 | 41 | Meat | 49.3 | 50.200000 |
| 41 | 42 | Veg | 47.4 | 46.900000 |
| 42 | 43 | Veg | 53.6 | 47.600000 |
| 43 | 44 | Veg | 47.4 | 46.400000 |
| 44 | 45 | Veg | 50.8 | 56.500000 |
| 45 | 46 | Meat | 51.3 | 50.600000 |
| 46 | 47 | Veg | 71.6 | 72.200000 |
| 47 | 48 | Veg | 67.0 | 66.100000 |
| 48 | 49 | Veg | 67.3 | 66.100000 |
| 49 | 50 | Meat | 68.1 | 66.600000 |
| 50 | 51 | Meat | 66.7 | 66.400000 |
| 51 | 52 | Veg | 45.0 | 60.000000 |
| 52 | 53 | Veg | 47.4 | 61.292894 |
| 53 | 54 | Veg | 47.4 | 61.020410 |
| 54 | 55 | Veg | 47.6 | 68.000000 |
d) Plot the raw data for before and after lunch and plot the distribtuino of the differences. Comment on both.
Note you may need to add a Diff column to the dataset
#Code here
e) Conduct a suitable rank-based non-parametric test to assess whether lunch improves decision-making scores. For this you should:
State your hypotheses
State relevant descriptive statistics
Carry out the test using the built in function from
scipy.statswith appropriate option choicesState your conclusions
#Code here
f) Conduct a suitable permutation test of VitalVit’s claim
State your hypotheses
State relevant descriptive statistics
Carry out the test using the built in function from
scipy.statswith appropriate option choicesState your conclusions
#Code here
2.12.3. 2. Correlation#
The researcher was also interested in the reliability of the decision-making task. In particular, they wanted to know whether individuals who performed well before lunch also tended to perform well after lunch.
This can be assessed by examining the correlation of decision-making scores within individuals across the two testing sessions. A strong positive correlation would suggest that the task reliably captures stable individual differences in decision-making ability, even if overall performance changes after lunch.
a) Plot the data and comment on what an appropriate test would be then carry out this test
#Code here
< Comment here>
b) Now carry out the permuation version
3. Does Meat vs. Veg Lunch Matter#
The researcher also asked participants whether they went for the meat or the veg option. They are interested in whether this choice will affect their AfterLunchScore.
a) Plot the differences between the groups
#Code here
b) Conduct an appropriate rank-based non-parametric test of the decision making scores
State your hypotheses
State relevant descriptive statistics
Carry out the test using the built in function from
scipy.statswith appropriate option choicesState your conclusions
#Code here
c) Conduct a permutation test of the same claim
State your hypotheses
State relevant descriptive statistics
Carry out the test using the built in function from
scipy.statswith appropriate option choicesState your conclusions
#Code here