Data Preprocessing
###Data pre-processing
#install.packages("readxl")
rm(list=ls())
library(readxl)
data<-read_excel("AllData.xlsx")
data<-as.data.frame(data)
str(data)
## 'data.frame': 9600 obs. of 6 variables:
## $ block : num 1 1 1 1 1 1 1 1 1 1 ...
## $ correct : num 0 1 0 0 0 0 0 0 0 0 ...
## $ count_trial_sequence: num 0 1 2 3 4 5 6 7 8 9 ...
## $ group : chr "ideo" "ideo" "ideo" "ideo" ...
## $ rt : num 3373 2716 3315 2533 2097 ...
## $ subject_nr : num 1 1 1 1 1 1 1 1 1 1 ...
data$group<-as.factor(data$group)
#change variable names
colnames(data)[2]<- "acc"
colnames(data)[3]<- "trl"
colnames(data)[6]<- "sbj"
str(data)
## 'data.frame': 9600 obs. of 6 variables:
## $ block: num 1 1 1 1 1 1 1 1 1 1 ...
## $ acc : num 0 1 0 0 0 0 0 0 0 0 ...
## $ trl : num 0 1 2 3 4 5 6 7 8 9 ...
## $ group: Factor w/ 2 levels "ideo","pseudo": 1 1 1 1 1 1 1 1 1 1 ...
## $ rt : num 3373 2716 3315 2533 2097 ...
## $ sbj : num 1 1 1 1 1 1 1 1 1 1 ...
#Calculate Average accuracy per group
data_temp<-aggregate(data$acc, list(data$sbj, data$group, data$block), mean)
colnames(data_temp) <- c("sbj", "group", "block", "acc")
str(data_temp)
## 'data.frame': 120 obs. of 4 variables:
## $ sbj : num 1 4 6 8 10 12 14 15 16 18 ...
## $ group: Factor w/ 2 levels "ideo","pseudo": 1 1 1 1 1 1 1 1 1 1 ...
## $ block: num 1 1 1 1 1 1 1 1 1 1 ...
## $ acc : num 0.475 0.525 0.588 0.5 0.475 ...
#Keep data from the final block of trials
data_sbj_final<-data_temp[data_temp$block==5,]
str(data_sbj_final)
## 'data.frame': 24 obs. of 4 variables:
## $ sbj : num 1 4 6 8 10 12 14 15 16 18 ...
## $ group: Factor w/ 2 levels "ideo","pseudo": 1 1 1 1 1 1 1 1 1 1 ...
## $ block: num 5 5 5 5 5 5 5 5 5 5 ...
## $ acc : num 0.575 0.625 0.863 0.85 0.588 ...
Graphs
###Graph (Boxplot)
c= c("grey75", "grey25")
m<-"Accuracy by Group"
yl<-"Proportion Correct"
xl<-"Group"
ylm<-c(0.0, 1.0)
plot(data=data_sbj_final, acc~group, frame.plot=F, col=c, main=m, xlab=xl, ylab=yl, ylim=ylm, xaxt="n", las=2, boxwex=0.5)
axis(side=1,tick=F, at=c(1,2),labels=c("Ideograms", "Pseudowords"))
