This is a tutorial for the erpR
package, a package for ERP analysis in R. Further details can be found at https://sites.google.com/site/giorgioarcara/erpr.
This is an introductory code, to give you an idea on how erpR works. A more detailed tutorial will be also created soon (30/07/2018).
library(erpR)
## Loading required package: stringr
To import data into erpR
you should have ASCII file of your data. You should have a separate file for each subject and a separate file for each condition. This ASCII files should have timepoints in row and electrodes in column. An example on how these files should be can be downloaded here Note that the line before the data typically include electrode labels. Additional lines before electrode labels can include further information (see help(import.erp)
)
# move to the directory with your files.
# setwd("your_directory_here")
# import data and store them in an erplist
#my_erplist = import.erp(filenamebase="Exp1_word_subj", numbers=1:20, startmsec=-200, endmsec=1500, fileinfo=T)
# my_erplist = import.erp(filenamebase="Exp1_word_subj", numbers=1:20, startmsec=-200, endmsec=1500, fileinfo=T, erplist=my_erplist)
For this tutorials we will use the same data, which are delievered already inside the erpR
package
data(erplistExample)
You can inspect easily the content of this erplist
.
str(erplistExample, 1)
erpR
In erpR
data are arranged in erplist
, which are lists containing ERP data. This ERP data are stored in erpdf
, which are simply R data frames with timepoints in row and electrodes in columns. Typically erpdf
have some additional information stored as attributes. The most crucial ones are startmsec
and endmsec
, which are the values (in milliseconds) corresponding to the start and end of the ERP epoch. \ The names of the erpdfs
are composed by two parts: base
and number
. The base
is typicall a string that indicates the experimental condition (es. "word"
), while number
is a numeric ID associated with a given subject. So, in erpr
language, "word_2"
, indicates the erpdf
for the condition labeled word
of the subject 2
. This way of codifying things is quite strict, but helps avoiding mistakes.
From an erplist
you can calculate easily a grandaverage
you can then plot the resuls of a single electrode
erp(word, "F3", smo=0, col="blue", ylim=c(-6,6), lwd=2)
or the all average in a rectangular layout
scalp(list(word, nonword), layout=1, ylim=10, legend=TRUE, lwd=2)
another typical plot is a topoplot on a given time window.
# the package akima is needed for this plot
require(akima)
## Loading required package: akima
#define a layout
mat=matrix(c(1,2), 1, 2, byrow=TRUE)
layout(mat, widths=c(0.8, 0.2))
#make a topoplot, authomatically excluding electrode with not found coordinates
par(pty="s", mar=c(2,2,2,2))
topo.data=topoplot(word, win.ini=400, win.end=600, draw.nose=T, draw.ears=T, draw.elec.lab=F, palette.steps=50, head.lwd=3)
## Warning: the following electrodes have not been found
## A2
## VEOG1
## HEOG1
#draw the palette on a new empty plot.
par(pty="m", mar=c(0,0,0,0))
plot.new()
topoplot.palette(cols=topo.data$palette, palette.lim=topo.data$zlim, p.height=0.6)