Original data divided 320 trials into 4 blocks, maybe we can see a more clear learning curve if these were 10 block

library(data.table)
library(rmarkdown)
library(knitr)
library(ggplot2)

Load data

#I'm inheriting some data from past student's dissertation project
#Oddly that the data file has no header so let's add them
setwd('/Users/tzhu9/Google Drive/ExecFcnBattery/Data/data_2012Nov14')
df<-read.csv('SessionA.out.csv', header=F)
df<-df[, c(1, 7,13,16,17)]
setnames(df, old = c('V1','V7','V13','V16','V17'), new = c('subj','correctness','block','rt','time'))

kable(head(df))
subj correctness block rt time
1 1 1 5929.71 Tuesday, April 10, 2012 12:36:43 PM
1 0 1 2741.45 Tuesday, April 10, 2012 12:36:49 PM
1 0 1 1103.62 Tuesday, April 10, 2012 12:36:53 PM
1 1 1 2045.41 Tuesday, April 10, 2012 12:36:58 PM
1 1 1 1069.94 Tuesday, April 10, 2012 12:37:02 PM
1 0 1 654.64 Tuesday, April 10, 2012 12:37:06 PM

Divide trials into 10 blocks and fill block number to new column

#Create a newblock column that dive 320 trials into 10 blocks
# Relying on help from StackOverflow #https://stackoverflow.com/questions/53473953/add-a-column-that-divides-#another-column-into-n-chunks-r

library(plyr)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:plyr':
## 
##     arrange, count, desc, failwith, id, mutate, rename, summarise,
##     summarize
## The following objects are masked from 'package:data.table':
## 
##     between, first, last
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#I want to divide each participants' trials into 10 chunks
n_chunks = 10
df<-df %>% 
  group_by(subj) %>% 
  mutate(newblock = rep(1:n_chunks, 
                        each = ceiling(n() / n_chunks))[1:n()])

#add a column with category type for creating summary table
df<-as.data.frame(df)
type<-rep('SD',length(df$subj))
df<-cbind(type,df)
kable(head(df))
type subj correctness block rt time newblock
SD 1 1 1 5929.71 Tuesday, April 10, 2012 12:36:43 PM 1
SD 1 0 1 2741.45 Tuesday, April 10, 2012 12:36:49 PM 1
SD 1 0 1 1103.62 Tuesday, April 10, 2012 12:36:53 PM 1
SD 1 1 1 2045.41 Tuesday, April 10, 2012 12:36:58 PM 1
SD 1 1 1 1069.94 Tuesday, April 10, 2012 12:37:02 PM 1
SD 1 0 1 654.64 Tuesday, April 10, 2012 12:37:06 PM 1

create summary table

#create summary table for later graph
library(Rmisc)
## Loading required package: lattice
summary <- summarySE(df, 
                     measurevar="correctness",
                     groupvars=c("type","newblock"))

summary
#reshape data from long to wide
# library(tidyr)
# summary<-spread(summary, key = newblock, value = correctness)

Graph learning curve

#plot the learning growth curve
ggplot(summary, aes(x=newblock, y=correctness, colour=type)) + 
    geom_errorbar(aes(ymin=correctness-se, ymax=correctness+se),
                  width=.1) +
    geom_line() +
    geom_point()