Analyze individual subjects’ data –accuracy and RT. Subjects categorized fish as “good” or “bad” based solely on a fish’s visual attributes, modulation in size at either 6 or 8 Hz. Three different Conditions defined by relationship between fish visual oscillation and the rate at which the accompanying broadband sound modulated: Congruent (sound and visual modulations at same rate), Control (sound unmodulated), or Incongruent (sound and visual modulations at different rates). The three conditions were tested in separate blocks of 80 trials each. Half the subjects categorized 6 Hz visual oscillation as “good”, others categorized 8 Hz visual oscillation as “good”. In this doc, 6 Hz is referred to as “slow”, while 8 Hz is referred to as “fast”.

Timestamp the run

Sys.time()
## [1] "2015-12-10 10:57:28 EST"

Theme for barGraph

rwsTheme4barGraph<-theme(                              
  axis.title.x = element_text(face="plain", color="black", size=18),
  axis.title.y = element_text(face="plain", color="black", size=18),
  plot.title = element_text(face="plain", color = "black", size=20, hjust=0),
  axis.line = element_line(size=.5),
  axis.text=element_text(color="black",size=rel(1.2))  
)

Load packages needed for analysis, then read in data from Excel sheet on Desktop folder

library(xlsx)
library(plyr)
library(ggplot2)
library(ez)
library(schoRsch)
## 
## Attaching package: 'schoRsch'
## 
## The following object is masked from 'package:psych':
## 
##     outlier
rawData <- read.xlsx("/Users/rSekuler/Desktop/ResponseToReviewers/GoodBadFishAnalysis/Exp2allSsNarrowFmtTrim.xlsx","narrowFormat")
summary(rawData)
##     Subject          Accuracy          RT         Modulation 
##  S10    : 480   correct  :3393   Min.   :   0.0   fast:2388  
##  S2     : 480   incorrect:1377   1st Qu.: 699.0   slow:2382  
##  S6     : 480                    Median : 847.0              
##  S9     : 480                    Mean   : 844.6              
##  S1     : 478                    3rd Qu.: 994.8              
##  S3     : 478                    Max.   :1987.0              
##  (Other):1894                                                
##        Condition       Correct      
##  Congruent  :1599   Min.   :0.0000  
##  Control    :1588   1st Qu.:0.0000  
##  Incongruent:1583   Median :1.0000  
##                     Mean   :0.7113  
##                     3rd Qu.:1.0000  
##                     Max.   :1.0000  
## 

Censor trials on which subject failed to respond (RT=0 in raw data file) or on which RT < 200 msec. Note: applying the same arbitrary, censoring criterion to all subjects’ data represents a default approach, which may not be optimal.

myData = subset(rawData, RT >=200)
summary(myData)
##     Subject          Accuracy          RT         Modulation 
##  S10    : 480   correct  :3393   Min.   : 212.0   fast:2377  
##  S2     : 480   incorrect:1360   1st Qu.: 700.0   slow:2376  
##  S9     : 480                    Median : 848.0              
##  S6     : 479                    Mean   : 847.6              
##  S1     : 478                    3rd Qu.: 995.0              
##  S3     : 478                    Max.   :1987.0              
##  (Other):1878                                                
##        Condition       Correct      
##  Congruent  :1597   Min.   :0.0000  
##  Control    :1578   1st Qu.:0.0000  
##  Incongruent:1578   Median :1.0000  
##                     Mean   :0.7139  
##                     3rd Qu.:1.0000  
##                     Max.   :1.0000  
## 

Separate correct and incorrect trials into distinct sets

right=with(myData, Correct == 1)
wrong=with(myData, Correct == 0)
rightTrials=myData[right,]
wrongTrials=myData[wrong,]

Density plots of RTs from right/wrong trials –put plots side-by side

mypar = par(no.readonly=TRUE)
par(mfrow=c(1,2))
hist(rightTrials$RT, breaks=10, freq=FALSE, ylim = c(0, 0.002), xlim=c(0,2000), col="blue",
     main="Correct Trials",xlab="RT in msec")
hist(wrongTrials$RT, breaks=10, freq=FALSE, ylim = c(0, 0.002), xlim=c(0,2000), col="blue", 
     main="Incorrect Trials",xlab="RT in msec")

par(mypar)

Note that incorrect responses are associated with more short RTs than correct responses are. This interesting result may be confounded with individual differences in overall response speed and accuracy.

Calculate values for comparing performance with fast/slow size modulation in combination with congruent, unmodulated and inconruent sounds

summary(myData)
##     Subject          Accuracy          RT         Modulation 
##  S10    : 480   correct  :3393   Min.   : 212.0   fast:2377  
##  S2     : 480   incorrect:1360   1st Qu.: 700.0   slow:2376  
##  S9     : 480                    Median : 848.0              
##  S6     : 479                    Mean   : 847.6              
##  S1     : 478                    3rd Qu.: 995.0              
##  S3     : 478                    Max.   :1987.0              
##  (Other):1878                                                
##        Condition       Correct      
##  Congruent  :1597   Min.   :0.0000  
##  Control    :1578   1st Qu.:0.0000  
##  Incongruent:1578   Median :1.0000  
##                     Mean   :0.7139  
##                     3rd Qu.:1.0000  
##                     Max.   :1.0000  
## 
taskSummary = ddply(myData, .(Subject, Condition, Modulation), summarise,
                      prCorrect = sum(Correct) / length(Correct))

taskSummary
##    Subject   Condition Modulation prCorrect
## 1       S1   Congruent       fast 0.8625000
## 2       S1   Congruent       slow 0.7375000
## 3       S1     Control       fast 0.7948718
## 4       S1     Control       slow 0.5750000
## 5       S1 Incongruent       fast 0.7750000
## 6       S1 Incongruent       slow 0.6250000
## 7      S10   Congruent       fast 0.8625000
## 8      S10   Congruent       slow 0.7375000
## 9      S10     Control       fast 0.8000000
## 10     S10     Control       slow 0.5750000
## 11     S10 Incongruent       fast 0.7750000
## 12     S10 Incongruent       slow 0.6250000
## 13      S2   Congruent       fast 0.8625000
## 14      S2   Congruent       slow 0.8625000
## 15      S2     Control       fast 0.4875000
## 16      S2     Control       slow 0.6875000
## 17      S2 Incongruent       fast 0.7750000
## 18      S2 Incongruent       slow 0.7500000
## 19      S3   Congruent       fast 0.9500000
## 20      S3   Congruent       slow 0.9000000
## 21      S3     Control       fast 0.6329114
## 22      S3     Control       slow 0.6250000
## 23      S3 Incongruent       fast 0.8250000
## 24      S3 Incongruent       slow 0.8227848
## 25      S4   Congruent       fast 0.7341772
## 26      S4   Congruent       slow 0.8250000
## 27      S4     Control       fast 0.6000000
## 28      S4     Control       slow 0.6750000
## 29      S4 Incongruent       fast 0.5063291
## 30      S4 Incongruent       slow 0.4868421
## 31      S5   Congruent       fast 0.8625000
## 32      S5   Congruent       slow 0.8375000
## 33      S5     Control       fast 0.8125000
## 34      S5     Control       slow 0.6375000
## 35      S5 Incongruent       fast 0.6750000
## 36      S5 Incongruent       slow 0.6233766
## 37      S6   Congruent       fast 0.3797468
## 38      S6   Congruent       slow 0.4875000
## 39      S6     Control       fast 0.4625000
## 40      S6     Control       slow 0.5000000
## 41      S6 Incongruent       fast 0.5250000
## 42      S6 Incongruent       slow 0.4875000
## 43      S7   Congruent       fast 0.9746835
## 44      S7   Congruent       slow 0.9250000
## 45      S7     Control       fast 0.5641026
## 46      S7     Control       slow 0.8101266
## 47      S7 Incongruent       fast 0.7250000
## 48      S7 Incongruent       slow 0.7974684
## 49      S8   Congruent       fast 0.8500000
## 50      S8   Congruent       slow 0.8625000
## 51      S8     Control       fast 0.7462687
## 52      S8     Control       slow 0.6753247
## 53      S8 Incongruent       fast 0.7721519
## 54      S8 Incongruent       slow 0.6086957
## 55      S9   Congruent       fast 0.9125000
## 56      S9   Congruent       slow 0.8875000
## 57      S9     Control       fast 0.4125000
## 58      S9     Control       slow 0.7625000
## 59      S9 Incongruent       fast 0.7625000
## 60      S9 Incongruent       slow 0.7125000

Plot each subject’s results for each modulation rate

taskPlot = ggplot(data=taskSummary, aes(x=Condition, y=prCorrect,
                                               color=Condition,
                                               group=Subject,
                                               label=Subject,ymax=max(1.0))) + 
   geom_text(position = position_dodge(width=0.5), size=6) + 
                geom_line(position = position_dodge(width=0.5), color='darkgray') +
                xlab('Condition') + 
                ylab('Pr(Correct)') +
                coord_cartesian(ylim=c(0.3,1.0))+
                scale_color_manual(values=c("red","green","blue"))+
                facet_grid(. ~ Modulation, space="free_x") +
      #  scale_x_discrete(limits=c("slow","fast"))+
                         theme(strip.text = element_text(face="bold", size=rel(2)),
      strip.background = element_rect(fill="gray", color="black",size=2))

taskPlot+rwsTheme4barGraph