library(infer)
library(data.table)
library(ggplot2)
library(dplyr)
library(skimr)
library(reshape2)
library(ANOVAreplication)

Background

In a Stroop task, participants are tasked with reading words in certain text colors and saying what the text color of the word is. There are 2 possibilities for this:

  1. Congruent - the word matches the text color (ex: Blue is colored blue)
  2. Incongruent - the word does not match the text color (ex: blue is colored red)

The goal of this short project is to investigate a Stroop effect dataset and run it through statistical analyses to see if there is evidence for a significant difference in the whole population’s Stroop test performance under different treatments, Congruent and Incongruent.

1. What is our independent variable? What is our dependent variable?

Independent Variable: treatment of test (congruent/incongruent)

Dependent Variable: Performance on test under treatments

2. What is an appropriate set of hypotheses for this task? What kind of statistical test do you expect to perform? Justify your choices.

Here, we are using a sample of the population, which we do not know much about, to make inferences in the population. Specifically, we are trying to measure whether there are differences in performance means (in seconds) from Congruent and Incongruent Stroop test treatments in the population.

Explanation of Symbols

H0: Null Hypothesis

HA: Alternative Hypothesis

μCongruent = Population mean of Congruent performance (in seconds)

μIncongruent = Population mean of Incongruent performance (in seconds)

Hypotheses

This is a dependent test, where the same sample is tested pre and post treatment.

The Null Hypothesis would be that there is no difference in population mean performance time for the Congruent and Incongruent treatments.

The Alternative Hypothesis would be that there is a significant difference in population mean performance time for the Congruent and Incongruent treatments.

Thus, the hypotheses would be represented as follows:

H0: μCongruent = μIncongruent

HA: μCongruent != μIncongruent

Assumptions and Methodology

The number of samples is 24. We do not know the population standard deviation, nor if the distribution of either treatment is normal.

With a low number of samples, and not much information on the population SD, a t-test would be the best fit for analysis. The hypotheses above have been chosen to avoid a strong assumption, thus resulting in a two-tailed t-test.

Loading in the data

This data was obtained via Udacity’s Data Analyst Nanodegree program, Inferential Statistics course. Data was copied from a google doc and exported as a csv file.

stroop = fread("~/Desktop/EDA-Project-Master-Dodd/stroopdata.csv")
stroop <- subset(stroop, is.na(stroop$Congruent)==FALSE)
stroop
##     Congruent Incongruent
##  1:    12.079      19.278
##  2:    16.791      18.741
##  3:     9.564      21.214
##  4:     8.630      15.687
##  5:    14.669      22.803
##  6:    12.238      20.878
##  7:    14.692      24.572
##  8:     8.987      17.394
##  9:     9.401      20.762
## 10:    14.480      26.282
## 11:    22.328      24.524
## 12:    15.298      18.644
## 13:    15.073      17.510
## 14:    16.929      20.330
## 15:    18.200      35.255
## 16:    12.130      22.158
## 17:    18.495      25.139
## 18:    10.639      20.429
## 19:    11.344      17.425
## 20:    12.369      34.288
## 21:    12.944      23.894
## 22:    14.233      17.960
## 23:    19.710      22.058
## 24:    16.004      21.157
##     Congruent Incongruent

Each row of the dataset contains the performance for one participant, with the first number their results on the congruent task and the second number their performance on the incongruent task.

3. Report some descriptive statistics regarding this dataset. Include at least one measure of central tendency and at least one measure of variability.

xBarC = mean(stroop$Congruent)
xBarI = mean(stroop$Incongruent)
n = nrow(stroop)
df = n-1

skim(stroop)
## Skim summary statistics
##  n obs: 24 
##  n variables: 2 
## 
## Variable type: numeric 
##      variable missing complete  n  mean   sd   min   p25 median   p75
## 1   Congruent       0       24 24 14.05 3.56  8.63 11.9   14.36 16.2 
## 2 Incongruent       0       24 24 22.02 4.8  15.69 18.72  21.02 24.05
##     max     hist
## 1 22.33 ▅▂▇▇▃▂▁▁
## 2 35.26 ▆▆▇▅▁▁▁▂

The mean of the Congruent Sample was 14.05, while the mean of the Incongruent sample was 22.02. Standard Deviations of each sample were 3.56 and 4.8, respectively.

4. Provide one or two visualizations that show the distribution of the sample data. Write one or two sentences noting what you observe about the plot or plots.

Getting the data in a format for single plot analysis

stroop2 = melt.data.table(stroop,measure.vars =c("Congruent","Incongruent"))
head(stroop2,5)
##     variable  value
## 1: Congruent 12.079
## 2: Congruent 16.791
## 3: Congruent  9.564
## 4: Congruent  8.630
## 5: Congruent 14.669

Melting the data tables will allow plotting of both histograms in the same plot, simply by separating by variable (Congruent, Incongruent).

ggplot(stroop2, aes(x = value,color=variable,fill=variable,alpha =0.8)) +
  geom_histogram(binwidth = 1) +
  ggtitle("Fig. 1: Comparison of Treatment Distributions (n=24)") + ylab("Frequency") +
  xlab("Value")

The distribution of Incongruent values has a higher center- there are no values below 15, while the Congruent distribution starts at 8. Incongruent results also have a larger max- values extend to 35.

ggplot(stroop2, aes(y = value,x=variable,color=variable,fill=variable,alpha =0.8)) +
  geom_boxplot() +
  ggtitle("Fig. 2: Comparison of Performance Time by Treatment (n=24)") + ylab("Performance Time (seconds)") +
  xlab("Treatment") + theme(legend.position = "none")

We can visualize the center of each sample’s treatment performance better with this boxplot. IT is clear that the Incongruent treatment had a higher mean and range. The minimum performacne time Incongruent treatment is larger than the mean of the Congruent performance time.

5. Now, perform the statistical test and report your results. What is your confidence level and your critical statistic value? Do you reject the null hypothesis or fail to reject it? Come to a conclusion in terms of the experiment task. Did the results match up with your expectations?

Let’s now run the data through a t-test. We will use a 95% Confidence level, which with 23 degrees of freedom translates a t critical value of +/- 2.069.

tcrit = 2.069

We can calculate the t-statistic thus:

tstat = (μDifference) / StandardError

Calculating standard deviation of the difference

# Calculate the Differences (Congruent - Incongruent) of each test
stroop$diff <- stroop$Congruent - stroop$Incongruent

# Calculate the squared deviations difference - ((Differences of Congruent and Incongruent)-Mean difference)^2
MeanDiff = mean(stroop$diff)
stroop$sqdDif <- (stroop$diff - MeanDiff)^2

# Sum the squared deviations difference
SumSqdDiff <- sum(stroop$sqdDif)

# Divide it by the number of samples - 1 to achieve the Variance Difference.
df = n - 1
VarianceDiff <- SumSqdDiff/df

# Square root the Variance Difference
StandarDeviationDifference = sqrt(VarianceDiff)

Calculating T statistic

#Calucate standard error
SE = StandarDeviationDifference/(sqrt(n))

#Caluclate T statistic
t = (MeanDiff)/(SE)
t
## [1] -8.020707

Calculating the Confidence Interval

CI Formula:

μDifference +/- tcrit * SE

XbarDiff = xBarC - xBarI

MarginError = tcrit * SE
CI = c(XbarDiff - MarginError, XbarDiff + MarginError)
CI
## [1] -10.019368  -5.910215

With t-statistic (-8.02) < t-critical (+/- 2.069), p < .05, and 23 degrees of freedom, we reject the null hypothesis.The 95% Confidence Interval is (-10.02, -5.91). The evidence suggests that there is worse performance when undergoing the incongruent treatment than the congruent treatment.

Resources

  1. A Discussion on Stack Overflow about Degrees of Freedom: https://stats.stackexchange.com/questions/16921/how-to-understand-degrees-of-freedom

  2. T-table: https://s3.amazonaws.com/udacity-hosted-downloads/t-table.jpg

  3. A Stroop Effect applet: https://faculty.washington.edu/chudler/java/ready.html

  4. Stroop Effect Wiki: https://en.wikipedia.org/wiki/Stroop_effect

  5. Resource on Hypothesis by Durham College https://durhamcollege.ca/wp-content/uploads/STAT_nullalternate_hypothesis.pdf