Load R packages
library(ggplot2)
library(tidyr)
library(dplyr)
library(lme4)
sem <- function(x) {sd(x, na.rm=TRUE) / sqrt(length(x))}
ci95 <- function(x) {sem(x) * 1.96}
First read in two data files and subject info. A and B refer to different trial order counterbalances.
subinfo <- read.csv("http://langcog.stanford.edu/sklar_expt6_subinfo_corrected.csv")
d.a <- read.csv("http://langcog.stanford.edu/sklar_expt6a_corrected.csv")
d.b <- read.csv("http://langcog.stanford.edu/sklar_expt6b_corrected.csv")
Next we gather these datasets into long form and get rid of the Xs in the headers.
d.a.long <- gather(d.a, subid, rt, X1:X21)
d.b.long <- gather(d.b, subid, rt, X22:X42)
d.a.long$subid <- sub('X', '', d.a.long$subid)
d.b.long$subid <- sub('X', '', d.b.long$subid)
Next we bind these together using bind_rows.
d.all.long <- bind_rows(d.a.long, d.b.long)
d.all.long$subid <- as.numeric(d.all.long$subid)
These are merged with subject info. using left_join. This dataframe will be called d.
d <- left_join(d.all.long, subinfo)
## Joining by: "subid"
Cleaning up the factor structure.
d$presentation.time <- factor(d$presentation.time)
levels(d$operand) <- c("addition","subtraction")
Histogram of the reaction times (rt’s)
qplot(rt, geom = 'histogram', data = d)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## Warning: Removed 237 rows containing non-finite values (stat_bin).
Performing the two manipulations checks…
ggplot(d, aes(x = objective.test, y = subjective.test)) + geom_point() + stat_smooth(method="glm", method.args = list(family="binomial"))
ggplot(d, aes(x = subjective.test, y = rt, colour = congruent)) + geom_point()
## Warning: Removed 237 rows containing missing values (geom_point).
ggplot(d, aes(x = objective.test, y = rt, colour = congruent)) + geom_point()
## Warning: Removed 237 rows containing missing values (geom_point).
Implementing Sklar et al.’s exclusion criterion
ds <- d[d$objective.test < .6 & d$subjective.test == 0, ]
d.subj <-
aggregate(rt ~ congruent + operand + subid + presentation.time, ds, FUN = 'mean') %>%
spread(congruent, rt) %>%
mutate(facil = no - yes)
d.summ<- aggregate(facil ~ operand + presentation.time, d.subj, FUN = mean)
d.summ$sem_facil <- aggregate(facil ~ operand + presentation.time, d.subj, FUN = sem)$facil
names(d.summ)[3] <- 'mean_facil'
print(ggplot(d.summ, aes(x = presentation.time, y = mean_facil))
+ geom_bar(stat = 'summary', fun.y = 'mean')
+ facet_grid(.~operand)
+ geom_errorbar(aes(ymin = mean_facil - sem_facil, ymax = mean_facil + sem_facil)))
## Warning: Stacking not well defined when ymin != 0
From the bar plot we see that being primed for 1700 ms with a number via a subtraction problem has a positive facilitation effect, meaning that participants name the number faster, wherease being primed via an addition problem actually has a negative facilitation effect, meaning that this slows down participants’ naming of the number.
Quick look at the data
head(ds)
## Source: local data frame [6 x 12]
##
## prime prime.result target congruent operand distance counterbalance
## (fctr) (int) (int) (fctr) (fctr) (int) (int)
## 1 =1+2+5 8 9 no addition -1 1
## 2 =1+3+5 9 11 no addition -2 1
## 3 =1+4+3 8 12 no addition -4 1
## 4 =1+6+3 10 12 no addition -2 1
## 5 =1+9+2 12 11 no addition 1 1
## 6 =1+9+3 13 12 no addition 1 1
## Variables not shown: subid (dbl), rt (int), presentation.time (fctr),
## subjective.test (int), objective.test (dbl)
Renaming contrasts to use with linear models
contrasts(ds$congruent) = cbind(YESvsNO = c(0, 1))
contrasts(ds$operand) = cbind(SUBvsADD = c(0, 1))
contrasts(ds$presentation.time) = cbind('2000vs1700' = c(0, 1))
Examining additive and interactive models…
summary(lm(rt ~ congruent + operand + presentation.time, data = ds, na.action=na.omit))
##
## Call:
## lm(formula = rt ~ congruent + operand + presentation.time, data = ds,
## na.action = na.omit)
##
## Residuals:
## Min 1Q Median 3Q Max
## -598.25 -94.65 -16.80 83.52 819.20
##
## Coefficients:
## Estimate Std. Error t value Pr(>|t|)
## (Intercept) 722.649 5.526 130.765 < 2e-16 ***
## congruentYESvsNO -5.847 5.491 -1.065 0.28704
## operandSUBvsADD -17.553 5.495 -3.194 0.00142 **
## presentation.time2000vs1700 -64.320 5.500 -11.694 < 2e-16 ***
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 138.1 on 2527 degrees of freedom
## (87 observations deleted due to missingness)
## Multiple R-squared: 0.05534, Adjusted R-squared: 0.05422
## F-statistic: 49.35 on 3 and 2527 DF, p-value: < 2.2e-16
summary(lm(rt ~ congruent * operand * presentation.time, data = ds, na.action=na.omit))
##
## Call:
## lm(formula = rt ~ congruent * operand * presentation.time, data = ds,
## na.action = na.omit)
##
## Residuals:
## Min 1Q Median 3Q Max
## -594.42 -94.84 -11.70 81.41 813.16
##
## Coefficients:
## Estimate
## (Intercept) 709.518
## congruentYESvsNO 13.326
## operandSUBvsADD 6.806
## presentation.time2000vs1700 -47.907
## congruentYESvsNO:operandSUBvsADD -34.231
## congruentYESvsNO:presentation.time2000vs1700 -19.608
## operandSUBvsADD:presentation.time2000vs1700 -28.715
## congruentYESvsNO:operandSUBvsADD:presentation.time2000vs1700 30.170
## Std. Error
## (Intercept) 7.879
## congruentYESvsNO 11.081
## operandSUBvsADD 11.335
## presentation.time2000vs1700 10.781
## congruentYESvsNO:operandSUBvsADD 16.009
## congruentYESvsNO:presentation.time2000vs1700 15.242
## operandSUBvsADD:presentation.time2000vs1700 15.551
## congruentYESvsNO:operandSUBvsADD:presentation.time2000vs1700 22.009
## t value
## (Intercept) 90.050
## congruentYESvsNO 1.203
## operandSUBvsADD 0.600
## presentation.time2000vs1700 -4.444
## congruentYESvsNO:operandSUBvsADD -2.138
## congruentYESvsNO:presentation.time2000vs1700 -1.286
## operandSUBvsADD:presentation.time2000vs1700 -1.847
## congruentYESvsNO:operandSUBvsADD:presentation.time2000vs1700 1.371
## Pr(>|t|)
## (Intercept) < 2e-16 ***
## congruentYESvsNO 0.2292
## operandSUBvsADD 0.5483
## presentation.time2000vs1700 9.22e-06 ***
## congruentYESvsNO:operandSUBvsADD 0.0326 *
## congruentYESvsNO:presentation.time2000vs1700 0.1984
## operandSUBvsADD:presentation.time2000vs1700 0.0649 .
## congruentYESvsNO:operandSUBvsADD:presentation.time2000vs1700 0.1706
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
##
## Residual standard error: 138.1 on 2523 degrees of freedom
## (87 observations deleted due to missingness)
## Multiple R-squared: 0.05773, Adjusted R-squared: 0.05511
## F-statistic: 22.08 on 7 and 2523 DF, p-value: < 2.2e-16
Operand and presentation time have significant negative impact in additive model (t = -3.194, p < .01) and (t = -11.694, p < .001). Presentation time has significant negative impact in interactive model (t = -4.444, p < .001) and there is a significant interaction between congruent and operand (t = -2.138, p < .05).
Graphing reaction time against distance (gouping by congruent) to show test of Sklar et al.’s original hypothesis…
ggplot(ds, aes(x = distance, y = rt, colour = congruent)) + geom_point() + geom_jitter()
## Warning: Removed 87 rows containing missing values (geom_point).
## Warning: Removed 87 rows containing missing values (geom_point).