In [7]:
import pandas as pd
import numpy as np
import scipy.stats as st
import matplotlib.pyplot as plt
import seaborn as sns
import math
In a Stroop experiment, participants are shown two lists of word of color names, printed in different ink colors, and asked to read out loud the ink color that the word was printed. The two lists are the congruent one, where the ink colors of the words agree with the words, and the incongruent one, where the ink colors don't match with the words.
Now looking at the dataset provided for the experiment:
In [8]:
stroopdata = pd.read_csv("stroopdata.csv")
stroopdata
Out[8]:
Firstly, assume the distribution of stimulus time for both congruent and incongruent lists are approximately normal, so we would be able to use Z-test or t-test. Secondly, we can see that we have a limited number of samples (24 and under 30), so we should use t-test instead of Z-test. Last but not least, the stimulus times are in pairs for both congruent and incongruent, and not independent events, so a pairwise t-test is our best bet.
Our goal is to determine whether the condition of the list would affect the stimulus time, or the mean stimulus time of each list would be significant different from each other. In other word, let's $\mu_D$, $\mu_I$ and $\mu_C$ be the mean difference between the two lists, the mean of the incongruent and the mean of the congruent, we have:
The null hypothesis is that there is no significant difference in the population average amount of time it takes to state the colors of the words in a congruent or incongruent condition. If $\mu_D$ is significantly different than 0, we can reject the null hypothesis and conclude that the stimulus time wouldn't be affected by the condition of the list. Otherwise, if $\mu_D$ is not diffent than zero then the condition of the list has no significant effect on the stimulus time. We use $\alpha = 0.05$ .
Before conducting the t-test, it would be beneficial for us to explore the dataset and its discriptive statistics.
Descriptive statistics of stimulus time of the congruent list:
In [62]:
stroopdata.describe()
Out[62]:
We can see that the incongruent group has higher mean, max and standard deviation comparing to the congruent list.
Now we can start plotting the data. The scatterplot of stimulus time of the congruent list in respective with the incongruent list shows a clear trend of the dataset that, in a pair, the incongurent stimulus time would always be higher than the congruent stimulus time.
In [38]:
sns.lmplot(x = 'Congruent', y = 'Incongruent', data = stroopdata)
plt.title("Stimulus times of congruent and incongruent conditions")
plt.xlabel("Congruent list (sec)")
plt.ylabel("Incongruent list (sec)")
plt.show()
In [4]:
fig, ax = plt.subplots()
ax.hist([stroopdata['Congruent'], stroopdata['Incongruent']], label = ['Congruent', 'Incongruent'])
ax.legend()
plt.title('Histogram of stimulus time per condition')
plt.xlabel ("Stimulus time (sec)")
plt.ylabel("Frequency")
plt.show()
Both the scatterplot and the histogram suggest that the incongruent have a longer stimulus time comparing to the congruent list.
We can perform the t-test easily using the scipy
package:
In [32]:
ttest = st.ttest_rel(stroopdata['Incongruent'], stroopdata['Congruent'])
print(ttest)
With the p-value is pvalue = 4.1003-08 < $\alpha = 0.05$, we can reject the null hypothesis.
Now consider the confidence interval:
In [34]:
# Differences:
stroopdata['Difference'] = stroopdata['Incongruent'] - stroopdata['Congruent']
# Sum of all differences:
sumdiff = sum(stroopdata['Difference'])
# Std of all differences:
stddiff = np.std(stroopdata['Difference'])
# Average of all sum differences:
avgdiff = sumdiff/24
# CI = avgdiff +- std(diff)/sqrt(n)
lower_bound = avgdiff - 2.064*stddiff/np.sqrt(24)
upper_bound = avgdiff + 2.064*stddiff/np.sqrt(24)
In [35]:
print(lower_bound)
print(upper_bound)
So with $\alpha = 0.05$, the confidence interval in this case is (5.958, 9.971).
We can reject the null hypothesis that there is no difference between the congruent and incongruent list, and conclude that the condition of the list does have an affect on the stimulus (reaction) time in the sample.
One possible explation for the phenomenon is the association between the texts in the list and the colors of the texts, e.g., it would be easier for us to associate the text "blue" with the color blue, then the color red. For further explorations, we can design an experiment when the texts are just words that don't have any association with the colors, and see if the stimulus time is shorter.