Graphical Exploratory Tools for ERP

Chi-Lin Yu

Outline

A reason workflow from user's perspective

Data

1. ERPdata : maybe a formal data for package

Preprocessing

1. data_select

2. data_summarize

3. downsample

EDA

1.edaplot

Data

head(dta[,1:5],3)
  Channel   value.1   value.2   value.3   value.4
1     Fp1 -1.545226 -1.889412 -1.463414 -1.335739
2     Fp2 -1.373787 -1.853133 -1.751572 -1.913380
3      F3 -2.856959 -2.690639 -0.926768 -0.168384
head(dta[,428:432],3)
  Experiment Condition Subject      AveRT IQ
1       Exp1   nonword   subj1 0.01340599 65
2       Exp1   nonword   subj1 0.01340599 65
3       Exp1   nonword   subj1 0.01340599 65

Data

str(dta[,c(1:5,428:432)],digits.d=1)
'data.frame':   680 obs. of  10 variables:
 $ Channel   : Factor w/ 34 levels "Fp1","Fp2","F3",..: 1 2 3 4 5 6 7 8 9 10 ...
 $ value.1   : num  -2 -1 -3 -2 -5 ...
 $ value.2   : num  -2 -2 -3 -3 -5 ...
 $ value.3   : num  -1.5 -1.8 -0.9 -1.8 -2.4 ...
 $ value.4   : num  -1.3 -1.9 -0.2 -1.5 -1.3 ...
 $ Experiment: chr  "Exp1" "Exp1" "Exp1" "Exp1" ...
 $ Condition : Factor w/ 2 levels "nonword","word": 1 1 1 1 1 1 1 1 1 1 ...
 $ Subject   : Factor w/ 10 levels "subj1","subj10",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ AveRT     : num  0.01 0.01 0.01 0.01 0.01 ...
 $ IQ        : num  65 65 65 65 65 ...

Look at Data

timepoint <- seq(0,1700,by=4)
Fig1 <- edaplot(dta,
                frames = timepoint ,
                datacol=2:427,
                subjcol=430,
                chancol=1,
                othvarcol=c(428:429,431:432),
                select_subj=NULL,
                select_chan=c("T3","T4","PZ"))+
        geom_line(aes(col=Condition))+
        facet_grid(Channel~Subject)

Look at Data

plot of chunk unnamed-chunk-6

Look at Data

Fig2 <- edaplot(data = dta,
                frames = timepoint ,
                datacol=2:427,
                subjcol=430,
                chancol=1,
                othvarcol=c(428:429,431:432),
                select_subj=NULL,
                select_chan="PZ",
                outlinesub = "subj2",
                outcolor = "red")+
        facet_wrap(~Condition)
Fig3 <- edaplot(data = dta,
                frames =timepoint ,
                datacol=2:427,
                subjcol=430,
                chancol=1,
                othvarcol=c(428:429,431:432),
                select_subj=NULL,
                select_chan="PZ",
                outlinesub = "subj10",
                outcolor = "blue")+
        facet_wrap(~Condition)

Look at Data

plot of chunk unnamed-chunk-8

Data Selection

dta2 <- data_select(data = dta,
                          frames = timepoint ,
                          datacol = 2:427,
                          subjcol = 430,
                          chancol = 1,
                          othvarcol = c(428:429,431:432),
                          select_subj = c(paste("subj",c(1,3:9),sep="")),
                          select_chan=c("T3","T4","PZ"))
head(dta2[,c(1,427:432)])
  Channel   value.426 Experiment Condition Subject      AveRT IQ
1      T3   0.5572408       Exp1   nonword   subj1 0.01340599 65
2      T3   6.7474460       Exp1      word   subj1 0.09596096 65
3      T4 -10.0724000       Exp1   nonword   subj1 0.01340599 65
4      T4   3.4233970       Exp1      word   subj1 0.09596096 65
5      PZ  -8.7248310       Exp1   nonword   subj1 0.01340599 65
6      PZ   4.9487610       Exp1      word   subj1 0.09596096 65

Downsample

dta3 <- downsample(data = dta2,
                   datacol = 2:427,
                   binwidth = 10,  # 426/5 = 85.2
                   movinginterval=5)
timepoint2 <- seq(1,1700,by = 16.1)
Fig4 <- edaplot(data = dta3,
        frames = timepoint2 ,
        datacol= 7:112,
        subjcol=4,
        chancol=1,
        othvarcol=c(2:3,5:6))+
        geom_line(aes(col=Subject))+
        facet_grid(Channel~Condition)

Downsample

plot of chunk unnamed-chunk-11

Data Exploration

Fig5 <- edaplot(data = dta3,
        frames = timepoint2 ,
        datacol= 7:112,
        subjcol=4,
        chancol=1,
        othvarcol=c(2:3,5:6))+
        geom_line(aes(col=Condition))+
        facet_grid(Channel~.)+
        stat_summary(aes(group=Condition),fun.y = "mean", 
                     colour = "purple", size = 1, geom = "point")+
        theme_bw()+
        theme(legend.position="bottom")+
        labs(list(x="Signal",y="Time Points"))

Data Exploration

plot of chunk unnamed-chunk-13

Data Exploration

Fig6 <- edaplot(data = dta3,
        frames = timepoint2 ,
        datacol= 7:112,
        subjcol=4,
        chancol=1,
        othvarcol=c(2:3,5:6))+
        geom_line(aes(col=IQ))+
        facet_grid(Channel~.)+
        scale_color_continuous(low="pink",high="red")+
        theme_bw()

Data Exploration

plot of chunk unnamed-chunk-15

Data Summarize

dtasum <- data_summarize(data=dta3,
                          frames = 1:426,
                          datacol = c(7:112,5),
                          subjcol = 4,
                          chancol = 1,
                          othvarcol = c(2:3,5:6),
                          summarycol= c(1,3),
                          fun=mean)
Fig7 <- edaplot(data = dtasum,
        frames = timepoint2 ,
        datacol= 3:108,
        subjcol=NULL,
        chancol=1,
        othvarcol=c(2,109))+
        geom_line(aes(col=Condition,size=as.factor(round(AveRT,1))))+
        facet_grid(Channel~.)+
        theme_bw()+
        scale_size_discrete(name="Average RT",range=c(1,2))+
        theme(legend.position="bottom")+
        labs(list(title="Average ERP curve",x="Signal",y="Time Points"))

Data Exploration

plot of chunk unnamed-chunk-17

Data

plot of chunk unnamed-chunk-19