Eeg Tutorial
Eeg Tutorial
Arnaud Delorme, Toby Fernsler, Hilit Serby, and Scott Makeig, April 12, 2006 Copyright University of San Diego California
Table of Contents
Introduction .....................................................................................................................................................................1 I. Analyzing Data in EEGLAB .........................................................................................................................................4 I.1. Loading data and visualizing data information..............................................................................................4 I.1.1. Getting started ......................................................................................................................................4 I.1.1.1. Learning Matlab..........................................................................................................................4 I.1.1.2. Installing EEGLAB and tutorial files............................................................................................4 I.1.1.3. Starting Matlab and EEGLAB.....................................................................................................5 I.1.2. Opening an existing dataset ................................................................................................................7 . I.1.3. Editing event values.............................................................................................................................8 I.1.4. About this dataset................................................................................................................................8 I.1.5. Scrolling through the data....................................................................................................................9 I.2. Using channel locations ...............................................................................................................................14 I.2.1. Importing channel location for the tutorial dataset.............................................................................14 I.2.2. Retrieving standardized channel locations .........................................................................................19 I.2.3. Importing measured 3-D channel locations information.....................................................................20 I.3. Plotting channel spectra and maps.............................................................................................................23 I.4. Preprocessing tools.....................................................................................................................................24 I.4.1. Changing the data sampling rate.......................................................................................................24 I.4.2. Filtering the data................................................................................................................................24 I.4.3. Re-referencing the data.....................................................................................................................25 I.5. Extracting data epochs................................................................................................................................28 I.5.1. Extracting epochs ...............................................................................................................................28 I.5.2. Removing baseline values.................................................................................................................29 I.6. Data averaging............................................................................................................................................30 I.6.1. Plotting the ERP data on a single axis with scalp maps....................................................................31 I.6.2. Plotting ERP traces in a topographic array........................................................................................32 I.6.3. Plotting ERPs in a two column array..................................................................................................33 I.6.4. Plotting an ERP as a series of scalp maps........................................................................................34 I.6.4.1. Plotting a series of 2-D ERP scalp maps ..................................................................................34 I.6.4.2. Plotting ERP data as a series of 3-D maps..............................................................................35 I.7. Selecting data epochs and plotting data averages......................................................................................38 I.7.1. Selecting events and epochs for two conditions................................................................................38 I.7.2. Computing Grand Mean ERPs ...........................................................................................................39 I.7.3. Finding ERP peak latencies...............................................................................................................41 I.7.4. Comparing ERPs in two conditions....................................................................................................42 I.8. Plotting ERP images ....................................................................................................................................44 I.8.1. Selecting a channel to plot.................................................................................................................44 I.8.2. Plotting ERP images using pop_erpimage()......................................................................................46 I.8.3. Sorting trials in ERP images..............................................................................................................48 I.8.4. Plotting ERP images with spectral options .........................................................................................51 I.8.5. Plotting spectral amplitude in single trials and additional options......................................................56 I.9. Independent Component Analysis of EEG data..........................................................................................57 I.9.1. Running ICA decompositions.............................................................................................................59 I.9.2. Plotting 2-D Component Scalp Maps.................................................................................................61 I.9.3. Plotting component headplots............................................................................................................63 I.9.4. Studying and removing ICA components...........................................................................................64 I.9.5. Subtracting ICA components from data.............................................................................................67 I.9.6. Retaining multiple ICA weights in a dataset.......................................................................................68 I.9.7. Scrolling through component activations...........................................................................................69 I.10. Working with ICA components ...................................................................................................................69 I.10.1. Rejecting data epochs by inspection using ICA...............................................................................69 I.10.2. Plotting component spectra and maps.............................................................................................70 I.10.3. Plotting component ERPs................................................................................................................73 I.10.4. Plotting component ERP contributions .............................................................................................74 I.10.5. Component ERP-image plotting .......................................................................................................76 I.11. Time/frequency decomposition ..................................................................................................................78
Table of Contents
I. Analyzing Data in EEGLAB I.11.1. Decomposing channel data ..............................................................................................................78 I.11.2. Computing component time/frequency transforms..........................................................................79 I.11.3. Computing component cross-coherences ........................................................................................80 I.11.4. Plotting ERSP time course and topography.....................................................................................81 II. Importing/exporting data and event or epoch information into EEGLAB...........................................................83 II.1. Importing continuous data..........................................................................................................................83 II.1.1. Importing a Matlab array...................................................................................................................83 II.1.2. Importing Biosemi .BDF files.............................................................................................................84 II.1.3. Importing European data format .EDF files.......................................................................................85 II.1.4. Importing EGI .RAW continuous files................................................................................................85 II.1.5. Importing Neuroscan .CNT continuous files ......................................................................................85 II.1.6. Importing Neuroscan .DAT information files.....................................................................................87 II.1.7. Importing Snapmaster .SMA files ......................................................................................................88 II.1.8. Importing ERPSS .RAW or .RDF data files .......................................................................................88 II.1.9. Importing Brain Vision Analyser Matlab files.....................................................................................88 II.1.10. Importing data in other data formats...............................................................................................88 II.2. Importing event information for a continuous EEG dataset........................................................................89 II.2.1. Importing events from a data channel...............................................................................................89 II.2.2. Importing events from a Matlab array or text file...............................................................................89 II.2.3. Importing events from a Presentation file ..........................................................................................91 II.3. Importing sets of single-trial EEG epochs into EEGLAB............................................................................92 II.3.1. Importing .RAW EGI data epoch files...............................................................................................92 II.3.2. Importing Neuroscan .EEG data epoch files.....................................................................................92 II.3.3. Importing epoch info Matlab array or text file into EEGLAB..............................................................92 II.4. Importing sets of data averages into EEGLAB...........................................................................................95 II.4.1. Importing data into Matlab .................................................................................................................95 II.4.2. Concatenating data averages...........................................................................................................95 II.4.3. Importing concatenated data averages in EEGLAB ..........................................................................96 II.5. Exporting data and ICA matrices................................................................................................................97 II.5.1. Exporting data to an ASCII text file...................................................................................................97 II.5.2. Exporting ICA weights and inverse weight matrices.........................................................................98 III. Rejecting artifacts in continuous and epoched data...........................................................................................99 III.1. Rejecting artifacts in continuous data........................................................................................................99 III.1.1. Rejecting data by visual inspection..................................................................................................99 III.1.2. Rejecting data channels based on channel statistics .....................................................................101 III.2. Rejecting artifacts in epoched data.........................................................................................................102 III.2.1. Rejecting epochs by visual inspection...........................................................................................103 III.2.2. Rejecting extreme values...............................................................................................................104 III.2.3. Rejecting abnormal trends.............................................................................................................105 III.2.4. Rejecting improbable data.............................................................................................................106 III.2.5. Rejecting abnormally distributed data............................................................................................108 III.2.6. Rejecting abnormal spectra...........................................................................................................109 III.2.7. Inspecting current versus previously proposed rejections.............................................................111 III.2.8. Inspecting results of all rejection measures...................................................................................112 III.2.9. Notes and strategy.........................................................................................................................113 III.3. Rejection based on independent data components................................................................................113 IV. Writing EEGLAB Matlab Scripts..........................................................................................................................115 IV.1. Why write EEGLAB Matlab scripts?........................................................................................................115 IV.2. Using dataset history to write EEGLAB scripts.......................................................................................115 IV.2.1. Dataset history: the EEG.history field............................................................................................116 IV.2.2. EEGLAB pop_ functions................................................................................................................117 IV.2.3. Script examples using dataset history...........................................................................................118 IV.2.4. Updating the EEGLAB window......................................................................................................119
Table of Contents
IV. Writing EEGLAB Matlab Scripts IV.3. Using EEGLAB session history to perform basic EEGLAB script writing ................................................119 IV.3.1. The h command.............................................................................................................................120 IV.3.2. Script example using session history .............................................................................................121 IV.3.3. Scripting at the EEGLAB structure level........................................................................................122 IV.4. Basic scripting examples .........................................................................................................................124 IV.5. Low level scripting...................................................................................................................................125 IV.5.1. Example script for processing multiple datasets ............................................................................126 IV.5.2. Example script performing time-frequency decompositions on all electrodes...............................127 IV.5.3. Creating a scalp map animation....................................................................................................128 V. EEGLAB event Structure.......................................................................................................................................129 V.1. Event processing in the EEGLAB GUI.....................................................................................................129 V.1.1. Event fields.....................................................................................................................................129 V.1.2. Importing, adding, and modifying events........................................................................................130 V.1.3. Selecting events.............................................................................................................................131 V.1.4. Using events for data processing...................................................................................................132 V.2. Event processing from the Matlab command line....................................................................................134 V.2.1. Accessing events from the commandline.......................................................................................134 V.2.1.1. Event types ............................................................................................................................134 V.2.1.2. Event latencies......................................................................................................................136 V.2.1.3. Urevents................................................................................................................................137 V.2.1.4. Boundary events...................................................................................................................137 V.2.1.5. 'Hard' boundaries between datasets.....................................................................................138 V.2.2. The 'epoch' structure......................................................................................................................139 V.2.3. Writing scripts using events............................................................................................................140 VI. Independent Component Clustering...................................................................................................................143 VI.1. Component Clustering............................................................................................................................143 VI.1.1. Why cluster?..................................................................................................................................143 VI.1.2. Before clustering............................................................................................................................144 VI.1.3. Clustering outline...........................................................................................................................145 VI.2. The graphic interface..............................................................................................................................145 VI.2.1. Creating a new STUDY structure and studyset.............................................................................146 VI.2.2. Loading an existing studyset.........................................................................................................148 VI.2.3. Preparing to cluster (Pre-clustering)..............................................................................................150 VI.2.4. Finding clusters ..............................................................................................................................153 VI.2.5. Viewing component clusters..........................................................................................................153 VI.2.6. Editing clusters..............................................................................................................................158 VI.2.7. Hierarchic sub-clustering...............................................................................................................160 VI.2.8. Editing STUDY datasets................................................................................................................163 VI.3. EEGLAB study data structures...............................................................................................................163 VI.3.1. The STUDY structure....................................................................................................................163 VI.3.2. The STUDY.datasetinfo sub-structure...........................................................................................164 VI.3.3. The STUDY.cluster sub-structure..................................................................................................165 VI.3.4. The STUDY.cluster.preclust sub-structure....................................................................................167 VI.4. Command line STUDY functions .............................................................................................................167 VI.4.1. Creating a STUDY.........................................................................................................................167 VI.4.2. Component clustering and pre-clustering......................................................................................168 VI.4.3. visualizing clusters.........................................................................................................................169 VI.4.4. Modeling condition ERP differences with std_envtopo()...............................................................169 A1. EEGLAB Data Structures....................................................................................................................................171 A1.1. EEG and ALLEEG ..................................................................................................................................171 A1.2. EEG.chanlocs........................................................................................................................................172 A1.3. EEG.event..............................................................................................................................................173 A1.4. EEG.epoch.............................................................................................................................................174
Table of Contents
A2. Options to Maximize Memory and Disk Space ..................................................................................................176 A2.1. Maximize memory menu........................................................................................................................176 A2.2. The icadefs.m file...................................................................................................................................177 A3. DIPFIT plug-in: Equivalent dipole source localization of independent components....................................178 A3.1. Dipole fitting with DIPFIT2 ......................................................................................................................179 A3.2. Setting up DIPFIT model and preferences.............................................................................................180 A3.3. Initial fitting - Scanning on a coarse-grained grid...................................................................................184 A3.4. Interactive fine-grained fitting.................................................................................................................186 A3.5. Automated dipole fitting ..........................................................................................................................188 A3.6. Visualizing dipole models.......................................................................................................................189 A3.6. Plotting dipole locations on scalp maps.................................................................................................192 A3.7. Using DIPFIT to fit EEG or ERP scalp maps ..........................................................................................193 A3.8. DIPFIT structure and functions..............................................................................................................194 A3.9. DIPFIT validation study using the spherical head model.......................................................................195 A3.10. Literature references............................................................................................................................196 A4. Equivalent dipole source localization of independent components using BESA.........................................197 A4.1. Component localization by equivalent dipoles: A simple example.........................................................197 A4.2. How to localize components using BESA..............................................................................................198 A4.3. Exporting component information..........................................................................................................199 A4.4. Importing BESA component locations ....................................................................................................200 A4.5. Visualizing dipole locations....................................................................................................................200 A4.6. Miscellany..............................................................................................................................................202 A5. Adding capabilities to EEGLAB ..........................................................................................................................203 A5.1. Open source policy................................................................................................................................203 A5.2. How to write EEGLAB functions .............................................................................................................203 A5.2.1. The signal processing function.....................................................................................................203 A5.2.2. The associated pop_ function.......................................................................................................203 A5.3. How to write an EEGLAB plugin............................................................................................................204 A5.3.1. The plugin function.......................................................................................................................204 A5.3.2. Adding a sub-menu .......................................................................................................................204 A5.3.3. Plugins and EEGLAB history........................................................................................................205 A5.3.4. Plugin examples...........................................................................................................................205
Introduction
What is EEGLAB?
EEGLAB is an interactive Matlab toolbox for processing continuous and event-related EEG, MEG and other electrophysiological data using independent component analysis (ICA), time/frequency analysis, and other methods including artifact rejection. First developed on Matlab 6.1 under Linux, EEGLAB runs on Matlab versions 6 (R13) and 7 (R14) under Linux or Unix, Windows, and Mac OS (Matlab v6 or current v7 recommended).
Why EEGLAB?
EEGLAB provides an interactive graphic user interface (gui) allowing users to flexibly and interactively process their high-density EEG and other dynamic brain data using independent component analysis (ICA) and/or time/frequency analysis (TFA), as well as standard averaging methods. EEGLAB also incorporates extensive tutorial and help windows, plus a command history function that eases users' transition from gui-based data exploration to building and running batch or custom data analysis scripts. EEGLAB offers a wealth of methods for visualizing and modeling event-related brain dynamics. For experienced Matlab users, EEGLAB offers a structured programming environment for storing, accessing, measuring, manipulating and visualizing event-related EEG, MEG, or other electrophysiological data. For creative research programmers and methods developers, EEGLAB offers an extensible, open-source platform through which they can share new methods with the world research community by contributing EEGLAB 'plug-in' functions that appear automatically in the EEGLAB menu. For example, EEGLAB is also being used for analysis of MEG data in several laboratories; EEGLAB plug-in functions might be created and released to perform specialized import/export, plotting and inverse source modeling for MEG data.
Tutorial Outline
This tutorial will demonstrate (hands-on) how to use EEGLAB to interactively preprocess, analyze, and visualize the dynamics of event-related EEG, MEG, or other electrophysiological data by operating on the tutorial EEG dataset "eeglab_data.set" which you may download here (4Mb). With this dataset, you should be able to reproduce the sample actions discussed in the tutorial and get the same (or equivalent) results as shown in the many results figures. For an overview outline of the whole tutorial, click here.
EEGLAB Overview
The EEGLAB graphic user interface (gui). The EEGLAB gui is designed to allow non-experienced Matlab users to apply advanced signal processing techniques to their data. However, more experienced users can also use the gui to save time in writing custom and/or batch analysis scripts in Matlab by incorporating menu shortcuts and EEGLAB history functions. The EEGLAB menu. Text files containing event and epoch information can be imported via the EEGLAB menu. The user can also use the menu to import event and epoch information in any of several file formats (Presentation, Neuroscan, ASCII text file), or can read event marker information from the binary EEG data file (as in, e.g., EGI, Neuroscan, and Snapmaster data formats). The menu then allows users to review, edit or transform the event and epoch information. Event information can be used to extract data epochs from continuous EEG data, select epochs from EEG data epochs, or to sort data trials to create ERP-image plots (Jung et al., 1999; Makeig et al., 1999). EEGLAB also provides functions to compute and visualize epoch and event statistics. Data structures and events. EEGLAB uses a single structure (EEG) to store data, acquisition parameters, events, channel locations, and epoch information as an EEGLAB dataset. This structure can also be accessed directly from the Matlab command line. The EEG structure contains two key sub-structures: EEG.chanlocs, holding channel locations, and EEG.event storing dataset event information. In EEGLAB v5.0 (March, 2006), a new superordinate structure, the STUDY has been introduced to allow automated processing of a group of EEG datasets. The first such facility introduced is a set of study functions to perform and evaluate clustering of similar independent data components across subjects, conditions, and sessions. 1
Introduction Three levels of use. EEGLAB functions may be roughly divided into three layers designed to increase ease-of-use for different types of users: I. Gui-based use. New Matlab users may choose to interact only with the main EEGLAB window menu, first to import data into EEGLAB (in any of several supported formats), and then to call any of a large number of available data processing and visualization functions by selecting main-window menu items organized under seven headings: File menu functions read/load and store/save datasets and studysets. Edit menu functions allow editing a dataset, changing its properties, reviewing and modifying its event and channel information structures. Tools menu functions extract epochs from continuous data (or sub-epochs from data epochs), perform frequency filtering, baseline removal, and ICA, and can assist the user in performing semi-automated artifact data rejection based on a variety of statistical methods applied to activity in the raw electrode channels or their independent components. Plot menu functions allow users to visualize the data in a variety of formats, via (horizontally and vertically) scrolling displays or as trial (ERP), power spectrum, event-related time/frequency averages, etc. A large number of visualization functions are dedicated to the display and review of properties of scalp data channels and underlying independent data components. The user can make use of standard Matlab capabilities to edit, print, and/or save the resulting plots in a variety of formats. Study menu entries show the current studyset and which of its constituent datasets are currently loaded. Datasets menu entries list loaded datasets, and allows the user to swtich back and forth among them. Help menu functions allow users to call up documentation on EEGLAB functions and data structures, including function lists and scrolling function help messages. II. EEGLAB command history. Intermediate level users may first use the menu to perform a series of data loading, processing and visualization functions, and then may take advantage of the EEGLAB command history functions to easily produce batch scripts for processing similar data sets. Every EEGLAB menu item calls a Matlab function that may also be called from the Matlab command line. These interactive functions, called "pop" functions, work in two modes. Called without (or in some cases with few) arguments, an interactive data-entry window pops up to allow input of additional parameters. Called with additional arguments, "pop" functions simply call the eponymous data processing function, without creating a pop-up window. When a "pop" function is called by the user by selecting a menu item in the main EEGLAB window, the function is called without additional parameters, bringing up its gui pop-up window to allow the user to enter computation parameters. When the processing function is called by EEGLAB, its function call is added as a command string to the EEGLAB session history variable. By copying history commands to the Matlab command line or embedding them in Matlab text scripts, users can easily apply actions taken during a gui-based EEGLAB session to a different data set. A comprehensive help message for each of the "pop" functions allows users to adapt the commands to new types of data. III. Custom EEGLAB scripting. More experienced Matlab users can take advantage of EEGLAB functions and dataset structures to perform computations directly on datasets using their own scripts that call EEGLAB and any other Matlab functions while referencing EEGLAB data structures. Most "pop_" functions describe above call signal processing functions. For example, the pop_erpimage() function calls signal processing and plotting function erpimage(). Since all the EEGLAB data processing functions are fully documented, they can be used directly. Experienced users should benefit from using all three modes of EEGLAB processing: gui-based, history-based, and autonomously scripted data analyses. Such users can take advantage of the data structure (EEG) in which EEGLAB datasets are stored. EEGLAB uses a single Matlab variable, a structure, "EEG", that contains all dataset information and is always available at the Matlab command line. This variable can easily be used and/or modified to perform custom signal processing or visualizations. Finally, while EEGLAB "pop" functions (described above) assume that the data are stored in an EEG data structure, most EEGLAB signal processing functions accept standard Matlab array arguments. Thus, it is possible to bypass the EEGLAB interface and data structures entirely, and directly apply the signal processing functions to data matrices. Distribution, documentation and support. The EEGLAB toolbox is distributed under the GNU General Public License (for details see http://www.gnu.org/licenses/gpl.txt). The source code, together with web tutorials and function description help pages, is freely available for download from http://sccn.ucsd.edu/eeglab/. The toolbox currently includes well over 300 Matlab functions comprising more than 50,000 lines of Matlab code. This user tutorial explains 2
Introduction in detail how to import and process data using EEGLAB, including the derivation and evaluation of its independent components. SCCN also provides "Frequently Asked Questions (FAQ)" and "Known Bugs" web pages, a support email ([email protected]), a dedicated mailing list for software updates ([email protected]), and an email discussion mailing list ([email protected]), which currently reaches over two thousand EEG researchers. Open-source EEGLAB functions are not precompiled; users can read and modify the source code of every function. Each EEGLAB function is also documented carefully using a standardized help-message format and each function argument is described in detail with links to related functions. We have attempted to follow recognized best practice in software design for developing EEGLAB. The source code of EEGLAB is extensively documented and is internally under the Linux revision control system (RCS), which allows us to easily collaborate with remote researchers on the development of new functions. Matlab allows incremental design of functions, so adding new features to a function can be easily accomplished while preserving backward compatibility. (Adapted from, A Delorme & S Makeig. EEGLAB: an open source toolbox for analysis of single-trial EEG dynamics. Journal of Neuroscience Methods 134:9-21 (2004)).
I.1.1.2. Installing EEGLAB and tutorial files If you started Matlab with its graphical interface, go to menu item "file" and select "set path", which opens the following window.
Or, if you are running Matlab from the command line, type in "pathtool", which will also call up this window. Click on the button marked "Add folder" and select the folder "eeglab4.512", then hit "OK" (EEGLAB will take care of adding its subfolder itself). Hit "save" in the pathtool window, which will make eeglab available for future Matlab sessions. Note that if you are installing a more recent version of EEGLAB, it is best to remove the old version from the Matlab path (select and hit "Remove") to avoid the possibility of calling up outdated routines. I.1.1.3. Starting Matlab and EEGLAB Here we will start Matlab and EEGLAB. KEY STEP 1: Start Matlab. WINDOWS: Go to Start, find Matlab and run it. Mac Option 1: Start from the Matlab icon in the dock or in the application folder. Mac Option 2: Start X11 and in a terminal window type "matlab" and hit enter. For added stability type "matlab -nodesktop" to run it without its java desktop. Linux: Open a terminal window and follow the Mac Option 2 instructions above. KEY STEP 2 (optional): Switch to the data directory (folder). In this case the directory you switch to should be the directory containing the example data provided for this tutorial. If you are running Matlab with its java desktop, you may also browse for the directory by clicking on the button marked "..." in the upper right of the screen,
which opens the window below. Double-click on a directory to enter it. Double-clicking on ".." in the folder list takes you up one level. Hit "OK" once you find the folder or directory you wish to be in. Alternatively, from the command line use "cd" (change directory) to get to the desired directory. KEY STEP 3: Start EEGLAB. Just type "eeglab" at the Matlab command line and hit enter.
The blue main EEGLAB window below should pop up, with its seven menu headings: File Edit Tools Plot Study arranged in typical (left-to-right) order of use. Datasets Help
To learn how to create EEGLAB datasets from your own data, see the tutorial chapter II on Importing data and data events. Select the tutorial file "eeglab_data.set" which is distributed with the toolbox (available here - press the right mouse button and select "save link as" if strange characters appear - or in the "sample_data" sub-directory if you downloaded the full version of EEGLAB) and press " Open". When the dataset is loaded by EEGLAB, the main EEGLAB window shows relevant information about it -- the number of channels, sampling rate, etc...:
Scroll through the events by pressing the ">", ">>", " < " and "<<" keys above. We will now briefly describe the experiment that produced the sample dataset to motivate the analysis steps we demonstrate in the rest of the tutorial. Sample experiment description In this experiment, there were two types of events "square" and "rt", "square" events corresponding to the appearance of a green colored square in the display and rt to the reaction time of the subject. The square could be presented at five locations on the screen distributed along the horizontal axis. Here we only considered presentation on the left, i.e. position 1 and 2 as indicated by the "position" field (at about 3 degree and 1.5 degree of visual angle respectively). In this experiment, the subject covertly attended to the selected location on the computer screen responded with a quick thumb button press only when a square was presented at this location. They were to ignore circles presented either at the attended location or at an unattended location. To reduce the amount of data required to download and process, this dataset contains only targets (i.e., "square") stimuli presented at the two left-visual-field attended locations for a single subject. For more details about the experiment see Makeig et al., Science, 2002, 295:690-694. When using events in an EEGLAB dataset, there are two required event fields: "type" and "latency", plus any number of additional user-defined information fields. It is important to understand here that the names of the fields were defined by the user creating the dataset, and that it is possible to create, save, and load as many event fields as desired. Note also that "type" and "latency" (lowercase) are two keywords explicitly recognized by EEGLAB and that these fields must be defined by the user unless importing epoch event information (Note: If only field "latency" is defined, then EEGLAB will create field "type" with a constant default value of 1 for each event). Unless these two fields are defined, EEGLAB will not be able to handle events appropriately to extract epochs, plot reaction times, etc. The Creating datasets tutorial explains how to import event information and define fields.
I.1.4. About this dataset Exploratory Step: Editing the Dataset Description. Select Edit > About this dataset. A text-editing window pops up which allows the user to edit a description of the current dataset. For the sample data, we entered the following description of the task. Press SAVE when done.
To the right of the plot window is the vertical scale value (unit, i.e. microvolts), which indicates the "height" of the given vertical scale bar. In this case, that value is 80 (microvolts). The same value is also shown in the lower right-hand edit box, where we can change it as explained below. Exploratory Step: Voltage Scale. Change the "Scale" edit-text box value to about 50, either by repeatedly clicking on the "-" button or by editing the text value from the keyboard, and press the "Enter" key to update the scrolling window.
Exploratory Step: Time Scale. To adjust the time range shown (horizontal scale), select eegplot() menu item Settings > Time range to display, and set the desired window length to "10" seconds as shown below,
10
Exploratory Step: Number of Channels to Display. To adjust the number of channels displayed, select eegplot() menu item Settings > Number of channels to display and enter the desired number of channels to display in the screen (for instance "16").
This will return a scrolling eegplot() window with a vertical channel-set slider on the left of the plot. Use it to scroll vertically through all the channels.
11
Exploratory Step: Zoom. To zoom in on a particular area of a data window, select eegplot() menu item Settings > Zoom off/on > Zoom on. Now using your mouse, drag a rectangle around an area of the data to zoom in on. The scrolling window may now look similar to the following. Click the right button on the mouse to zoom out again. Use menu Setting > Zoom off/on > Zoom off to turn off the zoom option.
Exploratory Step: Grid Lines. To display horizontal (x) and vertical (y) grid lines on the data, select Display > Grid > x axis or Display > Grid > y axis. Repeat this process to turn off either set of grid lines.
12
The eegplot() window also allows you to reject (erase) arbitrary portions of the continuous data. Actually, in the main EEGLAB menu, eegplot() is called from both menu items Plot > Scroll data and Tools > Reject continuous data using the " REJECT" button on the bottom right corner. Exploratory Step: Rejecting Data. Close the current eegplot() window and call Tools > Reject Continuous Data by eye from the main EEGLAB window. A warning message appears, click on continue. To erase a selected portion of the data, first drag the mouse along the area of interest to mark it for rejection. It is possible to mark multiple regions. To undo a rejection mark, click once on the marked region. Note: Zooming must be disabled to select a portion of the data.
Now, to erase the marked data regions, click the (lower right) " REJECT" button (above). A new dataset will be created with the marked regions removed. (Note: EEGLAB will also add new "rejection boundary" events to the new dataset event list. These insure that subsequent epoch selections will not cross non-contiguous rejection boundaries). For more details about rejecting continuous data regions and data epochs, see the data rejection tutorial. 13
I.2. Using channel locations Click " OK" (below) to create the new dataset with the marked data portions removed.
Press "OK" to create the new dataset. The EEGLAB main window now looks like:
Since we only performed this rejection for illustrative purposes, switch back to the original dataset by selecting main window menu item Datasets > Dataset 1 eeglab_data. Exploratory Step: Deleting a Dataset from Memory. To delete the newly created second dataset, select File > Clear dataset(s) or Edit > Delete dataset(s) and enter the dataset index, "2" as shown below, and press " OK".
The second dataset will now be removed from the Matlab workspace. Note: It is not necessary to switch back to the first dataset before deleting the second. It is also possible to delete several datasets at once from this window by entering their indices separated by spaces.
14
If you imported a binary data file in Neuroscan or Biosemi formats, channel labels will be present in the dataset (as of EEGLAB v4.31). When you call the channel editing window, a dialog box will appear asking you if you want to use standard channel locations corresponding to the imported channel labels (for example. Fz) from an channel locations file using an extended International 10-20 System. Otherwise, you must load a channel locations file manually. To load a channel locations file, press the " Read Locations" button and select the sample channel locations file "eeglab_chan32.locs" (this file is located in the "sample_data" sub-directory of the EEGLAB distribution).
In the next pop-up window, simply press " OK". If you do not specify the file format, the pop_chanedit() function will attempt to use the filename extension to assess its format. Press button " Read help" in the main channel graphic interface window to view the supported formats.
15
Now the loaded channel labels and polar coordinates are displayed in the pop_chanedit() window. To plot scalp maps only inside the head cartoon, enter "0.5" at the Plot radius edit box. In this case, the two eye electrodes will not be displayed nor considered computing interpolated 2-D scalp maps. If you do not see enough of the recorded field, set this dialogue box to "1.0" to interpolate and show scalp maps including all channels, with parts of the head below the (0.5) head equator shown in a 'skirt' or 'halo' outside the cartoon head boundary. (More precise spearate controls of which channel locations to interpolate and plot are available from the command line in the topographic map plotting function topoplot(). In the window below, you may scroll through the channel field values 1-by-1 using the "<" and ">" buttons, or in steps of 10 using "<<" and ">>".
The Set channel type button allows you to enter a channel type associated with the channel (for example, 'EEG', 'MEG', 'EMG', 'ECG', 'Events', etc.). Although channel types are not yet (v5.0b) widely used by other EEGLAB functions, they will be used in the near future to restrict plotting and computation to a desired subset of channel types, allowing easier analysis of multimodal datasets. It is therefore well worth the effort to add channel types to your data. This may also be done from the Matlab commandline. For example, to set the channel type of all channels except the last to 'EEG', and the last channel to type 'Events,' for c=1:EEG.nbchan-1 EEG.chanlocs(c).chantype = 'EEG'; end EEG.chanlocs(end).chantype = 'Events'; [ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); 16
I.2.1. Importing channel location for the tutorial dataset Important: Press Ok in the channel editing window above to actually import the channel locations!. Note that in the main EEGLAB window, the "channel location" flag now shows "yes". Supported channel locations file formats. Following are examples of ascii channel locations data in EEGLAB-supported formats: - Four channels from a polar coordinates file (with filename extension .loc, Do not include the (light blue) header line: # 1 2 3 Deg. -18 18 -90 Radius ,352 .352 ,181 Label Fp1 Fp2 C3
4 90 ,181 C4 - The same locations, from a spherical coordinates file (estension, .sph ): # 1 2 3 4 Azimut -63.36 63.36 32.58 32.58 Horiz. -72 72 0 0 Label Fp1 Fp2 C3 C4
- The same locations from a Cartesian coordinates file (extension, .xyz ): # 1 2 3 4 X -0.8355 -0.8355 0.3956 0.3956 Y -0.2192 0.2192 0 0 Z -0.5039 0.5039 -0.9184 0.9184 Label Fp1 Fp2 C3 C4
Note: In all the above examples, the first header line must not be present. Other supported channel locations file formats Polhemus (.elp) files Neuroscan spherical coordinates (.asc, .dat) Besa spherical coordinates (.elp, .sfp) EETrak sofware files (.elc) EEGLAB channel locations files saved by the pop_chanedit() function (.loc, .xyz, .sph, .ced) Note that pop_chanedit() and readlocs() can also be called from the command line to convert between location formats. For more details, see the readlocs() help message. Exploratory Step: Viewing Channel Locations. Reopen Edit > Channel locations if you closed it. To visualize the 2-D locations of the channels, press " Plot 2-D" above the " Read Locations" button. Else, at any time during an EEGLAB session you may refer to a plot showing the channel locations by selecting Plot > Channel location > By name . Either command pops up a window like that below. Note: In this plot, click on any channel label to see its channel number.
17
All channels of this montage are visible in the 2-D view above, since none of these channels are located below the head center and equator line. If the montage contained channel locations whose polar coordinate radius values were larger than the default value (e.g., 0.5) you entered in the pop_chanedit() window, those locations would not appear in the top-down 2-D view, and the interpolated scalp map would end at the cartoon head boundary. The 2-D plotting routine topoplot() gives the user full flexibility in choosing whether to show or interpolate data for inferior head channels; topoplot() is used by all EEGLAB functions that plot 2-D scalp maps. To visualize the channel locations in 3-D, press " Plot 3-D (xyz)". The window below will appear. The plotting box can be rotated in 3-D using the mouse:
You may change channel locations manually using the edit box provided for each channel's coordinates. However, after each change, you must update the other coordinate formats. For instance, if you update the polar coordinates for one channel, then press the " polar->sph. & xyz" button on the right of the pop_chanedit() window (see above) to convert these values to other coordinate formats.
18
Press Yes. The function will automatically look up channel locations for these known channel labels. The following channel editing window will then pop up.
Press "Plot 2-D" to plot the channel locations. Close the channel editing window (using Cancel to discard the entered locations), then proceed to the next section.
19
Press the "Read locations" button and select the file "scanned72.dat" from the "sample_data" subfolder of the 20
I.2.3. Importing measured 3-D channel locations information EEGLAB distribution. This is a channel locations file measured with the Polhemus system using Neuroscan software (kindly supplied by Zoltan Mari). Use autodetect ([]) for the file format. When the file has been imported, press the "Plot 2-D" button. The following plot will pop up.
As you can see, the measured 3-D channel coordinates may not be accurately distributed on the 2-D head model. This is because the measured values have not been shifted to the head center. To fix this problem, you must first find the head sphere center that best fits the imported 3-D electrode locations. To do so, press the "Opt. head center" (optimize head center). The following window will pop up:
Possibly, some of the channels should not be included in the head center optimization, if they are not on the head and/or do not have recorded locations. Enter electrodes indices to use (here, 1:3 33 35 64:72) in the edit window. You may also press the "Browse" button above to select channels that are not on the head. When you press OK in the browser window, the channel indices will be copied, as shown in the window above. Then press Ok. After the optimization has finished, press the "Plot 2-D" button once more.
21
In the view above, some channel locations are still incorrect. For instance, you may expect channel "Cz" to be at the vertex (plot center). To adjust this, press the "Rotate axis" button. The following window will pop up:
Simply press Ok to align channel 'Cz' to the vertex (by default). Then press the "Plot 2-D" button once more to again plot the scalp map.
I.3. Plotting channel spectra and maps This section has illustrated operations you may want to perform to adapt measured 3-D channel locations for use in EEGLAB. In the next chapter, we return to the tutorial dataset.
Exploratory Step: Plot Channel Spectra and Maps. To plot the channel spectra and associated topographical maps, select Plot > Channel spectra and maps. This will pop up the pop_spectopo() window (below). Leave the default settings and press " OK".
The function should return a spectopo() plot (below). Since we only sampled 15% of the data (via the "Percent data..." edit box above), results should differ slightly on each call. (Naturally, this will not occur if you enter 100% in the edit box).
Each colored trace represents the spectrum of the activity of one data channel. The leftmost scalp map shows the scalp distribution of power at 6 Hz, which in these data is concentrated on the frontal midline. The other scalp maps indicate the distribution of power at 10 Hz and 22 Hz. The pop_spectopo() window menu (above) allows the user to compute and plot spectra in specific time windows in the data. The "Percent data..." value can be used to speed the computation (by entering a number close to 0) or to return more definitive measures (by entering a number closer to 100). 23
I.4. Preprocessing tools Note: Functions pop_spectopo() and spectopo() also work with epoched data. Another menu item, Plot > Channel properties, plots the scalp location of a selected channel, its activity spectrum, and an ERP-image plot of its activity in single-epochs. The next section deals with some data pre-processing options available via the EEGLAB menu.
A pop_newset() window will pop up to ask for the name of the new dataset. We choose to modify the dataset name and to overwrite the parent dataset by checking the "Overwrite parent" checkbox, then pressing the "OK" button.
24
Note: If high-pass and low-pass cutoff frequencies are BOTH selected, the filtering routine may not work. To avoid this problem, we recommend first applying the low-pass filter and then, in a second call, the high-pass filter (or vice versa). Another common use for bandpass filtering is to remove 50-Hz or 60-Hz line noise. The filtering option in EEGLAB, eegfilt(), uses linear finite impulse response (FIR) filtering. If the Matlab Signal Processing Toolbox is present, it uses the Matlab routine filtfilt(). This applies the filter forward and then again backward, to ensure that phase delays introduced by the filter are nullified. If the Matlab Signal Processing toobox is not present, EEGLAB uses a simple filtering method involving the inverse fourrier transform. A non-linear infinite impulse response (IIR) filter plug-in is also distributed with EEGLAB. See menu item Tools > Filter the data (IIR). It uses the same graphical interface as the FIR filtering option described above. Although non-linear filters usually introduce different phase delays at different frequencies, this is compensated for by again applying filtering in reverse using Matlab function filtfilt(). In practice, we suggest you test the use of this non-linear filter, as is is stronger (and shorter) than linear filters. Note: If you apply filtering and continue to work with the updated data set, check that the filter has been applied by selecting menu item Plot > Channel spectra and maps to plot the data spectra. You might notice that filtered-out frequency regions might show 'ripples', unavoidable but hopefully acceptable filtering artifacts. (Note: There is much more to be learned about filtering, and more filtering options available in Matlab intself).
25
Converting data, before analysis, from fixed or common reference (for example, from a common earlobe or other channel reference) to 'average reference' is advocated by some researchers, particularly when the electrode montage covers nearly the whole head (as for some high-density recording systems). The advantage of average reference rests on the fact that outward positive and negative currents, summed across an entire (electrically isolated) sphere, will sum to 0 (by Ohm's law). For example, in the figure below a tangentially-oriented electrical source is associated with a positive inward current to the left (here, blue) and an opposing outward negative current to the right (red). If the current passing through the base of the skull to the neck and body is assumed to be negligible (for instance, because of low conductance of the skull at the base of the brain), one may assume that the sum of the electric field values recorded at all (sufficiently dense and evenly distributed) scalp electrodes is always 0 (the average reference assumption). The problem with this assumption is that "true" average reference data would require the distribution of electrodes to be even over the head. This is not usually the case, as researchers typically place more electrodes over certain scalp areas, and fewer (if any) on the lower half of the head surface. As a consequence, an average reference result using one montage may not be directly comparable to an average reference result obtained using another montage.
26
Below, we detail the process of transforming data to 'average reference'. Note that in this process, the implied activity time course at the former reference electrode may be calculated from the rest of the data (so the data acquires an additional channel - though not an additional degree of freedom!). Also note that if the data were recorded using nose tip or ear lobe electrodes, you should not include these reference electrodes when computing the average reference in (1) (below), Thus, in the example below the dividing factor (in (3)) would be 64 instead of 65. Note that in localizing sources using the EEGLAB DIPFIT plug-in, 'average reference' will be used internally (without user input). The choice of data reference does color (literally) the plotted results of the data analysis. For example, plots of mean alpha power over the scalp must have a minimum at the reference channel, even if there are in fact alpha sources just below and oriented toward the reference channel! However, no (valid) reference can said to be wrong - rather, each reference can be said to give another view of the data. Howeever, the nature of the reference needs to be taken into account when evaluating (or, particularly, comparing) EEG results.
For ICA decomposition (covered later in the tutorial), the selection of reference is not so important. This is because changing the reference only amounts to making a linear transformation of the data (in mathematical terms, multiplying it by a fixed re-referencing matrix), a transformation to which ICA should be insensitive. In practice, we have obtained results of similar quality from data recorded and analyzed with mastoid, vertex, or nose tip reference. We advise recording eye channels (conventionally four channels, two for vertical eye movement detection and two for horizontal eye movement detection) using the same reference as other channels, instead of using bipolar montages. One can always recover the bipolar montage activity by subtracting the activities of the electrode pairs. We term these channels 'peri-ocular EEG' channels since what they record is not exclusively electrooculographic (EOG) signals, but also includes e.g. prefrontal EEG activities. ICA can be used to decompose data from either average reference, common reference, or bipolar reference channels -- or from more than one of these types at once. However, plotting single scalp maps requires that all channels use either the same common reference or the same average reference. Robert Oostenveld advises that peri-ocular channel values, even in ICA component maps, may best be omitted from inverse source modeling using simple head models, since these are apt to poorly model the conductance geometry at the front of the head. We will now describe how to specify the reference electrode(s) in EEGLAB and to (optionally) re-reference the data Exploratory Step: Re-reference the Data. Select Tools > Re-reference to convert the dataset to average reference by calling the pop_reref() function. When you call this menu item for the first time for a given dataset, the following window pops up.
27
The (sample) data above were recorded using a mastoid reference. Since we do not wish to include this reference channel (neither in the data nor in the average reference), we do not click the "Include current reference channel in data" checkbox (Do click this checkbox when the recording reference was on the scalp itself). The box "Data are referenced to one site (default)" should remain checked. Now, press the "OK" button: the re-referencing window below appears.
Press the "Ok" button to compute the average reference. This step will then be recorded in the main EEGLAB window (not shown). As in the previous step, a dialogue box will appear asking for the name of the new dataset. Save the re-referenced data to a new dataset or hit cancel, as the new reference is not used in the following sections. After the data have been average referenced, calling the Tools > Re-reference menu still allows re-referencing the data to any channel or group of channels (or undoing an average reference trqansform -- as long as you chose to include the initial reference channel in the data when you transformed to average reference). Note: The re-referencing function also re-references the stored ICA weights and scalp maps, if they exist. The next tutorial section deals with extracting data epochs from continuous or epoched datasets.
28
Click on the upper right button, marked "...", of the resulting pop_epochs() window, which calls up a browser box listing the available event types.
Here, choose event type "square" (onsets of square target stimuli in this experiment), and press "OK". You may also type in the selected event type directly in the upper text box of the pop_epochs() window.
Here, retain the default epoch limits (from 1 sec before to 2 sec after the time-locking event). If you wish, add a descriptive name for the new dataset. Then press "OK". A new window will pop up offering another chance to change the dataset name and/or save the dataset to a disk file. At this point, it can be quite useful to edit the dataset description -- to store the exact nature of the new dataset in the dataset itself, for future reference. Do this by pressing "Description". Accept the defaults and enter "OK".
Another window will then pop up to facilitate removal of meaningless epoch baseline offsets. This operation is discussed in the next section. In this example, the stimulus-locked windows are 3 seconds long. It is often better to extract long data epochs, as here, to make time-frequency decomposition possible at lower (<< 10 Hz) frequencies.
29
I.5.2. Removing baseline values After the data has been epoched, the following window will pop up automatically. It is also possible to call it directly, by selecting menu item Tools > Remove baseline.
Here we may specify the baseline period in each epoch (in ms or in frames = time points) -- the latency window in each epoch across which to compute the mean to remove The original epoched dataset is by default overwriten by the baseline-removed dataset. Note: There is no uniformly 'optimum' method for selecting either the baseline period or the baseline value. Using the mean value in the pre-stimulus period (the pop_rmbase() default) is effective for many datasets, if the goal of the analysis is to define transformations that occur in the data following the time-locking events. Press " OK" to subtract the baseline (or " Cancel" to not remove the baseline). Exploratory Step: Re-reference the Data. This is a good time to save the epoched and baseline-removed dataset under a new name, as explained above, since we will be working extensively with these data epochs. You should also preserve the continuous dataset on the disk separately to allow later arbitrary re-epoching for various analyses. We might have saved the epoched dataset as a new file under a new filename using the pop_newset() window (above) (by pressing " Browse"). To save the current dataset at any other time, select File > Save current dataset or File > Save current dataset as from the EEGLAB menu. (In this case, these two menu items are equivalent, since we have not yet saved this dataset). The file-browser window below appears. Entering a name for the dataset (which should end with the filename extension ".set"), and pressing " SAVE" (below) and then " OK" (above) will save the dataset including all its ancillary information re events, channel locations, processing history, etc., plus any unique structure fields you may have added yourself - see the script writing tutorial.
The next tutorial discusses averaging the data epochs of epoched datasets.
I.6. Data averaging in a set of data epochs time locked to some class of events are not limited to nor completely expressed in features of their time-locked trial average or Event-Related Potential (ERP). EEGLAB contains several functions for plotting 1-D ERP averages of dataset trials (epochs). EEGLAB also features functions for studying the EEG dynamics expressed in the single trials, which may be visualized, in large part, via 2-D (potential time series by trials) 'ERP-image' transforms of a dataset of single-trial epochs (a.k.a., epoched data). In ERP-image plots, EEG data epochs (trials) are first sorted along some relevant dimension (for example, subject reaction times, within-trial theta power levels, mean voltage in a given latency window, alpha phase at stimulus onset, or etc.), then (optionally) smoothed across neighboring trials, and finally color-coded and visualized as a 2-D rectangular color (or monochrome) image. (Construction of ERP images will be detailed in section I.8).
I.6.1. Plotting the ERP data on a single axis with scalp maps
Here, we will use the tutorial dataset as it was after the last Key Step, Key Step 8. Exploratory Step: Plotting all-channel ERPs. To plot the (ERP) average of all dataset epochs, plus ERP scalp maps at selected latencies, select Plot > Channel ERP> With scalp maps. As a simple illustration using the sample dataset, we retain the default settings in the resulting pop_timtopo() window, entering only a plot title and pressing " OK".
A timtopo() figure (below) appears. Each trace plots the averaged ERP at one channel. The scalp map shows the topographic distribution of average potential at 430 ms (the latency of maximum ERP data variance). Alternatively, one or more exact scalp map latencies may be specified in the pop-window above.
31
I.6.1. Plotting the ERP data on a single axis with scalp maps Function timtopo() plots the relative time courses of the averaged ERP at all channels, plus "snapshots" of the scalp potential distribution at various moments during the average ERP time course. Note: To visualize the ERP scalp map at all latencies -- as an "ERP movie" (i.e., to view the play of the ERP on the scalp), call function eegmovie() from the command line.
Note: If called from the command line, the plottopo() function 'geom' option can also be used to plot channel waveforms in a rectangular grid. You may visualize a specific channel time course by clicking on its trace (above), producing a pop-up sub-axis view. For example, click on the ERP trace marked "POz" (above) to call up a full-sized view of this trace (as below).
32
Many EEGLAB plotting routines use the toolbox function axcopy() to pop up a sub-axis plotting window whenever the users clicks on the main plot window. Sub-axis windows, in turn, do not have axcopy() enabled, allowing the user to use the standard Matlab mouse 'Zoom In/Out' feature.
33
As in the previous plot, clicking on a trace above pops up a full window sub-axis view.
The topoplot() window (below) then appears, containing ERP scalp maps at the specified latencies. Here, the plot grid has 3 columns and 2 rows; other plot geometries can be specified in the gui window above via the Plot geometry text box.
34
I.6.4.2. Plotting ERP data as a series of 3-D maps Exploratory Step: Plotting a series of 3-D ERP scalp maps. To plot ERP data as a series of 3-D scalp maps, go to the menu Plot > ERP map series > In 3-D The query window (below) will pop up, asking you to create and save a new 3-D head map 3-D spline file. This process must be done only once for every montage (and proceeds much more quickly in EEGLAB v4.6-). Click Ok to begin this process.
The window below will pop up. Here, you have two choices: If you have already generated a spline file for this channel location structure, you may enter it here in the first edit box (first click on the "Use existing spline file or structure" to activate the edit box, then browse for a datafile. If you have not made such a file, you will need generate one. However, first your channel locations must be co-registered with the 3-D head template to be plotted. Note: If you are using one of the template channel location files, for example, the (v4.6+) tutorial dataset, the "Talairach transformation matrix" field (containing channel alignment information) will be filled automatically. Enter an output file name (in the second edit box), trial latencies to be plotted ("0:100:500" below indicating latencies 0, 100, 200, 300, 400, and 500 ms) and press OK.
35
I.6.4.2. Plotting ERP data as a series of 3-D maps Now, the 3-D plotting function pop_headplot(), will create the 3-D channel locations spline file. A progress bar will pop up to indicate when this process will be finished. When the 3-D spline file has been generated, select Plot > ERP map series > In 3-D. Now that a spline file has been selected, another gui window will appear. As for plotting 2-D scalp maps, in the first edit box type the desired latencies, and press OK. The headplot() figure (below) will appear .
As usual, clicking on a head plot will make it pop up in a sub-axis window in which it can be rotated using the mouse. Note: To select (for other purposes) a head plot or other object in a figure that has the axcopy() pop-up feature activated, click on it then delete the resulting pop-up window. To plot the heads at a specified angle, select the Plot > ERP map series > In 3-D menu item. Note that now by default the function uses the 3-D spline file you have generated above. Enter latencies to be displayed and the headplot() 'view' option (as in the example below), and press OK.
The headplot() window (below) will then appear. You may also rotate the individual heads using the mouse. This is often necessary to show the illustrated spatial distribution to best effect.
36
We will now briefly describe the channels-to-head model co-registration process. If your dataset contains specific channel locations, for example locations that you may have measured on the subject head using a Polhemus system, and you want to use these electrode locations for 3-D plotting, headplot() must first determine the positions of your electrode locations relative to a template head surface. A generic transformation cannot be performed because the origin ([0 0 0]) in your electrode location system does not necessarily correspond to the center of the template head (.e.g., the intersection of the fiducial points: nasion and pre-auricular points) used by headplot(). Even if this were the case, heads have different shapes, so your scanned electrode locations might need to be scaled or warped in 3-D to match the template head mesh. The co-registration window begins this operation. Call back the headplot(). gui window using menu item Plot > ERP map series > In 3-D. Set the checkbox labeled "Or recompute a new spline file named:", and then click the "Manual coreg." push button. A window appears explaining how to perform the co-registration.
37
I.7. Selecting data epochs and plotting data averages In the window above, the red electrodes are those natively associated with the template head mesh. Rather than directly aligning your electrode locations (shown in green) to the head mesh, your montage will be aligned to template electrode locations associated with the head mesh by scanning on the same subject's head (here shown in red). For the sample dataset, this alignment has already been performed. (Click the "Labels on" push button to display the electrode labels). When you have finished the co-registration, simply click OK and a vector of 9 new channel alignment values (shift, in 3-D; rotation, in 3-D; scaling, in 3-D) will be copied back to the interactive headplot() window. For more information about channel co-registration, see the DIPFIT tutorial. Note: It is possible, and relatively easy, to generate custom headplot() head meshes. Let us know by email if you are interested in learning how to do this.
The next tutorial section will demonstrate how to use EEGLAB functions to compare the ERP trial averages of two datasets.
Exploratory Step: Selecting Events and Epochs for Two Conditions. Select Edit > Select epochs/events. The pop_selectevent() window (below) will appear. Enter "1" in the textbox next to " position", which will select all epochs in which the target appeared in position "1".
38
Now a pop_newset() window for saving the new dataset pops up. We name this new dataset "Square, Position 1" and press " OK".
Now, repeat the process to create a second dataset consisting of epochs in which the target appeared at position 2. First, go back to the previous dataset by selecting Datasets > Continuous EEG Data epochs, Square. Next select Edit > Select epoch/events. In the resulting pop_selectevent() window, enter "2" in the text box to the right of the " position" field. Press OK, then name the new dataset "Square, Position 2".
See the event tutorial, section V.1.3 on selecting events for more details on this topic. Another function that can be useful for selecting a dataset subset is the function pop_select() called by selecting Edit > Select data. The example below would select data sub-epochs with the epoch time range from -500 ms to 1000 ms. It would, further, remove dataset epochs 2, 3 and 4 and remove channel 31 completely.
I.7.2. Computing Grand Mean ERPs Exploratory Step: Computing Grand Mean ERPs. Select Plot > Sum/Compare ERPs. In the top text-entry boxes of the resulting pop_comperp() window (below), enter the indices of datasets 3 and 4. On the first row, click the "avg." box to display grand average, the "std." box to display standard deviation, and the "all ERPs" box to display ERP averages for each dataset. Finally 0.05 for the t-test significance probability (p) threshold. Then press OK.
Now, click on the traces at electrode position FPz, calling up the image below. You may remove the legend by deselecting it under the Insert > Legend menu.
40
Note: If you prefer to use positive up view for the y-axis scale, type "'ydir', 1" in the "Plottopo options" field. This can be set as a global or project default in "icadefs.m". See the Options tutorial. The ERPs for datasets 3 and 4 are shown in blue and red. The grand average ERP for the two conditions is shown in bold black, and the standard deviation of the two ERPs in dotted black. Regions significantly different from 0 are highlighted based on a two-tailed t-test at each time point. This test compares the current ERP value distribution with a distribution having the same variance and a 0 mean. Note that this t-test has not been corrected for multiple comparisons. The p values at each time point can be obtained from a command line call to the function pop_comperp().
41
Note: It may be desirable to first use the low pass filtering edit box of the pop_comperp() interface to smooth average data peaks before measuring latency peaks.
42
Again, individual electrode traces can be plotted in separate windows by clicking on electrode locations of interest in the figure (above). Note that here, since the two conditions are similar (only the position of the stimulus on the screen changes), the ERP difference is close to 0.
This function can also be used to compute and plot grand-mean ERP differences between conditions across several subjects, and can assess significant differences between two conditions using a paired t-test (two-tailed). To do so, load the datasets for the two conditions for each subject into EEGLAB and enter the appropriate indices in the pop_comperp() window. In EEGLAB 5.0b, a new concept and data structure, the STUDY, has been introduced to aggregate and process datasets from multiple subjects, sessions, and/or conditions. See the Component clustering and STUDY structure tutorials for details. The new STUDY-based functions include a command line function, std_envtopo() that visualizes the largest or selected independent component cluster contributions to a grand-average ERP in two conditions, and to their difference. In the following sections, we will be working from the second dataset only, and will not use datasets 3 and 4. Return to the second dataset using the Datasets top menu, and optionally delete datasets numbers 3 and 4 using File > 43
I.8. Plotting ERP images Clear dataset(s). Data averaging collapses the dynamic information in the data, ignoring inter-trial differences which are large and may be crucial for understanding how the brain operates in real time. In the next section, we show how to use EEGLAB to make 2-D ERP-image plots of collections of single trials, sorted by any of many possibly relevant variables.
It is also easy to misinterpret or over-interpret an ERP-image plot. For example, using phase-sorting at one frequency (demonstrated below) may blind the userto the presence of other oscillatory phenomena at different frequencies in the same data. Again, it is the responsibility of the user to correctly weight and interpret the evidence that a 2-D ERP-image plot presents, in light of to the hypothesis of interest -- just as it is the user's responsibility to correctly interpret 1-D ERP time series.
44
The plot above shows that alpha band power (e.g., at 10 Hz) is concentrated over the central occipital scalp. Exploratory Step: Locating Electrodes. We will use the dataset as it was after the last Key Step, Key Step 8. To find which electrodes are located in this region, we can simply plot the electrode names and locations by selecting Plot > Channel locations > By name, producing the figure below. We see that electrode POz is the channel at which alpha power is largest. Click on the POz channel label (below) to display its number (27).
Note: It is also possible to plot electrode locations in the spectral graph by entering " 'electrodes', 'on' "in the lowest text box ("Scalp map options") of the interactive pop_spectopo() window.
45
An ERP image is a rectangular colored image in which every horizontal line represents activity occurring in a single experimental trial (or a vertical moving average of adjacent single trials). The figure below (not an ERP image) explains the process of constructing ERP-image plots. Instead of plotting activity in single trials such as left-to-right traces in which potential is encoded by the height of the trace, we color-code their values in left-to-right straight lines, the changing color value indicating the potential value at each time point in the trial . For example, in the following image, three different single-trial epochs (blue traces) would be coded as three different colored lines (below).
46
I.8.2. Plotting ERP images using pop_erpimage() By stacking above each other the color-sequence lines for all trials in a dataset, we produce an ERP image. In the standard erpimage() output figure (below), the trace below the ERP image shows the average of the single-trial activity, i.e. the ERP average of the imaged data epochs. The head plot (top left) containing a red dot indicates the position of the selected channel in the montage. (Note: Both of these plotting features (as well as several others) can be turned off in the pop_erpimage() pop-up window (above). See checkboxes "plot ERP" and "plot scalp map").
Since activity in single trials contains many variations, it may be useful to smooth the activity (vertically) across neighboring trials using a rectangular (boxcar) moving average. Exploratory Step: Plotting a Smoothed ERP. Again call up the pop_erpimage() interactive window and set the smoothing width to 10 instead of 1. Now (see below) it is easier to see the dominant alpha-band oscillations in single trials. Note: Because of the large number of available options, parameters from the last call (if any) are recalled as defaults (though optional arguments entered via the text box are not). If you experience a problem with this feature, you may type >>eegh(0) on the Matlab command line to clear the history.
47
When plotting a large number of trials, it is not necessary to plot each (smoothed) trial as a horizontal line. (The screen and/or printer resolution may be insufficient to display them all). To reduce the imaging delay (and to decrease the saved plot file size), one can decimate some of the (smoothed) ERP-image lines. Entering 4 in the "Downsampling" box of the pop_erpimage() window would decimate (reduce) the number of lines in the ERP image by a factor of 4. If the Smoothing width is (in this case) greater than 2*4 = 8, no information will be lost from the smoothed image. Note: To image our sample dataset, it is not necessary to decimate, since we have relatively few (80) trials.
48
Note: In this and some other interactive pop-windows, holding the mouse cursor over the label above a text-entry box for a few seconds pops up an explanatory comment. Now, the erpimage() figure below appears. The curved black line corresponds to the latency time of the event (rt) we are sorting by.
In general, the user can sort on any event field value. For example call back the pop_erpimage() window, press the " Epoch-sorting Field " button, and select position instead of latency. Remove rt from the Event type box. Finally enter yes under the Rescale box. Press OK. In the resulting erpimage() plot, trials are sorted by stimulus position (1 or 2, automatically normalized values to fit the post-stimulus space for display). Note that the smoothing width (10) is applied to both the single-trial data and to the sorting variable. This explains the oblique line connecting the low (1) and high (2) sorting variable regions. Note: One can also enter a Matlab expression to normalize the sorting variable explicitly (see erpimage() help). 49
Now, reselect the latency of the rt events as the trial-sorting variable (press the Epoch-sorting field button to select "latency " and press the Event type button to select "rt " ). Enter "no" under Rescale (else, reaction times would be automatically normalized).
Use the Align input to re-align the single-trial data based on the sorting variable (here the reaction time) and the change time limits. The latency value given in Align will be used for specifying time 0. To select the median of the trial-sorting values (here, median reaction time) for specifying the new time 0 (which will be at the response time minus the median reaction time), our convention is to use "Inf" the Matlab symbol for infinity in this box (as below). If you want to set a different value (for instance, while plotting an ERPimage for one subject, you might want to use the median reaction time you computed for all your subjects), simply enter the value in ms in the Align input box. Note: Temporal realignment of data epochs, relative to one another, will result in missing data at the lower-left and upper-right "corners" of the ERP image. The ERP-image function shows these as green (0) and returns these values as "NaN"s (Matlab not-a-number).
50
The ERP image figure (below) will be created. Here, the straight vertical line at time about 400 ms indicates the moment of the subject response, and the curving vertical line, the time at which the stimulus was presented in each trial. Compare the figure below with the previous non-aligned, RT-sorted ERP image.
Note just before the stimulus onset the red oblique stripe: this is produced by phase sorting: the phase (i.e., the latency of the wave peaks) is uniformly distributed across the re-sorted trials. In this computation, a 3-cycle 10 Hz wavelet was applied to a window in each trial centered at time 0. The width of the wavelet was 300 ms (i.e., three 10-Hz cycles of 100 ms). Therefore, it extended from -150 ms to 150 ms. After the wavelet was applied to each trial, the function sorted the trials in order of the phase values (-pi to pi) and displayed an ERP image of the trials in this (bottom-to-top) order. The dominance of circa 10-Hz activity in the trials , together with the 10-trial smoothing we applied makes the phase coherence between adjacent trials obvious in this view. We could have applied phase-sorting of trials using any time/frequency window. The results would depend on the strength of the selected frequency in the data, particularly on its degree of momentum (i.e., did the data exhibit long bursts at this frequency), and its phase-locking (or not) to experimental events. Phase-sorted ERP images using 52
I.8.4. Plotting ERP images with spectral options different time and frequency windows represent different paths to "fly through" complex (single-channel) EEG data. (Note: Use keyword 'showwin' to image the time window used in sorting the data for any type of data-based sorting (e.g., by phase, amplitude, or mean value). To see the phase sorting more clearly, keep the same settings, but this time enter "50" under " percent low-amp. trials to ignore". Here, the 50% of trials with smallest 10-Hz (alpha) power in the selected time window will be rejected; only the (40) others (larger-alpha 50%) will be imaged. Here (below), we can better see how the alpha wave seems to resynchronize following the stimulus. Before time 0, alpha phase is more or less random (uniformly distributed) and there is little activity in the average ERP. At about 200 ms, alpha activity seems to (partially) synchronize with the stimulus and an N300 and P400 ERP appears.
Our interpretation (above) of these trials as representing phase synchronization need not be based on visual impression alone. To statistically assess whether alpha activity is partially resynchronized by (i.e., is partly phase-reset by) the stimuli, we need to plot the phase coherence (or phase-locking factor) between the stimulus sequence and the post-stimulus data. This measure, the Inter-Trial Coherence (ITC) our terminology, takes values between 0 and 1. A value of 1 for the time frequency window of interest indicates that alpha phase (in this latency window) is constant in every trial. A value of 0 occurs when the phase values in all trials are uniformly distributed around the unit circle. In practice, values somewhat larger than 0 are expected for any finite number of randomly phase-distributed trials. Exploratory Step: Inter-Trial Coherence. To plot the ITC in our ERP-image figure, we choose to enter the following parameters in the pop_erpimage() window: we omit the " Percent low-amp. of Trials to ignore" value (or enter "0"). Under Sort trials by phase>Frequency enter "9 11" and also enter "9 11" in the " Inter-Trial Coherence>Frequency" box. Enter "0.01" under " Signif. level" and press OK. Note that these two entries must be equal (the window actually prevents the user from entering different values). Entering a frequency range instead of one frequency (e.g., 10 as before) tells erpimage() to find the data frequency with maximum power in the input data (here between 9 and 11 Hz).
53
Two additional plot panels appear below the ERP panel (uV). The middle panel, labelled ERSP for "Event Related Spectral Power", shows mean changes in power across the epochs in dB. The blue region indicates 1% confidence limits according to surrogate data drawn from random windows in the baseline. Here, power at the selected frequency (10.12 Hz) shows no significant variations across the epoch. The number "25.93 dB" in the baseline of this panel indicates the absolute baseline power level. Note: To compare results, it is sometimes useful to set this value manually in the main ERP-image pop-window. The bottom plot panel shows the event-related Inter-Trial Coherence (ITC), which indexes the degree of phase synchronization of trials relative to stimulus presentation. The value "10.12 Hz" here indicates the analysis frequency selected. Phase synchronization becomes stronger than our specified p=0.01 significance cutoff at about 300 ms. Note: The ITC significance level is typically lower when based on more trials. Moreover, ITC is usually not related to power changes.
54
I.8.4. Plotting ERP images with spectral options Discussion Point: Does the ERP here arise through partial phase synchronization or reset following stimulus onset? In a 'pure' case of (partial) phase synchronization: EEG power (at the relevant frequencies) remains constant in the post-stimulus interval. The ITC value is significant during the ERP, but less than 1 (complete phase locking). In our case, the figure (above) shows a significant post-stimulus increase in alpha ITC accompanied by a small (though non-significant) increase in alpha power. In general, an ERP could arise from partial phase synchronization of ongoing activity combined with a stimulus-related increase (or decrease) in EEG power. It is important not to overinterpret the results of phase sorting in ERP-image plots. For example, the following calls from the Matlab commandline simulate 256 1-s data epochs using Gaussian white noise, lowpass filters this below (simulated) 12 Hz, and draw the following 10-Hz phase sorted ERP-image plot of the resulting data. The figure appears to identify temporally coherent 10-Hz activity in the (actual) noise. The (middle) amplitude panel below the ERP-image plot shows, however, that amplitude at (simulated) 10 Hz does not change significantly through the (simulated) epochs, and the lowest panel shows that inter-trial coherence is also nowhere significant (as confirmed visually by the straight diagonal 10-Hz wave fronts in the center of the ERP image). % Simulate 256 1-s epochs with Gaussian noise % at 256-Hz sampling rate; lowpass < 12 Hz >> data = eegfilt(randn(1,256*256),256,0,15); % Plot ERP image, phase sorted at 10 Hz >> figure; >> erpimage(data,zeros(1,256),1:256,'Phase-sorted Noise',1,1,... 'phasesort',[128 0 10],'srate',256,... 'coher',[10 10 .01], 'erp','caxis',0.9);
Taking epochs of white noise (as above) and adding a strictly time-locked 'ERP-like' transient to each trial will give a phase-sorted ERP-image plot showing a sigmoidal, not a straight diagonal wavefront signature. How can we differentiate between the two interpretations of the same data (random EEG plus ERP versus partially phase reset EEG)? For simulated one-channel data, there is no way to do so, since both are equally valid ways of looking at the same (simulated) data - no matter how it was created. After all, the simulated data themselves do not retain any "impression" of how they were created - even if such an impression remains in the mind of the experimenter! 55
I.8.5. Plotting spectral amplitude in single trials and additional options For real data, we must use convergent evidence to bias our interpretation towards one or the other (or both) interpretations. The "partial phase resetting" model begins with the concept that the physical sources of the EEG (partial synchronized local fields) may ALSO be the sources of or contributors to average-ERP features. This supposition may be strengthened or weakened by examination of the spatial scalp distributions of the ERP features and of the EEG activity. However, here again, a simple test may not suffice since many cortical sources are likely to contribute to both EEG and averaged ERPs recorded at a single electrode (pair). An ERP feature may result from partial phase resetting of only one of the EEG sources, or it may have many contributions including truly 'ERP-like' excursions with fixed latency and polarity across trials, monopolar 'ERP-like' excursions whose latency varies across trials, and/or partial phase resetting of many EEG processes. Detailed spatiotemporal modeling of the collection of single-trial data is required to parcel out these possibilities. For further discussion of the question in the context of an actual data set, see Makeig et al. (2002). In that paper, phase resetting at alpha and theta frequencies was indicated to be the predominant cause of the recorded ERP (at least at the indicated scalp site, POz). How does the ERP in the figure above differ? The Makeig et al. paper dealt with non-target stimuli, whereas for the sample EEGLAB dataset we used epochs time locked to target stimuli from one subject (same experiment). The phase synchronization might be different for the two types of stimuli. Also, the analysis in the paper was carried out over 15 subjects and thousands of trials, whereas here we analyze only 80 trials from one subject. (The sample data we show here are used for tutorial purposes. We are now preparing a full report on the target responses in these experiments.) Note: Altogether, there are five trial sorting methods available in erpimage(): Sort by the sorting variable (default) - Sorts input data trials (epochs) by the 'sortvar,' sorting variable (for example, RT) input for each epoch of the input data. Sort by value ('valsort')- Here, trials are sorted in order of their mean value in a given time window. Use this option to sort by ERP size (option not available yet in the interactive window). Sort by amplitude ('ampsort')-- Trials are sorted in order of spectral amplitude or power at a specified frequency and time window. Use this option to display, for example, P300 responses sorted by alpha amplitude (option not available yet in the interactive window). Sort by phase ('phasesort')-- Trials are sorted in order of spectral phase in a specified time/frequency window. Do not sort ('nosort')-- Display input trials in the same order they are input.
56
In the next tutorial, we show how to use EEGLAB to perform and evaluate ICA decomposition of EEG datasets.
I.9. Independent Component Analysis of EEG data constituting a linear spatial filter). After ICA decomposition, each row of the data activation matrix gives the time course of the activity of one component process spatially filtered from the channel data. In the case of ICA decomposition, the independent component filters are chosen to produce the maximally temporally independent signals available in the channel data. These are, in effect, information sources in the data whose mixtures, via volume conduction, have been recorded at the scalp channels. The mixing process (for EEG, by volume conduction) is passive, linear, and adds no information to the data. On the contrary, it mixes and obscures the functionally distinct and independent source contributions. These information sources may represent synchronous or partialy synchronous activity within one (or possibly more) cortical patch(es), else activity from non-cortical sources (e.g., potentials induced by eyeball movements or produced by single muscle activity, line noise, etc.). The following example, from Onton and Makeig (2006), shows the diversity of source information typically contained in EEG data, and the striking ability of ICA to separate out these activities from the recorded channel mixtures.
Fifteen seconds of EEG data at 9 (of 100) scalp channels (top panel) with activities of 9 (of 100) independent components (ICs, bottom panel). While nearby electrodes (upper panel) record highly similar mixtures of brain and non-brain activities, ICA component activities (lower panel) are temporally distinct (i.e. maximally independent over time), even when their scalp maps are overlapping. Compare, for example, IC1 and IC3, accounting for different phases of eye blink artifacts produced by this subject after each visual letter presentation (grey background) and ensuing auditory performance feedback signal (colored lines). Compare, also, IC4 and IC7, which account for overlapping frontal (4-8 Hz) theta band activities appearing during a stretch of correct performance (seconds 7 through 15). Typical ECG and EMG artifact ICs are also shown, as well as overlapping posterior (8-12 Hz) alpha band bursts that appear when the subject waits for the next letter presentation (white background) For comparison, the repeated average visual evoked response of a bilateral occipital IC process (IC5) is shown (in red) on the same (relative) scale. Clearly the unaveraged activity dynamics of this IC process are not well summarized by its averaged response, a dramatic illustration of the independence of phase-locked and phase-incoherent activity.
58
ICA Algorithms: Note (above) that EEGLAB allows users to try different ICA decomposition algorithms. Only "runica", which calls runica() and "jader" which calls the function jader() (from Jean-Francois Cardoso) are a part of the default EEGLAB distribution. To use the "fastica" algorithm (Hyvarinen et al.), one must install the fastica toolbox and include it in the Matlab path. Details of how these ICA algorithms work can be found in the scientific papers of the teams that developed them. In general, the physiological significance of any differences in the results or different algorithms (or of different parameter choices in the various algorithms) have not been tested -- neither by us nor, as far as we know, by anyone else. Applied to simulated, relatively low dimensional data sets for which all the assumptions of ICA are exactly fulfilled, all three algorithms return near-equivalent components. We are satisfied that Infomax ICA (runica/binica) gives stable decompositions with up to hundreds of channels (assuming enough training data are given, see below), and therefore we can recommend its use, particularly in its faster binary form (binica()). Note about "jader": this algorithm uses 4th-order moments (whereas Infomax uses (implicitly) a combination of higher-order moments) but the storage required for all the 4th-order moments become impractical for datasets with more than ~50 channels. Note about "fastica": Using default parameters, this algorithm quickly computes individual components (one by one). However, the order of the components it finds cannot be known in advance, and performing a complete decomposition is not necessarily faster than Infomax. Thus for practical purposes its name for it should not be taken literally. Also, in our experience it may be less stable than Infomax for high-dimensional data sets. Very important note: We usually run ICA using many more trials that the sample decomposition presented here. As a general rule, finding N stable components (from N-channel data) typically requires more than kN^2 data sample points (at each channel), where N^2 is the number of weights in the unmixing matrix that ICA is trying to learn and k is a multiplier. In our experience, the value of k increases as the number of channels increases. In our example using 32 channels, we have 30800 data points , giving 30800/32^2 = 30 pts/weight points. However, to find 256 components, it appears that even 30 points per weight is not enough data. In general, it is important to give ICA as much data as possible for successful training. Can you use too much data? This would only occur when data from radically different EEG states, from different electrode placements, or containing non-stereotypic noise were concatenated, increasing the number of scalp maps associated with independent time courses and forcing ICA to mixture together dissimilar activations into the N output components. The bottom line is: ICA works best when given a large amount of basically similar and mostly clean data. When the number of channels (N) is large (>>32) then a very large amount of data may be required to find N components. When insufficient data are available, then using the 'pca' option to runica() to find fewer than N components may be the only good option. Supported Systems for binica: To use the optional (and much faster) "binica ", which calls binica() , the faster C translation of "runica()" ), you must make the location of the executable ICA file known to Matlab and executable on your system ( Note: Edit the EEGLAB icadefs() Matlab script file to specify the location of the binica() executable). The EEGLAB toolbox includes three versions of the binary executable Informax ica routine, for linux (compiled under Redhat 2.4 ), freebsd (3.0) and freebsd (4.0) (these are named, respectively ica_linux2.4 , ica_bsd3.0 and ica_bsd4.0). Note that the executable file must also be accessible through the Unix user path variable otherwise binica() won't work. Windows and sun version (older version of binary ICA executable) are available here (copy them 59
I.9.1. Running ICA decompositions to the EEGLAB directory). Please contact us to obtain the latest source code to compile it on your own system. Running " runica" produces the following text on the Matlab command line: Input data size [32,1540] = 32 channels, 1540 frames. Finding 32 ICA components using logistic ICA. Initial learning rate will be 0.001, block size 36. Learning rate will be multiplied by 0.9 whenever angledelta >= 60 deg. Training will end when wchange < 1e-06 or after 512 steps. Online bias adjustment will be used. Removing mean of each channel ... Final training data range: -145.3 to 309.344 Computing the sphering matrix... Starting weights are the identity matrix ... Sphering the data ... Beginning ICA training ... step 1 - lrate 0.001000, wchange 1.105647 step 2 - lrate 0.001000, wchange 0.670896 step 3 - lrate 0.001000, wchange 0.385967, angledelta 66.5 deg step 4 - lrate 0.000900, wchange 0.352572, angledelta 92.0 deg step 5 - lrate 0.000810, wchange 0.253948, angledelta 95.8 deg step 6 - lrate 0.000729, wchange 0.239778, angledelta 96.8 deg ... step 55 - lrate 0.000005, wchange 0.000001, angledelta 65.4 deg step 56 - lrate 0.000004, wchange 0.000001, angledelta 63.1 deg Inverting negative activations: 1 -2 -3 4 -5 6 7 8 9 10 -11 -12 -13 -14 -15 -16 17 -18 -19 -20 -21 -22 -23 24 -25 -26 -27 -28 -29 -30 31 -32 Sorting components in descending order of mean projected variance ... 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 Note that the "runica" Infomax algorithm can only select for components with a supergaussian activity distribution (i.e., more highly peaked than a Gaussian, something like an inverted T). If there is strong line noise in the data, it is preferable to enter the option " 'extended', 1 " in the command line option box, so the algorithm can also detect subgaussian sources of activity, such as line current and/or slow activity. Another option we often use is the stop option: try " 'stop', 1E-7 " to lower the criterion for stopping learning, thereby lengthening ICA training but possibly returning cleaner decompositions, particularly of high-density array data. We also recommend the use of collections of short epochs that have been carefully pruned of noisy epochs (see Rejecting artifacts with EEGLAB). In the commandline printout, the "angledelta" is the angle between the direction of the vector in weight space describing the current learning step and the direction describing the previous step. An intuitive view of the annealing angle ('angledelta') threshold (see above) is as follows: If the learning step takes the weight vector (in global weight vector space) 'past' the true or best solution point, the following step will have to 'back-track.' Therefore, the learning rate is too high (the learning steps are too big) and should be reduced. If, on the other hand, the learning rate were too low, the angle would be near 0 degrees, learning would proceed in (small) steps in the same direction, and learning would be slow. The default annealing threshold of 60 degrees was arrived at heuristically, and might not be optimum. Note: the "runica" Infomax function returns two matrices, a data sphering matrix (which is used as a linear preprocessing to ICA) and the ICA weight matrix. For more information, refer to ICA help pages (i.e. http://www.sccn.ucsd.edu/~arno/indexica.html). If you wish, the resulting decomposition (i.e., ICA weights and sphere matrices) can then be applied to longer epochs drawn from the same data, e.g. for time-frequency decompositions for which epochs of 3-sec or more may be desirable. The component order returned by runica/binica is in decreasing order of the EEG variance accounted for by each component. In other words, the lower the order of a component, the more data (neural and/or artifactual) it accounts for. In contrast to PCA, for which the first component may account for 50% of the data, the second 25%, etc..., ICA 60
I.9.2. Plotting 2-D Component Scalp Maps component contributions are much more homogeneous, ranging from roughly 5% down to ~0%. This is because PCA specifically makes each successive component account for as much as possible of the remaining activity not accounted for by previously determined components -- while ICA seeks maximally independent sources of activity. PCA components are temporally or spatially orthogonal - smaller component projections to scalp EEG data typically looking like checker boards - while ICA components of EEG data are maximally temporally independent, but spatially unconstrained -- and therefore able to find maps representing the projection of a partially synchronized domain / island / patch / region of cortex, no matter how much it may overlap the projections of other (relatively independent) EEG sources. This is useful since, apart from ideally (radially) oriented dipoles on the cortical surface (i.e., on cortical gyri, not in sulci), simple biophysics shows that the volume projection of each cortical domain must project appreciably to much of the scalp. Important note: Run twice on the same data, ICA decompositions under runica/binica will differ slightly. That is, the ordering, scalp topography and activity time courses of best-matching components may appear slightly different. This is because ICA decomposition starts with a random weight matrix (and randomly shuffles the data order in each training step), so the convergence is slightly different every time. Is this a problem? At the least, features of the decomposition that do not remain stable across decompositions of the same data should not be interpreted except as irresolvable ICA uncertainty. Differences between decompositions trained on somewhat different data subsets may have several causes. We have not yet performed such repeated decompositions and assessed their common features - though this would seem a sound approach. Instead, in our recent work we have looked for commonalities between components resulting from decompositions from different subjects.
The following topoplot() window appears, showing the scalp map projection of the selected components. Note that the scale in the following plot uses arbitrary units. The scale of the component's activity time course also uses arbitrary units. However, the component's scalpmap values multiplied by the component activity time course is in the same unit as the data.
61
Learning to recognize types of independent components may require experience. The main criteria to determine if a component is 1) cognitively related 2) a muscle artifact or 3) some other type of artifact are, first, the scalp map (as shown above), next the component time course, next the component activity power spectrum and, finally (given a dataset of event-related data epochs), the erpimage() . For example an expert eye would spot component 3 (above) as an eye artifact component (see also component activity by calling menu Plot > Component activations (scroll)). In the window above, click on scalp map number 3 to pop up a window showing it alone (as mentioned earlier, your decomposition and component ordering might be slightly different).
Note: From EEGLAB v4.32 on, if the electrode montage extends below the horizontal plane of the head center, topoplot() plots them as a 'skirt' (or halo) around the cartoon head that marks the (arc_length = 0.5) head-center plane. (Note: Usually, the best-fitting sphere is a cm or more above the plane of the nasion and ear canals). By default, all channels with location arc_lengths <= 1.0 (head bottom) are used for interpolation and are shown in the plot. From the commandline, topoplot() allows the user to specify the interpolation and plotting radii ('intrad' and 'plotrad') as well as the radius of the cartoon head ('headrad'). The 'headrad' value should normally be kept at its physiologically correct value (0.5). In 'skirt' mode (see below), the cartoon head is plotted at its normal location relative to the electrodes, the lower electrodes appearing in a 'skirt' outside the head cartoon. If you have computed an equivalent dipole model for the component map (using the DIPFIT plug-in) topoplot() can indicate the location of the component equivalent current dipole(s). Note that the 'balls' of the dipole(s) are located as if looking down from above on the transparent head. The distance of the electrode positions from the vertex, however, is proportional to their (great circle) distance on the scalp to the vertex. This keeps the electrodes on the sides of the head from being bunched together as they would be in a top-down view of their positions. This great-circle projection spreads out the positions of the lower electrodes. Thus, in the figure below, the (bottom) electrodes plotted on the lower portion of the 62
I.9.3. Plotting component headplots 'skirt' are actually located on the back of the neck. In the plot, they appear spread out, whereas in reality they are bunched on the relatively narrow neck surface. The combinations of top-down and great-circle projections allows the full component projection (or raw data scalp map) to be seen clearly, while allowing the viewer to estimate the actual 3-D locations of plot features.
The EEGLAB v4.32 topoplot() above shows an independent component whose bilateral equivalent dipole model had only 2% residual variance across all 252 electrode locations. This binica() decomposition used PCA to reduce the over 700,000 data points to 160 principal dimensions (a ratio of 28 time points per ICA weight).
63
I.9.4. Studying and removing ICA components The headplot() window below appears. You may use the Matlab rotate 3-D option to rotate these headplots with the mouse. Else, enter a different 'view' angle in the window above.
For example, click on the button labeled " 3". This component can be identified as an eye artifact for three reasons: 1) The smoothly decreasing EEG spectrum (bottom panel) is typical of an eye artifact; 2) The scalp map shows a strong far-frontal projection typical of eye artifacts; And 3) it is possible to see individual eye movements in the component 64
I.9.4. Studying and removing ICA components erpimage() (top-right panel). Eye artifacts are (nearly) always present in EEG datasets. They are usually in leading positions in the component array (because they tend to be big) and their scalp topographies (if accounting for lateral eye movements) look like component 3 or perhaps (if accounting for eye blinks) like that of component 10 (above). Component property figures can also be accessed directly by selecting Plot > Component properties . (There is an equivalent menu item for channels, Plot > Channel properties). Artifactual components are also relatively easy to identify by visual inspection of component time course (menu Plot > Component activations (scroll) (not show here)).
Since this component accounts for eye activity, we may wish to subtract it from the data before further analysis and plotting. If so, click on the bottom green " Accept" button (above) to toggle it into a red " Reject" button (note that at this point components are only marked for rejection; to subtract marked components, see next chapter I.9.5. Subtracting ICA components from data). Now press OK to go back to the main component property window. Another artifact example in our decomposition is component 32, which appears to be typical muscle artifact component. This components is spatially localized and show high power at high frequencies (20-50 Hz and above) as shown below.
65
Artifactual components often encountered (but not present in this decomposition) are single-channel (channel-pop) artifacts in which a single channel goes 'off,' or line-noise artifacts such as 23 (the ERP image plot below shows that it picked up some noise line at 60 Hz especially in trials 65 and on).
Many other components appear to be brain-related ( Note: Our sample decomposition used in this tutorial is based on clean EEG data, and may have fewer artifactual components than decompositions of some other datasets). The main criteria for recognizing brain-related components are that they have 1) dipole-like scalp maps, 2) spectral peaks at typical EEG frequence is (i.e., 'EEG-like' spectra) and, 3) regular ERP-image plots (meaning that the component does not account for activity occurring in only a few trials). The component below has a strong alpha band peak near 10 Hz and a scalp map distribution compatible with a left occipital cortex brain source. When we localize ICA sources using single-dipole or dipole-pair source localization. Many of the 'EEG-like' components can be fit with very low residual 66
I.9.5. Subtracting ICA components from data variance (e.g., under 5%). See the tutorial example for either the EEGLAB plug-in DIPFIT or for the BESA plug-in for details.
What if a component looks to be "half artifact, half brain-related"? In this case, we may ignore it, or may try running ICA decomposition again on a cleaner data subset or using other ICA training parameters. As a rule of thumb, we have learned that removing artifactual epochs containing one-of-a-kind artifacts is very useful for obtaining 'clean' ICA components. Important note: we believe an optimal strategy is to, 1) run ICA 2) reject bad epochs (see the functions we developed to detect artifactual epochs (and channels, if any) in the tutorial on artifact rejection). In some cases, we do not hesitate to remove more than 10% of the trials, even from 'relatively clean' EEG datasets. We have learned that it is often better to run this first ICA composition on very short time windows . 3) Then run ICA a second time on the 'pruned' dataset. 4) Apply the resulting ICA weights to the same dataset or to longer epochs drawn from the same original (continuous or epoched) dataset (for instance to copy ICA weights and sphere information from dataset 1 to 2. First, call menu Edit > Dataset info of dataset 2. Then enter "ALLEEG(1).icaweights" in the "ICA weight array ..." edit box, "ALLEEG(1).icasphere" in the "ICA sphere array ..." edit box, and press "OK").
A window will pop up, plotting channel ERP before (in blue) and after (in red) component(s) subtraction and asking you if you agree with the new data ERP.
67
Press Yes . A last window will pop up asking you if you want to rename the new data set. Give it a name and again press OK.
Note that storing the new dataset in Matlab memory does not automatically store it permanently on disk. To do this, select File > Save current dataset. Note that we will pursue with all components, so you can appreciate the contribution of artifactual components to the ERP. Go back to the previous dataset using the Dataset top menu. Note: If you try to run ICA on this new dataset, the number of dimensions of the data will have been reduced by the number of components subtracted. We suggest again 'baseline-zeroing' the data (if it is epoched when some components have been removed, data epoch -baseline means may change). To run ICA on the reduced dataset, use the 'pca' option under the Tools > Run ICA pop-up window, type 'pca', '10' in the Commandline options box to reduce the data dimensions to the number of remaining components (here 10), before running ICA (see runica()). If the amount of data has not changed, ICA will typically return the same (remaining) independent components -- which were, after all, already found to be maximally independent for these data.
I.9.7. Scrolling through component activations >> [ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); % copy to EEGLAB memory
Both sets of weights will then be saved when the dataset is saved, and reloaded when it is reloaded. See the script tutorial for more information about writing Matlab scripts for EEGLAB.
In the next tutorial, we show more ways to use EEGLAB to study ICA components of the data.
69
First, adjust the scale by entering "10" in the scale text edit box (lower right). Now, click on the data epochs you want to mark for rejection. For this exercise, highlight two epochs. You can then deselect the rejected epochs by clicking again on them. Press the " Reject" button when finished and enter a name for the new dataset (the same dataset minus the rejected epochs), or press the " Cancel" button to cancel the operation.
At this point, you may spend some time trying out the advanced rejection functions we developed to select and mark artifactual epochs based on ICA component maps and activations. For directions, see the Data rejection tutorial . Then, after rejecting 'bad' epochs, run ICA decomposition again. Hopefully, by doing this you may obtain a 'cleaner' decomposition. Important note: what do we mean by a cleaner ICA decomposition? ICA takes all its training data into consideration. When too many types (i.e., scalp distributions) of 'noise' - complex movement artifacts, electrode 'pops', etc -- are left in the training data, these unique/irreplicable data features will 'draw the attention' of ICA, producing a set of component maps including many single-channel or 'noisy'-appearing components. The number of components (degrees of freedom) devoted to decomposition of brain EEG alone will be correspondingly reduced. Therefore, presenting ICA with as much 'clean' EEG data as possible is the best strategy (note that blink and other stereotyped EEG artifacts do not necessarily have to be removed since they are likely to be isolated as single ICA components). Here 'clean' EEG data means data after removing noisy time segments (does not apply to removed ICA components). For this tutorial, we decide to accept our initial ICA decomposition of our data and proceed to study the nature and behavior(s) of its independent components. First, we review a series of functions whose purpose is to help us determine which components to study and how to study them.
I.10.2. Plotting component spectra and maps consider, the forth is the percentage of the data to sample at random (smaller percentages speeding the computation, larger percentages being more definitive). Since our EEG dataset is fairly small, we choose to change this value to "100" (= all of the data). We will then visualize which components contribute the most at 10 Hz, entering "10" in the " Scalp map frequency " text box. We simply scan all components, the default in " Components to consider". Press OK.
In the previous window, we plotted the spectra of each component. A more accurate strategy (for technical reasons) is to plot the data signal minus the component activity and estimate the decrease in power in comparison to the original signal at one channel (it is also possible to do it at all channel but it requires to compute the spectrum of the projection of each component at each channel which is computationally intensive). To do so, go back to the previous interactive window , choose explicitly to plot component's contribution at channel 27 (POz) where power appears to be maximum at 10 Hz using the " Electrode number to analyze ...:" field, uncheck the checkbox " [checked] compute component spectra...". Set percent to "100" as before. Finally we will display 6 component maps instead of 5 (default) (note that all component spectra will be shown) and we will set the maximum frequency to be plotted at 30 Hz using the " Plotting frequency range" option in the bottom panel (below). Press OK when done.
71
The following text is displayed Component 1 percent variance accounted for: 3.07 Component 2 percent variance accounted for: 3.60 Component 3 percent variance accounted for: -0.05 Component 4 percent variance accounted for: 5.97 Component 5 percent variance accounted for: 28.24 Component 6 percent variance accounted for: 6.15 Component 7 percent variance accounted for: 12.68 Component 8 percent variance accounted for: -0.03 Component 9 percent variance accounted for: 5.04 Component 10 percent variance accounted for: 52.08 Component 11 percent variance accounted for: 0.79 .... "Percent variance acounted for" (pvaf) compares the variance of the data MINUS the (back-projected) component to the variance of the whole data. Thus, if one component accounts for all the data, the data minus the component back-projection will be 0, and pvaf will be 100%; If the component has zero variance, it accounts for none of the data 72
I.10.3. Plotting component ERPs and pvaf = 0%. If a component somehow accounts for the NEGATIVE of the data, however, pvaf will be larger than 100% (meaning: "If you remove this component, the data actually get larger, not smaller!"). According to the variance accounted for output above, component 10 accounts for more than 50% of power at 10 Hz for channel POz. (Note: A channel number has to be entered otherwise component contributions are not computed).
The plotdata() window below pops up, showing the average ERP for all 31 components.
Click on the component-1 trace (above) to plot this trace in new window (as below).
73
As for electrodes, use menu Plot > Sum/Compare comp. ERPs to plot component ERP differences accross multiple datasets.
In the envtopo() plot (below), the black thick line indicates the data envelope (i.e. minimum and maximum of all channel at every time point) and the colored show the component ERPs.
74
The picture above looks messy, so again call the pop_envtopo() window and zoom in on time range from 200 ms to 500 ms post-stimulus, as indicated below.
We can see (below) that near 400 ms component 1 contributes most strongly to the ERP.
75
On the command line, the function also returns the percent variance accounted for by each component: IC4 pvaf: 31.10% IC2 pvaf: 25.02% IC3 pvaf: 16.92% ...
76
For component 6 (below) we observe in the erpimage() figure that phase at the analysis frequency (9Hz to 11Hz) is evenly distributed in the time window -300 to 0 ms (as indicated by the bottom trace showing the inter-trial coherence (ITC) or phase-locking factor). This component accounts for much of the EEG power at 10 Hz, but for little if any of the average ERP. Overall, mean power at the analysis frequency does not change across the epoch (middle blue trace) and phase at the analysis frequency is not reset by the stimulus (bottom blue trace). Here again, the red lines show the bootstrap significance limits (for this number of trials).
Note: As scale and polarity information is distributed in the ICA decomposition (not lost!) between the projection weights (column of the inverse weight matrix, EEG.icawinv) and rows of the component activations matrix (EEG.icaact), the absolute amplitude and polarity of component activations are meaningless and the activations have no unit of measure (through they are proportional to microvolt). To recover the absolute value and polarity of activity accounted for by one or more components at an electrode, image the back-projection of the component activation(s) at that channel. Go back to the previous ERP-image window, use the same parameters and set " Project to channel #" to 27. Note that the ERP is reversed in polarity and that absolute unit for power has changed.
77
In the next tutorial, we show how to use EEGLAB to perform and visualize time/frequency decompositions of channel activities or independent component activations.
The timef() window below appears. The top image shows mean event-related changes in spectral power (from pre-stimulus baseline) at each time during the epoch and at each frequency (< 50 Hz). To inspect these changes 78
I.11.1. Decomposing channel data more closely, click on the color image. A new window will pop up. Enabling Matlab zoom allows zooming in to any desired time/frequency window. The ERSP image shows a brief but significant decrease in power at about 370 ms at 8 Hz (click on the image to zoom in and determine the exact frequency), a power increase centered at 13.5 Hz and starting at 300 ms. More spectral changes occur at 20-28 Hz. Note that the method used to asses significance is based on random data shuffling, so the exact significance limits of these features may appear slightly different. The upper left panel shows the baseline mean power spectrum, and the lower part of the upper panel, the ERSP envelope (low and high mean dB values, relative to baseline, at each time in the epoch). The lower image shows is the Inter-Trial coherence (ITC) at all frequencies. We previously encountered the ITC when we explained the ERPimage function. A significant ITC indicates that the EEG activity at a given time and frequency in single trials becomes phase-locked (not phase-random with respect to the time-locking experimental event). Here, a significant ITC appears briefly at about 10 Hz (at about the same time as the power increase in the upper panel), but this effect might well become insignificant using a more rigorous significance threshold. Note that the time/frequency points showing significant ITC and ERSP are not necessarily identical. In this plot, ITC hardly reaches significance and cannot be interpreted. The help message for the timef() function contains information about all its parameters, the images and curve plotted, and their meanings.
79
The following timef() window appears. The ITC image (lower panel) shows strong synchronization between the component activity and stimulus appearance, first near 15 Hz then near 4 Hz. The ERSP image (upper panel) shows that the 15-Hz phase-locking is followed by a 15-Hz power increase, and that the 4-Hz phase-locking event is accompanied by, but outlasts, a 4-Hz power increase. Note that the appearance of oscillatory activity in the ERP (trace under bottom ITC image) before and after the stimulus is not significant according to ITC.
80
In the crossf() window below, the two components become synchronized (top panel) around 11.5 Hz (click on the image to zoom in). The upper panel shows the coherence magnitude (between 0 and 1, 1 representing two perfectly synchronized signals). The lower panel indicates the phase difference between the two signals at time/frequency points where cross-coherence magnitude (in the top panel) is significant. In this example, the two components are synchronized with a phase offset of about -120 degrees (this phase difference can also be plotted as latency delay in ms, using the minimum-phase assumption. See crossf() help for more details about the function parameters and the plotted variables).
One can also use Plot > Time-frequency transforms > Channel cross-coherence to plot event-related cross-coherence between a pair of scalp channels, but here relatively distant electrode channels may appear synchronized only because a large EEG source projects to both of them. Other source confounds may also affect channel coherences in unintuitive ways. Computing cross-coherences on independent data components may index transient synchronization between particular cortical domains.
I.11.4. Plotting ERSP time course and topography each part of their figures as a Matlab variable. Accumulating the ERSP and ITC images (plus the ERSP baseline and significance-level information) for all channels (e.g., via an EEGLAB script) allows use of another toolbox routine, tftopo() (currently not available from the EEGLAB menu).
82
Note on importing data from other file formats: To import continuous data from a Matlab .mat file instead from a Matlab array, scroll the list of choices in the box above that shows " Matlab .mat file ". Note: When reading a Matlab .mat file, EEGLAB assumes it contains only one Matlab variable. For reading a (32-bit) binary float-format data file, two choices are available: 'float le' ("little-endian") and 'float be' ("big-endian") The correct choice here depends on operating system. In case the bit ordering is unknown, try each of them. Note that the toolbox command line function shortread() can also be used to read data from a (16-bit) short-integer file. The resulting Matlab array may then be imported into EEGLAB as shown above. Now is a good time to add a " Description" about the dataset. A window will pop up containing a text box for this purpose. Enter as much information about the dataset as possible. The information you enter will be saved with the dataset for future reference by you or by others who may load the data. You can add to or revise these comments later by selecting menu item " Edit > Dataset info". It is also possible to save the newly created data into a new dataset, either retaining or overwriting (in Matlab process memory) the old dataset. To also save the new dataset (with all its accompanying information fields) to disk, enter a filename in the lower edit field. Press " OK" to accept.
83
II.1.1. Importing a Matlab array Then use menu item Plot > Channel data (scroll) to visualize the imported data.
Press OPEN to import a file. Then a second window pops up, press Ok.
Press OK, then select menu item Plot > Channel data (scroll) to inspect the data. A sample .BDF file is available -TEST_256.BDF (use "save link as" in your browser). (More sample files and reading functions are also available from the Biosemi ftp site). To extract event records from .BDF data, select menu item File > Import event info > From data channel as explained elsewhere in this tutorial.
84
The function pop_readegi() should be able to read EGI Version 2 and Version 3 data files. The presence of events in the EGI format is recorded in an additional EGI data channel. Information from this channel is automatically imported into the EEGLAB event table and this channel is then removed by EEGLAB from the EEGLAB data. (If, for any reason this fails to occur, extract events using menu item File > Import event info > From data channel as explained elsewhere in this tutorial.)
85
Select the file to input (after changing the filter to the correct directory if necessary), and press " OPEN". The following window will pop up:
The first input field concerns the structure of the .CNT file. If the imported data don't look like continuous EEG, try changing this number. Most often it should be 1 or 40, but other values may work. Now press " OK". A window asking for a new set name will pop up, press OK to save the new data set.
Next, use menu item Plot > Channel data (scroll) to inspect the input data and menu item Edit > Event values to inspect the input event field latencies. EEGLAB (from version 4.31) automatically reads channel labels. If you call the menu Edit > Channel locations, EEGLABn will automatically find the location of most channels (based on channel labels). We will now illustrate how to import additional epoch event information contained in an accompanying Neuroscan .DAT file into the EEGLAB dataset. Before importing the .DAT file, you must first epoch the loaded data (i.e., you must separate it into data epochs). To epoch the data, select Tools > Extract epochs
86
Simply press " OK" to epoch the data based on the events contained in the .CNT file (here using a time window extending from -1 s before to 2 s after events). The following window will appear:
Use this window to enter description and save the new dataset. For computers with limited memory (RAM), try overwriting the parent dataset (here, the continuous dataset we have just imported) by checking the "Overwrite parent" box in this window. One may also save the dataset to disk. Press " OK" when done. The following baselind removel window will pop up:
Simply press " OK" and continue. Data epochs have now been extracted from the EEG data.
In .DAT files, there must be a reaction time (in milliseconds) for each epoch. However, depending on experiment design there may be no reaction time in a given epoch. Then one has to use a code value for reaction time latencies in these epochs. For instance, you might decide that a value of "1000" (ms) would indicate that the subject did not respond. (If all the epochs of the experiment already have a reaction time, do not enter anything here.) 87
A window will pop up to ask for a file name. Then select menu item Plot > Channel data (scroll) to inspect the data and item Edit > Event values to inspect event latencies and types. A sample .SMA data file is available -TEST.SMA (use "save link as" in your browser).
88
Enter "33" as the event channel and set the edge-extract type to "up (leading)" ( Note: place the mouse over the text " Transitions to extract" to see contextual help). Press " OK". Now, the event information will have been imported into the test EEGLAB dataset. At the same time, channel 33 will have been deleted from the test data. Select menu item Edit > Event values to inspect the imported event types and latencies.
II.2.2. Importing events from a Matlab array or text file 3 4.7707 5 6.5979 ... Select menu item File > Import event info > Import Matlab array or ASCII file target response target response 2 2 1 1
Browse for the tutorial text file, set the number of header lines to 1 (for the first line of the file, which gives the column field names) and set the input fields (i.e., the names associated with the columns in the array) to "latency type position". If these field names are quoted or separated by commas, these extra characters are ignored. NOTE: It is NECESSARY to use the names "latency" and "type" for two of the fields. These two field names are used by EEGLAB to extract, sort and display events. These fields must be lowercase since Matlab is case sensitive. In this interactive window the input " Event indices" and checkbox " Append events?" can be used to insert new events or replace a subset of events with new events (for instance for large EEG files which may have several event files). Important note about aligning events An essential input above is " Align event latencies to data events" which aligns the first event latency to the existing event latency and checks latency consistency. A value of NaN (Matlab for not-a-number) indicates that this option is ignored (as in the example above). However, for most EEG data, the EEG is recorded with basic events stored in an event channel (see Import events from a data channel above) for instance. Detailed event information is recorded separately in a text file: as a consequence the events recorded in the text file have to be aligned with the events recorded in the EEG. To do so, set the input for " Align event latencies to data events " to 0 if the first event in the text file correspond to the first event recorded in the EEG (i.e., if the offset between the two is 0). Setting this value to 1 indicates that event 1 in the event text file corresponds to event number 2 in the EEG data. Here, negative values can also be used to indicate that events in text file start before those recorded in the EEG). When aligning events, as shown in the following section, the function displays the latencies of the two event types, so the user can check that they are aligned based on his knowledge of the experiment (for instance, there may be more events in the text file than recorded in the EEG). The last checkbox allow to automatically adjust the sampling rate of the new events so they best align with the closest old event. This may take into account small differences in sampling rates that could lead to big differences by the end of the experiment (e.g., a 0.01% clock difference during would lead to a 360-ms difference after one hour if not corrected).
90
Scroll file fields to select which field (i.e., file column) contain the event type and which column contain the event latency. The default is fine with this specific file, so simply press OK. Matlab then returns Replacing field 'Event Type' by 'type' for EEGLAB compatibility Replacing field 'Time' by 'latency' for EEGLAB compatibility Renaming second 'Uncertainty' field Reading file (lines): 6 Check alignment between pre-existing (old) and loaded event latencies: Old event latencies (10 first): 10789 21315 31375 41902 51962 62489 ... New event latencies (10 first): 10789 21315 31376 41902 51963 62489 ... Best sampling rate ratio found is 0.9999895. Below latencies after adjustment Old event latencies (10 first): 10789 21315 31376 41902 51963 62488 ... New event latencies (10 first): 10789 21315 31375 41902 51962 62489 ... 91
II.3. Importing sets of single-trial EEG epochs into EEGLAB Pop_importevent warning: 0/6 have no latency and were removed eeg_checkset: value format of event field 'Duration' made uniform eeg_checkset: value format of event field 'Uncertainty2' made uniform eeg_checkset note: creating the original event table (EEG.urevent) Done. The function aligs the first event latency recorded in the Presentation file to the first event latency recorded in the EEG in the SnapMaster file. Check that the events recorded in the SnapMaster file have the same latencies as the ones recorded in the .LOG presentation file. The function then computes the best sampling rate ratio: this may account for small differences in sampling rate that could lead to big differences at the end of the experiement (e.g., 0.01% clock difference during half an hour would lead to a 360-ms difference after one hour if not corrected). Note that if the events are shifted (with respect to events from the binary EEG file), it is always possible to suppress events manually or to import the presentation file as a text file, as described in the previous section. Note that some Presentation files that contain comments at the end of the file may not be supported. If you are not able to import a Presentation file, try removing any comments from the end of the file. If it still does not work, try importing the Presentation file as a text file as described in the previous section.
Then select menu item Plot > EEG data (scroll) to inspect the imported data. In this case, epoch events have also been imported from the file and can be visualized using menu item Edit > Event values.
II.3.3. Importing epoch info Matlab array or text file into EEGLAB
Importing epoch information means that data epochs have already been extracted from the continuous EEG data, and that the Matlab array or text epoch information file has one entry per epoch. To illustrate how to import such a file or array, we will once more create some simulated EEG data. >> eegdata = rand(32, 256, 10); % 32 channels, 256 time points per epoch, 10 epochs
Select menu item File > Import data > From ascii/float data file or Matlab array.
92
II.3.3. Importing epoch info Matlab array or text file into EEGLAB
Press " OK" in this window (Note: If you select a data importing format different from "Matlab variable", be sure to click on it to actually select the option). Then, a second window will pop up.
Press " OK" in this window (see importing a Matlab array at the beginning of this page for more information). Note that the Matlab array, being 3-D, is automatically imported as data epochs: the first dimension is interpreted as data channels, the second as data points and the third as data epochs or trials (e.g., our sample data matrix above contains 10 epochs). Let us imagine that our simulated EEG data came from a simple stimulus/response task, with subject responses being either "correct" or "wrong" and response latencies recorded in milliseconds. Then the epoch event file might look something like this:
93
II.3.3. Importing epoch info Matlab array or text file into EEGLAB Epoch Response Response_latency 1 2 3 4 5 6 7 8 9 10 Correct Correct Correct Correct Wrong Correct Correct Correct Correct Correct 502 477 553 612 430 525 498 601 398 573
This file tutorial_epoch.txt can be downloaded or copied from the array above in a text file. Then select menu item File > Import epoch info > from Matlab array or ascii file, bringing up the following window:
Above, browse for the "tutorial_epoch.txt" file, set the input fields to "epoch response rt" (where rt is an acronym for "reaction time"). The only one of these fields that contains latency information is "rt", so it is entered to the as input to the " Field name(s) containing latencies" query box. This file (see above) has 1 header line, as we need to specify in the " Number of file header lines to ignore" box. Finally the reaction times are recorded in milliseconds, which we indicate as "1E-3" (i.e., one-thousandth of a second). Note that the last entry, " Remove old epoch ...", allows the user to import other information later if it is unset. Press " OK" when done. Now select Edit > Event fields.
It is a good idea to click each of the "Field description" buttons above to add detailed descriptions of the meaning of each of the fields and the coding of the field values (for example: 1 = correct, 2 = wrong, etc.). This information is stored along with the event field values when the dataset is saved (very useful for later analysis by you or others!). 94
II.4. Importing sets of data averages into EEGLAB Above, there are now five fields, not three as for the file data. Also note that the field "rt" is not present. All of this is normal because EEGLAB does not store epoch information as such, but converts it into fields in its events structure. Though this seems a bit complicated in the beginning, it helps avoid redundancy and inconsistencies between epoch and event information. It also means that new data epochs can be re-extracted from data epochs based on the stored events. Now select menu item Edit > Event values to inspect what happened to the reaction time information (use the arrow to move to the second event):
As shown above, when epoch information was imported, events with type named rt were created and assigned a latency. If we had had several columns containing latency information, the function would have created several types. (Programming note: For convenience, standard epoch information is available from the command line in the variable EEG.epoch. Also, event information available in EEG.event can be used for script or command line data processing. See the script writing tutorial for more information.)
II.4.2. Concatenating data averages For instance typing >> whos under Matlab might return Name Size Bytes Class avgcond1 31x600 14880 double array avgcond2 31x600 14880 double array avgcond3 31x600 14880 double array Grand total is 55800 elements using 446400 bytes Note: If necessary, transpose the arrays (so rows=channels, colunmns=data sampels, i.e. chan*samp) like this (not necessary for this example) >>avgcond1 = avgcond1'; Then concatenate the arrays >> allcond = [ avgcond1 avgcond2 avgcond3 ] ;
Enter the information as indicated above. The following window pops up and allows you to add comments and/or save the new dataset immediately. Press OK to create a new dataset.
Select Plot > Channel ERPs> in rect. array and set the last option Plot single trials to YES to visualize the three condition ERPs.
96
It is possible to process the three average-ERP epochs as if they were single-trial epochs (although in this case some EEGLAB functions may not be meaningful). See the Data analysis tutorial for more information.
-1000.0000 -992.1880 -984.3761 -976.5641 -968.7521 -960.9402 -953.1282 -945.3162 -937.5043 -929.6923 -921.8803 -914.0684 -906.2564 -898.4444 -890.6325 -882.8205 -875.0085 -867.1966 -859.3846 -851.5726 -843.7607 -835.9487 -828.1367 -820.3248 -812.5128 -804.7009 ...
97
II.5.1. Exporting data to an ASCII text file The first column contains the time axis and the other the data for each electrode. This file might, for example, be imported into SPSS or BMDP.
The text file on disk then contains the weight matrix. It may be re-imported into another EEGLAB dataset using menu item Edit > Dataset info. As shown below, enter the filename in the ICA weight array edit box. Leave the sphere edit box empty, or empty it if it is not empty. See the ICA decomposition tutorial for more details on sphere and weight matrices.
98
99
Note: to select portions of data that extend out of the plotting window, simply drag the mouse over the new region and connect it to a previously marked region. For instance, in the following plotting window which already had the time interval 2.1 seconds to 3.4 seconds selected (as shown above), drag the mouse from 6.9 seconds back to 4.7.
100
Some estimated variables of the statistics are printed as text in the lower panel to facilitate graphical analysis and interpretation. These variables are the signal mean, standard deviation, skewness, and kurtosis (technically called the 4 first cumulants of the distribution) as well as the median. The last text output displays the Kolmogorov-Smirnov test result (estimating whether the data distribution is Gaussian or not) at a significance level of p=0.05. The upper left panel shows the data histogram (blue bars), a vertical red line indicating the data mean, a fitted normal distribution (light blue curve) and a normal distribution fitted to the trimmed data (yellow curve). The P and 1-P percentile points are marked with yellow ticks on the X axis. A horizontal notched-box plot with whiskers is drawn below the histogram. The box has lines at the lower quartile (25th-percentile), median, and upper quartile 101
III.2. Rejecting artifacts in epoched data (75th-percentile) values. The whiskers are lines extending from each end of the box to show the extent of the rest of the data. The whisker extends to the most extreme data value within 1.5 times the width of the box. Outliers ('+') are data with values beyond the ends of the whiskers. The upper right panel shows the empirical quantile-quantile plot (QQ-plot). Plotted are the quantiles of the data versus the quantiles of a Standard Normal (i.e., Gaussian) distribution. The QQ-plot visually helps to determine whether the data sample is drawn from a Normal distribution. If the data samples do come from a Normal distribution (same shape), even if the distribution is shifted and re-scaled from the standard normal distribution (different location and scale parameters), the plot will be linear. Empirically, 'bad' channels have distributions of potential values that are further away from a Gaussian distribution than other scalp channels. For example, plotting the statistics of periocular (eye) Channel 1 below, we can see that it is further away from a normal distribution than Channel 10 above. (However, Channel 1 should not itself be considered a 'bad' channel since ICA can extract the eye movement artifacts from it, making the remained data from this channel usable for futher analysis of neural EEG sources that project to the face). The function plotting data statistics may provide an objective measure for removing a data channel. Select menu item Tools > Select data to remove one or more data channels. It is also possible to plot event statistics from the EEGLAB menu -- see the EEGLAB event tutorial for details.
Note that the function above may also be used to detect bad channels in non-continuous (epoched) data.
102
III.2.1. Rejecting epochs by visual inspection >> EEG = pop_eegfilt( EEG, 1, 0, [], [0]);% Highpass filter cutoff freq. 1Hz. >> [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, 'setname', ... 'Continuous EEG Data'); % Save as new dataset. >> EEG = pop_reref( EEG, [], 'refstate',0); % Re-reference the data >> EEG = pop_epoch( EEG, { 'square' }, [-1 2], 'newname', 'Continuous EEG Data epochs', 'epochinfo', 'yes'); % Epoch dataset using 'square' events. >>EEG = pop_rmbase( EEG, [-1000 0]); % remove baseline >> [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, 'setname', ... 'Continuous EEG Data epochs', 'overwrite', 'on'); % save dataset >>[ALLEEG EEG] = eeg_store(ALLEEG, EEG, CURRENTSET); % store dataset >> eeglab redraw % redraw eeglab to show the new epoched dataset After having an epoched dataset, call the main window for epoched data rejection, select Tools > Reject data epochs > Reject data (all methods). The window below will pop up. We will describe the fields of this window in top-to-bottom order. First, change the bottom multiple choice button reading " Show all trials marked for rejection by the measure selected above or checked below" to the first option, " Show only the new trials marked for rejection by the measure selected above". We will come back to the default option at the end.
III.2.2. Rejecting extreme values on them. Rejecting parts of an epoch is not possible.
Marked trials are highlighted in the eegplot() window (below) that then pops up. Now epochs marked for rejection may be un-marked manually simply by clicking on them. Note that the activity at some electrodes is shown in red, indicating the electrodes in which the outlier values were found. Press "Update Marks" to confirm the epoch markings.
104
At this point, a warning will pop up indicating that the marked epochs have not yet been rejected and are simply marked for rejection. When seeing this warning, press "OK" to return to main rejection window.
Also note that several thresholds may be entered along with separate applicable time windows. In the following case, in addition to the preceding rejection, additional epochs in which EEG potentials went above 25 V or below -25 V during the -500 to 0 ms interval will be marked for rejection.
III.2.4. Rejecting improbable data fit value might be 0 v at the beginning of the trial and 50 v at the end). The minimal fit between the EEG data and a line of minimal slope is determined using a standard R-square measure. To test this, in the main rejection window enter the following data under find abnormal trends (which calls function pop_rejtrend()), and press "CALC/PLOT".
The following window will pop up. Note that in our example the values we entered are clearly too low (otherwise we could not detect any linear drifts in in this clean EEG dataset). Electrodes triggering the rejection are again indicated in red. To deselect epochs for rejection, click on them. To close the scrolling window, press the "Update marks" button.
Note: Calling this function (pop_rejtrend()) either directly from the command line, or by selecting Tools > Reject data epochs > Reject flat line data, allows specifying additional parameters.
III.2.4. Rejecting improbable data improbable data press "Calculate" (which calls function pop_jointprob()), and then press "PLOT".
The first time this function is run on a dataset, its computation may take some time. However the trial probability distributions will be stored for future calls. The following display shows the probability measure value for every trial and electrode (each number at the bottom shows an electrode, the blue traces the trial values). On the right, the panel containing the green lines shows the probability measure over all the electrodes. Rejection is carried out using both single- and all-channel thresholds. To disable one of these, simply raise its limit (e.g. to 15 std.). The probability limits may be changed in the window below (for example, to 3 standard deviations). The horizontal red lines shift as limit values are then modified. Note that if you change the threshold in the window below the edit boxes in the main window will be automatically updated (after pressing the "UPDATE" button).
It is also possible to look in detail at the trial probability measure for each electrode by clicking on its sub-axis plot in the above window. For instance, by clicking on electrode number two on the plot, the following window would pop up (from left to right, the first plot is the ERPimage of the square values of EEG data for each trial, the second plot indicates which trials were labeled for rejection (all electrodes combined) and the last plot is the original probability measure plot for this electrode with limits indicated in red).
107
Close this window and press the "UPDATE" button in the probability plot window to add to the list of trials marked for rejection. Now press the "Scroll data" button to obtain the standard scrolling data window. Inspect the trials marked for rejection, make any adjustments manually, then close the window by pressing "UPDATE MARKS".
III.2.6. Rejecting abnormal spectra activity distribution. Once more, single- and all-channel thresholds are defined in terms of standard deviations from mean kurtosis value. For example, enter the following parameters under find abnormal distribution press "Calculate" (which calls function pop_rejkurt()), then press "PLOT".
In the main rejection window note that the Currently marked trials field have changed to 5. In the plot figure all trials above the threshold (red line) are marked for rejection, note that there are more than 5 such lines. The figure presents all channels, and the same trial can exceed the threshold several times in different channles, and therefore there are more lines than marked trials.
As with probability rejection, these limits may be updated in the pop-up window below, and pressing "Scroll data" in the main rejection window (above) brings up the standard data scrolling window display which may be used to manually adjust the list of epochs marked for rejection.
109
Computing the data spectrum for every data epoch and channel may take a while. We use a frequency decomposition based on the slepian multitaper (Matlab pmtm() function) to obtain more accurate spectra than using standard Fourier transforms. After computing the trial spectra, the function removes the average power spectrum from each trial spectrum and tests whether the remaining spectral differences exceed the selected thresholds. Here, two windows pop up (as below), the top window being slaved to the bottom. The top window shows the data epochs and the bottom window the power spectra of the same epochs. When scrolling through the trial spectra, the user may use the top window to check what caused a data trial to be labeled as a spectral outlier. After further updating the list of marked trials, close both windows by pressing "UPDATE MARKS" in the bottom window.
110
As with standard rejection of extreme values, several frequency thresholding windows may be defined. In the window below, we specify that the trial spectra should again not deviate from the mean by +/-50 dB in the 0-2 Hz frequency window (good for catching eye movements) and should not deviate by +25 or -100 dB in the 20-40 Hz frequency window (useful for detecting muscle activity).
The scrolling window appears and now shows that at trials 11 & 12 the blue window is actually divided into two, with dark blue on the top and light blue on the bottom. Dark blue indicates that the trial is currently marked as rejected. The 111
III.2.8. Inspecting results of all rejection measures light blue indicates that the trial was already rejected using the previous rejection threshold.
Note that pressing "UPDATE MARKS" only updates the currently rejected trials and optional visual adjustments. Previously rejected trials are ignored and can not be removed manually in the plot window.
112
When visually modifying the set of trials labeled for rejection in the window above, all the current rejection measure are affected and are reflected in the main rejection window after you press the "UPDATE MARKS" button.
III.3. Rejection based on independent data components (all methods). We suggest that the analysis be done iteratively in the following seven steps: 1. Visually reject unsuitable (e.g. paroxysmal) portions of the continuous data. 2. Separate the data into suitable short data epochs. 3. Perform ICA on these epochs to derive their independent components. 4. Perform semi-automated and visual-inspection based rejection on the derived components.* 5. Visually inspect and select data epochs for rejection. 6. Reject the selected components and data epochs. 7. Perform ICA a second time on the pruned collection of short data epochs -- This may improve the quality of the ICA decomposition, revealing more independent components accounting for neural, as opposed to mixed artifactual activity. If desired, the ICA unmixing and sphere matrices may then be applied to (longer) data epochs from the same continuous data. Longer data epochs are useful for time/frequency analysis, and may be desirable for tracking other slow dynamic features. *Note: After closing the main ICA rejection window, select Tools > Reject data using ICA > Export marks to data rejection and then Tools > Reject data epochs > Reject by inspection to visualize data epochs marked for rejection using ICA component activities.
'
114
You may refer at any time to Appendix A1. EEGLAB Data Structures for a more complete description of the EEG structure.
115
Clicking "Save" in the window above will cause the command history to be saved into the Matlab script file "doitagain.m" (you can choose any name for this file, as long as it ends in the standard Matlab script file extension, ".m"). Note: when the file was saved, an extra command, " >> eeglab redraw " was added at the end to insure that the main graphic interface would be updated after the dataset was processed. Now, to process another dataset using the same commands you used for processing the current dataset, try closing the current Matlab session, restart Matlab then EEGLAB, reload a different dataset and run the script saved above by typing >> doitagain 116
IV.2.2. EEGLAB pop_ functions Most of the commands in the history field call EEGLAB "pop_" functions. These are functions that take as input the EEG structure. The next sub-section discusses how to use these functions in EEGLAB scripts.
IV.2.3. Script examples using dataset history output variables). For example, the pop_erpimage() function returns the same outputs as the erpimage() function: >> figure; [outdata, outvar, outtrials] = pop_erpimage(EEG,1,12); % ERP-image plot of channel 12 % or the equivalent non-pop function call >> figure; [outdata, outvar, outtrials] = erpimage( EEG.data(12,:), zeros(1,EEG.trials), EEG.times, '', 10, 1, 'nosort') Important note: If pop_[funcname]() is a plotting function, then a new figure is created automatically only when the function is called in pop-up window mode. Otherwise, pop_[funcname]() plotting commands (as well as all non-pop plotting commands, except eegplot()) should be preceded by a Matlab " figure; " command, as in the example above (Note: the " figure;" is added before the command by the EEGLAB history mechanism). This feature allows you to create compound figures using Matlab subplot() or the more flexible EEGLAB version sbplot().
IV.2.4. Updating the EEGLAB window At this point you may want to save all the modified datasets to the computer. You may also use menu File > Save history > Dataset history to save the current dataset history ( EEG.history field) into a Matlab script file and recall this Matlab script from the command line as described in the previous sub-section. Note: EEGLAB loading dataset commands (menus File > Load dataset) are not stored in the dataset history. The reason for this is that if you were to load a dataset repeatedly, you would not want the repeated load command to be in your dataset history. More advanced scripting examples will be presented in the following sections.
Whenever you wish to switch back from interacting with the EEG dataset on the command line to working with the EEGLAB graphic interface, you should perform one of the two commands below: 1. If no EEGLAB window is running in the background, type: >> eeglab redraw; 2. If there is an open EEGLAB session, first type: >> [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG); to save the modified information, and then: >> eeglab redraw; to see the changes reflected in the EEGLAB window. To learn more about scripting and EEGLAB data structures see the next section IV.3.3.
IV.3. Using EEGLAB session history to perform basic EEGLAB script writing
There are two main EEGLAB Matlab data structures, ' EEG' and ' ALLEEG'. The ALLEEG array contains all the dataset structures that currently loaded in the EEGLAB session. The EEG structures contains all the information about the current dataset being processed. There are two main differences between EEGLAB dataset history and session history. As the names imply, session history saves all the function calls issued for all the datasets in the current EEGLAB session, while dataset history saves only the function calls that modified the current dataset. Session history is available only during the current session of EEGLAB -- starting a new EEGLAB session will create a new session history -- whereas dataset history is saved in the " EEG.history" field of the EEG dataset structure when you save the dataset at the end of the 119
IV.3. Using EEGLAB session history to perform basic EEGLAB script writing session. It therefore will be retrieved when the dataset is re-loaded in future EEGLAB sessions (assuming, of course, that you save the dataset at the end of the current session!). EEGLAB session history allows you to manipulate and process several datasets simultaneously. Thus, its use can be considered the next level of EEGLAB scripting.
120
Clicking "Save" in the window above will cause the session command history to be saved into the Matlab script file "eeglabhist.m" (you can choose any name for this file, as long as it ends in the standard Matlab script file extension, ".m"). Now try closing the current Matlab session, restarting Matlab, and running the script saved above by typing >> eeglabhist The main EEGLAB window is created and the same dataset is loaded. Now open the script file "eeglabhist.m" in any text editor so you may modify function calls. Note: as for the dataset history, when the file was saved, an extra command, " >> eeglab redraw " was added at the end to insure that the main graphic interface would be updated after the dataset was (re)loaded.
121
IV.3.2. Script example using session history EEG.chanlocs=pop_chanedit(EEG.chanlocs, { 'load', '/home/payton/ee114/chan32.locs'},{ 'convert',{ 'topo2sph', 'gui'}},{ 'convert',{ 'sph2cart', 'gui'}}); % read the channel location file and edit the channel location information figure; pop_spectopo(EEG, 0, [-1000 237288.3983] , 'percent', 20, 'freq', [10], 'icacomps', [1:0],'electrodes','off'); % plot RMS power spectra of the ICA component activations; show a scalp map of total power at 10 Hz plus maps of the components contributing most power at the same frequency Important note: As briefly mentioned previously, functions called from the main EEGLAB interactive window display the name of the underlying pop_function in the window title bar. For instance, selecting File > Load an existing dataset to read in an existing dataset uses EEGLAB function " pop_loadset()".
The next steps in learning to write EEGLAB Matlab scripts involve learning to change EEGLAB function parameters and adding loops to perform multiple analyses.
122
IV.3.3. Scripting at the EEGLAB structure level or >> [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG); to create a new dataset at the next available free space in the ALLEEG variable. The dataset number will then be available in the variable CURRENTSET. Note that if a previous dataset is already assigned as dataset 2, then only the last command (above) will not overwrite it. To view the changes in the main EEGLAB window, use the command: >> eeglab redraw; Another command that can be used to modify the ALLEEG structure is pop_newset(). This command, which also performs extensive dataset consistency checks, has more useful advanced options. To modify the current dataset with its accumulated changes type: [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET, 'overwrite', 'on'); If you wish to create a new dataset to hold the modified structure use: [ALLEEG EEG CURRENTSET] = pop_newset(ALLEEG, EEG, CURRENTSET); The returned argument CURRENTSET holds the set number of the new dataset stored in EEGLAB. Note the EEG contains only the current dataset, so you must use extra caution whenever updating this structure. e.g., Be sure it contains the dataset you actually want to process! The functions above call the function eeg_checkset() to check the internal consistency of the modified dataset. >> EEG = eeg_checkset(EEG); or >> EEG = eeg_checkset(EEG, 'eventconsistency'); The second command above runs extra checks for event consistency (possibly taking some time to complete) and regenerates the EEG.epoch structures from the EEG.event information. This command is only used when the event structure is being altered. See the Event tutorial to learn how to work with EEG events. The commands above are very useful if the option to maintain multiple datasets is on. If the option to maintain multiple datasets is off (via the File > Maximize Memory menu item), the ALLEEG variable is not used and EEG is the only variable that contains dataset information. When using this option you can only process one dataset at a time (the goal here is to use less memory and being able to process bigger datasets). Any changes made by the user to the EEG structure are thus applied instantaneously and are irreversible. For consistency, all the commands above will work, however the ALLEEG variable will be empty. 2) New fields added to the EEG structure by users will not be removed by EEGLAB functions. For instance, any additional information about a dataset might be stored in the user-added field: >> EEG.analysis_priority = 1; 3) The following are the reserved variable names used by EEGLAB EEG - the current EEG dataset ALLEEG - all the EEG datasets CURRENTSET - the index of the current dataset. Thus >> EEG = ALLEEG(CURRENTSET); LASTCOM - the last command used ALLCOM - Matlab commands issued from the EEGLAB menu during this EEGLAB session Note that EEGLAB does not use global variables (the variables above are accessible from the command line but they are not used as global variables within EEGLAB). The above variables are ordinary variables in the global Matlab 123
IV.4. Basic scripting examples workspace. All EEGLAB functions except the main interactive window function eeglab() (and a few other display functions) process one or more of these variables explicitly as input parameters and do not access or modify any global variable. This insures that they have a minimum chance of producing unwanted 'side effects' on the dataset.
IV.5. Low level scripting [0:100:500], %with the plot title - 'ERP image', in 2 rows and 3 columns. Below, the 0 means do not plot dipoles. %Plot marks showing the locations of the electrodes on the scalp maps. pop_topoplot(EEG,1, [0:100:500] , 'ERP image',[2:3] ,0, 'electrodes', 'on'); In the next section, we will directly call some lower-level EEGLAB data processing functions. For instance, the command above can be executed by directly calling the signal processing function topoplot() as shown below. times = [0:100:500]; % Define variables: pos = eeg_lat2point(times/1000, 1, EEG.srate, [EEG.xmin EEG.xmax]); % Convert times to points (or >pos = round( (times/1000-EEG.xmin)/(EEG.xmax-EEG.xmin) * (EEG.pnts-1))+1;) % See the event tutorial for more information on processing latencies mean_data = mean(EEG.data(:,pos,:),3); % Average over all trials in the desired time window (the third dimension of EEG.data % allows to access different data trials). See appendix A1 for more information maxlim = max(mean_data(:)); minlim = min(mean_data(:)); % Get the data range for scaling the map colors. maplimits = [ -max(maxlim, -minlim) max(maxlim, -minlim)]; % Plot the scalp map series. figure for k = 1:6 sbplot(2,3,k); % A more flexible version of subplot. topoplot( mean_data(:,k), EEG.chanlocs, 'maplimits', maplimits, 'electrodes', 'on', 'style', 'both'); title([ num2str(times(k)) ' ms']); end cbar; % A more flexible version of colorbar.
IV.5.1. Example script for processing multiple datasets function documentation is supposed to describe function output in all possible situation, occasionally users may need to look in the function script files themselves to see exactly how data processing is performed. Since EEGLAB functions are open source, this is always possible.
126
IV.5.2. Example script performing time-frequency decompositions on all electrodes end % End subject eeglab redraw % Update the main EEGLAB window Repetitive processes, such as the computation performed above, may be time consuming to perform by hand if there are many epochs in each dataset and many datasets. Therefore it may be best performed by an EEGLAB Matlab script that is left to run until finished in a Matlab session. Writing scripts using EEGLAB functions makes keeping track of data parameters and events relatively easy, while maintaining access to the flexibility and power of the Matlab signal processing and graphics environment. Notes: Normally, the user might want to accumulate and save the ERSPs and other output variables returned by timef() above to make possible further quantitative comparisons between subjects. The function described in the next paragraph tftopo() allows the user to combine ERSP outputs from different subjects and apply binary statistics. In the current version of EEGLAB, the cross-coherence function crossf() can calculate significance of differences between coherences in two conditions. In the future, timef() will be extended to allow comparisons between multiple ERSP and ITC transforms directly. The same type of iterative normalization (illustrated above) may be applied for the "baseamp" parameter returned by pop_erpimage()
127
IV.5.3. Creating a scalp map animation Executing the following code on the tutorial dataset (after highpass filtering it above 1 Hz, extracted data epochs, and removing baseline), produces the following figure.
128
The "type" and "latency" fields are the most important EEGLAB event fields (see below). Some EEGLAB functions recognize and use these two fields for plotting events, sorting trials, etc. (Note: One can also process events lacking these fields, though this strongly limits the range of event processing possibilities). Other fields, including "epoch", "duration", "urevent", are also recognized by EEGLAB (they are created automatically during extracting of epochs, rejecting data, or storing event data). User-defined fields can have any other name that is relevant to the data (for example, "position" in the example above). A short description of recognized event fields is given below. Further information can be found in the event scripting section in the next sections. type - specifies the type of the event. For example, 'square' in the example above is a stimulus type, 'rt' is a subject button-press (i.e., reaction-time) event, etc... In continuous datasets, EEGLAB may add events of type 'boundary' to specify data boundaries (breaks in the continuous data). The next section on event scripting provides more detailed information about this special event type. latency - contains event latencies. The latency information is displayed in seconds for continuous 129
V.1.1. Event fields data, or in milliseconds relative to the epoch's time-locking event for epoched data. As we will see in the event scripting section, the latency information is stored internaly in data samples (points or EEGLAB 'pnts') relative to the beginning of the continuous data matrix (EEG.data). duration - duration of the event. This information is displayed in seconds for continuous data, and in milliseconds for epoched data. Internally, duration is (also) stored in data samples (pnts). urevent - contains indices of events in the original ('ur' in German) event structure. The first time events are imported, they are copied into a separate structure called the 'urevent' structure. This field is hidden in the graphic interface (above) since they should not be casually modified. epoch - indices of the data epochs (if any) the event falls within. Note: all event fields may contain either numbers or strings (except for latency, duration, urevent and epoch which must contain numbers). For instance, the type field can contain a number (i.e. 1,2, etc.) or a string (i.e. 'square', 'rt', etc.). However, EEGLAB cannot process a mixture of both formats (numeric and string) for one field. A function that checks the event structure (eeg_checkset() with flag "eventconsistency"), called each time a dataset is modified, enforces each field's contents to remain consistent, automatically converting numeric values to strings if necessary. This constraint was imposed to speed up event manipulation by a factor of about 1000X.
After you press OK, the events may be resorted (events must always be in order of increasing latency), and some field contents may be modified to ensure consistency, as indicated at the end of the previous section. In the graphic interface above, all experimental events can be manually modified by simply typing the new values in the edit window for each field. Events may also be deleted (Delete event button) or resorted (see the bottom part of 130
V.1.2. Importing, adding, and modifying events the window). Resorting events is only for viewing purposes (as EEGLAB cannot process an event structure that is not sorted by increasing event latency). Another way to insert new events is to select menu item Edit > Event fields as shown below. Through its graphic interface, you may add new fields and import Matlab arrays or text files to fill them. For instance, to add a test field containing only "0"s, enter "test" in the edit box of the "Edit field" column. Then enter "0" in the "file/array" column and press OK. Using this window, you may also delete event fields (last column) or rename them (window bottom). Finally you may change the description of event fields by clicking on buttons in the "Field description" column. (Note: It is efficient to enter event field description information in the first dataset you create for an experiment, and then to copy this information to subsequent datasets from the same experiment. Entering event field descriptions will allow you or others who may explore the same data later (perhaps when new analysis tools become available or of interest) to quickly grasp the meaning of the event information.
131
This operation will extract epochs of duration one second before to two seconds after all events of type "square". 2. Events can also be used for making ERP-image plots. Select Plot > Channel ERP image. This brings up the pop_erpimage() window (below).
132
The "Epoch-sorting field" button allows you to choose any of the event fields as the sorting criteria. The next button, "Event type(s)", enables you to choose only a subset of events. In this example, events of type "square" are sorted by their position field value. For more details see I.8.2. Plotting ERP images . 3. Event statistics can be plotted with regard to different event fields. For example, selecting menu option Plot > Data statistic > Event statistic the following window pops up.
Entering 'rt' as the event type, and "[250 500]" (ms) as the event latency range, and pressing OK will show the following 'rt' event statistics.
133
See the rejection tutorial on data channel statistics (III.1.2) for more information on this graphic interface. 4. Most EEGLAB functions take events into account. For instance, functions that remove data (pop_eegplot(), pop_select()) will also remove events that occur during the data removed (though not their corresponding urevents). Functions that process continuous data (pop_spectopo(), pop_resample(), pop_mergeset()) will take into account 'boundary' events (data events added by EEGLAB to note portions of the data that have been removed or at 'hard' boundaries between concatenated datasets).
134
V.2.1.1. Event types ans = 1x157 struct array with fields: type position latency urevent To display the field values for the first event, type >> EEG.event(1) This will return ans = type: 'square' position: 2 latency: 129.087 urevent: 1 Remember that custom event fields can be added to the event structure and will thereafter be imported with the event information whenever the dataset is loaded. Therefore, the names of some event fields may differ in different datasets. Note that event field information can be easily retrieved using commands such as >> {EEG.event.fieldname}. For example >> {EEG.event(1:5).type} returns the contents of the type field for the first 5 events ans = 'square' 'square' 'rt' 'square' 'rt' Use the following commands to list the different event types in the unprocessed tutorial dataset: >> unique({EEG.event.type}); ans = 'rt' 'square' The command above assumes that event types are recorded as strings. Use unique(cell2mat({EEG.event.type})); for event types stored as numbers. >>
You may then use the recovered event type names to extract epochs. Below is the commandline equivalent of the epoch extraction procedure presented above in section I.5. Extracting data epochs. >>EEG = pop_epoch( EEG, { 'square' }, [-1 2], 'epochinfo', 'yes'); If you decide to process data from the commandline directly, do not forget to first remove baseline activity >> EEG = pop_rmbase( EEG, [-1000 0]); See the Script tutorial for more details on how to write Matlab scripts using EEGLAB.
135
V.2.1.2. Event latencies V.2.1.2. Event latencies We may use the same command as in the section above to display the contents of the event latency field. Event latencies are stored in units of data sample points relative to (0) the beginning of the continuous data matrix (EEG.data). For the tutorial dataset (before any processing), typing: >>{EEG.event(1:5).latency} returns the first 5 event latencies, ans = [129.0087] [218.0087] [267.5481] [603.0087] [659.9726]
To see these latencies in seconds (instead of sample points above), you need first to convert this cell array to an ordinary numeric array (using EEGLAB cell2mat() function), then subtract 1 (because the first sample point corresponds to time 0) and divide by the sampling rate. Therefore, >>(cell2mat({EEG.event(1:5).latency})-1)/EEG.srate returns the same event latencies in seconds, ans = 1.0001 1.6954 2.0824 4.7032 5.1482
For consistency, for epoched datasets the event latencies are also encoded in sample points with respect to the beginning of the data (as if the data were continuous). Thus, after extracting epoch from the tutorial dataset (section I.5) >>{EEG.event(1:5).latency} returns the first 5 event latencies, ans = [129] [218.00] [267.5394] [424] [513] Note that for an epoched dataset this information has no direct meaning. Instead, select menu item Edit > Event values (calling function pop_editeventvals()) to display the latency of this event in seconds relative to the epoch time-locking event. From the commandline, you may use the eeg_ function eeg_point2lat() to convert the given latencies from data points relative to the beginning of the data to latencies in seconds relative to the epoch time-locking event. For example: >> eeg_point2lat(cell2mat({EEG.event(1:5).latency}), ... cell2mat({EEG.event(1:5).epoch}), EEG.srate, [EEG.xmin EEG.xmax]) ans = 0 0.6953 1.0823 -0.6953 0
The reverse conversion can be accomplished using function eeg_lat2point(). The most useful function for obtaining event information from the commandline is EEGLAB function eeg_getepochevent(). This function may be used for both continuous and epoch data to retrieve any event field for any event type. For example, using the tutorial data (after epoch extraction), type in 136
V.2.1.3. Urevents >> [rt_lat all_rt_lat] = eeg_getepochevent(EEG, 'rt', [], 'latency'); to obtain the latency of events of type rt. The first output is an array containing one value per data epoch (the first event of the specified type in each data epoch). The second output is a cell array containing the field values for all the relevant events in each data epoch. Latency information is returned in milliseconds. (Note: the third input allows searching for events in a specific time window within each epoch. An empty value indicates that the whole epoch time range should be used). Similarly to otain the value of the event 'position' field for 'square' events in each epoch, type >> [rt_lat all_rt_lat] = eeg_getepochevent(EEG, 'square', [], 'position'); Continuous data behave as a single data epoch, so type >> [tmp all_sq_lat] = eeg_getepochevent(EEG, 'square'); to obtain the latencies of all 'square' events in the continuous data (via the second output). V.2.1.3. Urevents In EEGLAB v4.2 and above, a separate "ur" (German for "original") event structure, EEG.urevent, holds all the event information originally loaded into the dataset. If some events or data regions containing events are removed from the data, this should not affect the EEG.urevent structure. If some new events are inserted into the dataset, the urevent structure is automatically updated. This is useful to obtain information on the context of events in the original experiment. Even after extracting data epochs, the prior context of each event in a continuous or epoched dataset is still available. Currently the EEG.urevent structure can only be examined from the command line. The EEG.urevent structure has the same format as the EEG.event structure. The ' urevent' field in the event structure (e.g., EEG.event(n).urevent) contains the index of the corresponding event in the urevent structure array -thereby 'pointing' from the event to its corresponding urevent, e.g., its "original event" number in the continuous data event stream. For example, if a portion of data containing the second event is removed from a continuous dataset during artifact rejection, the second event will not remain in the EEG.event structure. It will remain, however, in the EEG.urevent structure. e.g. the second EEG.event might now point to the third EEG.urevent: >> EEG.event(2).urevent ans = 3 Note that ' urevent' indices in the EEG.event structure do not have to increase linearly. For example after epochs were extracted from the tutorial dataset, >> {EEG.event(1:5).urevent} ans = [1] [2] [3] [1] [2] This means that events 1 and 2 (in the first data epoch) and events 4 and 5 (in the second data epoch) are actually the same original events. At present (v4.4), a few EEGLAB commandline functions use the urevent structure: eeg_time2prev(), eeg_urlatency() and eeg_context(). We will use the important eeg_context() function in a script example below. The next section provides more insight into the relation between the EEG.event and EEG.urevent structures. V.2.1.4. Boundary events Events of reserved type 'boundary' are created automatically by EEGLAB when portions of the data are rejected from continuous data or when continuous datasets are concatenated. These events indicate the latencies and (when 137
V.2.1.4. Boundary events possible) the durations of the discontinuities these operations introduce in the data. In the image below, a portion of data that included event #2 was rejected, and a type 'boundary' event was added to the event structure. Its index became 2, since events are sorted by their latencies. The urevent structure continues to hold the original event information, with no added 'boundary' event.
Boundary events are standard event structures with event.type = 'boundary'. They also have an ' event.duration' field that holds the duration of the rejected data portion (in data samples). (Note: Since all events in a dataset must have the same set of fields, in datasets containing boundary events every event will have a 'duration' field -- set by default to 0 except for true boundary type events. Boundary events are used by several signal processing functions that process continuous data. For example, calculating the data spectrum in the pop_spectopo() function operates only on continuous portions of the data (between boundary events). Also, data epoching functions will (rightly!) not extract epochs that contain a boundary event. Epoched datasets do not have boundary events between data epochs. Instead of being stored in a 2-D array of size (channels, sample_points) like continuous data, epoched data is stored in a 3-D array of size (channels, sample_points, trials). Events in data epochs are stored as if the data were continuous, in effect treating the data as a 2-D array of size (channels, (sample_points*trials)). This format makes handling events from the commandline more convenient. The purpose of the EEG.urevent structure is to retain the full record of experimental events from the original continuous data, as shown in the image below. Function eeg_context() uses 'urevent' information to find events defined by their neighboring event 'context' in the experiment (and original data).
V.2.1.5. 'Hard' boundaries between datasets When continuous datasets are concatenated, a 'harder' type of boundary event must be inserted, this time into both the EEG.event and EEG.urevent structures. In particular, if the first urevent in the pair was the last event in one dataset, and the next urevent was the first event in the next concatenated dataset (which need not have been recorded at the same time), the latencies of the neighboring pair of urevents cannot be compared directly. Such so-called "hard" boundary events marking the joint between concatenated datasets have the usual type "boundary" but a special "duration" value, NaN (Matlab numeric value "not-a-number"). They are the only "boundary" events present in EEG.urevent and are the only type "boundary" events in EEG.event with a "duration" of "NaN" and an EEG.event.urevent pointer to an urevent. Hard "boundary" events are important for functions such as eeg_context() 138
V.2.1.5. 'Hard' boundaries between datasets that are concerned with temporal relationships among events in the original experiment (i.e., among urevents).
139
then typing >> EEG.epoch(1) returns ans = event: 1 eventlatency: 1.0823e+03 eventposition: 2 eventtype: 'rt' eventurevent: 3 This means that epoch number "1" contains a single event of type "rt" at latency 1082.3 ms, it also indicates that this is the first event in the dataset (i.e. event: 1), but note that it was the third event in the original dataset, since its corresponding urevent (stored in ' EEG.event.urevent') is "3".
V.2.3. Writing scripts using events event (in real data points) EEG.event(end).latency = EEG.event(index).latency 0.1*EEG.srate; EEG.event(end).type = 'cue'; % Make the type of the new event 'cue' end; end; EEG = eeg_checkset(EEG, 'eventconsistency'); % Check all events for consistency [ALLEEG EEG CURRENTSET] = eeg_store(ALLEEG, EEG, CURRENTSET); % Store dataset eeglab redraw % Redraw the main eeglab window
Event context (as more reliably retrieved from the 'EEG.urevent' table) can be valuable in data analysis. For example, one may want to study all events of a certain type (or set of types) that precede or follow events of some other types by delays within a given range. A classic ERP example was the demonstration by Squires et al. that the P300 peak was larger when a rare stimulus followed a string of standard stimuli than when it followed other rare stimuli. The (v4.4) commandline function eeg_context() looks for events of specified "target" type(s), then for preceding and/or succeeding events of specified "neighbor" type(s). The script below is a simple demonstration script using eeg_context() that finds target events in the sample dataset that are followed by appropriate button press responses. Some response ambiguity is resolved by making sure the response does not follow a succeeding target. (In that case, we assume the response is to the second target). It also finds the responded targets that follow a non-responded target since, we expect, the EEG dynamics time-locked to these targets may differ in some way from those not following a 'miss'. % For each target 'square' event, find the succeeding 'rt' and 'square' events [targsrt,nextrts,nxtypert,rtlats] = eeg_context(EEG,{'square'},{'rt'},1); % find succeeding rt events [targssq,nextsqs,nxtypesq,sqlats] = eeg_context(EEG,{'square'},{'square'},1); % find succeeding square events % find target 'square' events with appropriate button-press responses selev = []; % selected events rejev = []; % rejected events for e=1:length(targsrt) % For each target, if rtlats(e) > 200 & rtlats(e) < 1500 ... % if 'rt' latency in acceptable range & (sqlats(e) > rtlats(e) | isnan(sqlats(e))) % and no intervening 'square' event, selev = [selev targsrt(e,1)]; % mark target as responded to else % Note: the isnan() test above tests for NaN value % of sqlats (when no next "square") rejev = [rejev targsrt(e,1)]; end end rts = rtlats(selev); % collect RT latencies of responded targets whos rtlats sqlats nextrts nextsqs selev = targs(selev); % selev now holds the selected EEG.event numbers rejev = targs(rejev); fprintf(['Of %d "square" events, %d had acceptable "rt" responses ',... 'not following another "square".\n'],length(targsrt),length(selev)); % % find targets following non-responded targets 141
V.2.3. Writing scripts using events % aftererr = rejev+1; % find target events following an unresponded target aftererr(find(ismember(aftererr,selev)==0)) = []; % remove events themselves % not responded whos selev rejev aftererr fprintf(['Of %d "square" events following non-responded targets, ',... '%d were themselves responded.\n\n'],length(rejev),length(aftererr));
The EEGLAB 'urevent' structure allows researchers to explore the point of view that no two events during an experiment are actually equivalent, since each event occurs in a different context. Although hard to dispute, insights into brain function to be gleaned from this point of view are sacrificed when dynamics time-locked to all events of a certain type are simply averaged together. In particular, the EEGLAB erpimage() and pop_erpimage() functions allow users to visualize differences in potential time course or spectral amplitudes in epochs time-locked to events sorted by some feature of their context. A simple example is sorting stimulus-locked epoch by subsequent response time ('rt'), though this is only a simple and straightforward example. Using the eeg_context() function, one might also sort stimulus event-locked epochs by the amount of time since the previous button press, or by the fraction of 'position'=1 events in the last minute, etc. Some future EEGLAB functions (and many user scripts) will no doubt exploit such possibilities in many ways.
142
VI.1.1. Why cluster? areas that generate the activities summed by the (Cz) channel may be rather different in different subjects, depending on the physical locations, extents, and particularly the orientations of the cortical source areas, both in relation to the 'active' electrode site (e.g., Cz) and/or to its recorded reference channel (for example, the nose, right mastoid, or other site). That is, data recorded from equivalent channel locations (Cz) in different subjects may sum activity of different mixtures of underlying cortical EEG sources, no matter how accurately the equivalent electrode locations were measured on the scalp. This fact is commonly ignored in EEG research. Is my IC your IC? Following ICA (or other linear) decomposition, however, there is no natural and easy way to identify a component from one subject with one (or more) component(s) from another subject. A pair of independent components (ICs) from two subjects might resemble and/or differ from each other in many ways and to different degrees -- by differences in their scalp maps, power spectra, ERPs, ERSPs, ITCs, or etc. Thus, there are many possible (distance) measures of similarity, and many different ways of combining activity measures into a global distance measure to estimate component pair similarity. Thus, the problem of identifying equivalent components across subjects is non-trivial. An attempt at doing this for 31-channel data was published in 2002 and 2004 in papers whose preparation required elaborate custom scripting (by Westerfield, Makeig, and Delorme). A 2005 paper by Onton et al. reported on dynamics of a frontal midline component cluster identified in 71-channel data. EEGLAB now contains functions and supporting structures for flexibly and efficiently performing and evaluating component clustering across subjects and conditions. With its supporting data structures and stand-alone 'std_' prefix analysis functions, EEGLAB makes it possible to summarize results of ICA-based analysis across more than one condition from a large number of subjects. This should make more routine use of linear decomposition and ICA possible to apply to a wide variety of hypothesis testing on datasets from several to many subjects. The number of EEGLAB clustering and cluster-based functions will doubtless continue to grow in number and power in the future versions, since they allow the realistic use of ICA decomposition in hypothesis-driven research on large or small subject populations. NOTE: Independent component clustering (like much other data clustering) has no single 'correct' solution. Interpreting results of component clustering, therefore, warrants caution. Claims to discovery of physiological facts from component clustering should be accompanied by thoughtful caveat and, preferably, by results of statistical testing against suitable null hypotheses.
144
VI.1.2. Before clustering Set the first option so that no more than one dataset is stored in memory at a time. Dataset data arrays are then read from disk whenever EEGLAB requires access to the data, but without cluttering memory. This will allow Matlab to load and hold a large number of dataset structures forming a large STUDY. Also, unset the third option so ICA component activations do not get recomputed automatically. This saves time as datasets are re-saved automatically during pre-clustering and clustering.
145
VI.2. The graphic interface After downloading the sample clustering data, unzip it in a folder of your choice (preferably in the "sample_data" sub-folder of the EEGLAB release you are currently using; under Unix use the "unzip" command). This will create a sub-folder "5subjects" containing several studysets. Then open a Matlab session and run >> eeglab.
Warning: Under Matlab 7.x and Unix, do not copy and paste information into the edit boxes, because though it seems this should work, Matlab does not correctly register such inputs. Enter all information manually (except 'browsed' datasets). This problem does not seem to arise currently under Windows. Note that the fields "Subject" and "Condition" have been filled automatically. This is because the datasets already contained this information. For instance, if you were to load this dataset into EEGLAB by selecting menu item Edit > Dataset info, you would be able to edit the "Subject" and "Condition" information for this dataset (as shown below). You may also edit it within the study itself, since dataset information and study dataset information may be different to ensure maximum flexibility. For instance, if you want one dataset to belong to several studies, but play different roles in each. Note: Use the checkbox "Update dataset information..." to maintain consistency between dataset and studyset fields. However, if you check this option, datasets may be modified on disk by clustering functions.
146
Enter all datasets fo4 all subjects in the study, so that the study gui looks like this:
After you have finished adding datasets to the study, press "OK" in the study gui to import all the dataset information. We strongly recommend that you also save the study by filling in the last edit box in the gui or, by selecting menu item File > Save study as after closing the interface. Important note: Continuous data collected in one task or experiment session are often separated into epochs defining different task conditions (for example, separate sets of epochs time locked to targets and non-targets respectively). Datasets from different conditions collected in the same session are assumed by the clustering functions to have the same ICA components (i.e., the same ICA decomposition is assumed to have been applied to the data from all session conditions at once). If this was not the case, then datasets from the different conditions must be assigned to different sessions.
147
An EEGLAB study contains descriptions of and links to data in one to many epoched datasets, for example a set of datasets from a group of subjects in one or more conditions of the same task, or performing different tasks in the same or different sessions. Other designs are possible, for instance a number of different task conditions from the same subject collected during one or more sessions. The term " STUDY" indicates that these datasets should originate from a single experimental study and have comparable structure and significance. When in use, studyset datasets are partially or totally loaded into EEGLAB. They thus may also be accessed and modified individually, when desired, through the main EEGLAB graphic interface. In the gui, epoch consistency indicates whether or not the data epochs in all the datasets have the same lengths and limits. "Channels per frame" indicates the number of channels in each of the datasets ( Note: It is possible to process datasets with different numbers of channels). "Channel location" indicates whether or not channel locations are present for all datasets. Note that channel locations may be edited for all datasets at the same time (simply call menu item Edit > Channel locations). The "Clusters" entry indicates the number of component clusters associated with this study. There is always at least one cluster associated with a study. This contains all the pre-selected ICA components from all datasets. The "Status" entry indicates the current status of the study. In this case, the study is ready for pre-clustering. Below, we detail what the STUDY terms "subjects", "conditions", "sessions", and "groups" mean. To list the datasets in the study, use menu item Study > Edit study info. The following window will pop up:
148
The top of the window contains information about the study, namely its running name, the extended task name for the study, and some notes. The next section contains information about the 10 datasets that are part of the study. For each dataset, we have specified a subject code and condition name. We chose to leave the session and group labels empty, as they were irrelevant for this study. (For this study, there was only one subject group and both conditions were collected in a single session, so the same ICA decomposition was used for both conditions). Uniform default values will be used by EEGLAB for those fields. The Components column contains the components for each dataset that will be taken into consideration during clustering. Note that if you change the component selection (by pressing the relevant push button), all datasets with the same subject name and the same session number will also be updated (as these datasets are assumed to have the same ICA decomposition). Each of the datasets may also contain subject, group, session, and condition codes. They do not necessarily have to be the same as those present in the study. For example, the same dataset may represent one condition in one study and a different condition in another study. In general, however, we prefer the dataset information to be consistent with the studyset information - thus we check the first checkbox here. The second checkbox removes all current cluster information. When cluster information is present, it is not possible to add or remove datasets and to edit certain fields (because this would not be consistent with the already computed clusters). Re-clustering the altered study does not take much time, once the pre-clustering information for the new datasets (if any) has been computed and stored. The third checkbox allows the study to be saved or re-saved as a studyset. KEY STEP 2: Here, we begin by pre-selecting components for clustering. Simply press the "Select by r.v." push button in the gui above. The entry box below will appear. This allows you to set a threshold for residual variance of the dipole model associated with each component. Note: Using this option requires that dipole model information is present in each dataset. Use EEGLAB plug-in DIPFIT2 options and save the resulting dipole models into each dataset before calling the study guis. Otherwise, options related to dipole localization will not be available.
149
This interface allows specifying that components used in clustering will only be those whose equivalent dipole models have residual dipole variance less than a specified threshold (0% to 100%). The default value is 15%, meaning that only components with residual variance of less than 15% will be included in clusters. This is useful because of the modeled association between components with 'dipolar' (or sometimes dual-dipolar) scalp maps with physiologically plausible components, those that may represent the activation in one (or two coupled) brain area(s). For instance, in the interface above, the resid. var. default is set to 15%. This means that only component that have an equivalent dipole model with less than 15% residual variance will be selected for clustering. Pressing "OK" will cause the component column to be updated in the main study-editing window. Then press "OK" to save your changes.
150
The top section of the gui above allows selecting clusters from which to produce a refined clustering. There is not yet any choice here -- we must select the parent datasets that contain all selected components from all datasets (e.g., the components selected at the end of the previous section). The checkboxes on the left in the second section of the pop_preclust() interface above allow you to select which component activity measures to include in the cluster location measure constructed to perform clustering. The goal of the pre-clustering function is to compute an N-dimensional cluster position vector for each component. These 'cluster position' vectors will be used to measure the 'distance' of components from each other in the N-dimensional cluster space. The value of N is arbitrary but, for numeric reasons pertaining to the clustering algorithms, should be kept relatively low (e.g., <10). In the cluster position vectors, for example, the three first values might represent the 3-D (x,y,z) spatial locations of the equivalent dipole for each component. The next, say, 10 values might represent the largest 10 principal components of the first condition ERP, the next 10, for the second condition ERP, and so on. If you are computing (time/frequency) spectral perturbation images, you cannot use all their (near-3000) time-frequency values, which are redundant, in any case. Here also, you should use the "Dim." column inputs to reduce the number of dimensions (for instance, to 10). Note: pop_preclust() reduces the dimension of the cluster position measures (incorporating information from ERP, ERSP, or other measures) by restricting the cluster position vectors to an N-dimensional principal subspace by principal component analysis (PCA). You may wish to "normalize" these principal dimensions for the location and activity measures you select so their metrics are equivariant across measures. Do this by checking the checkbox under the "norm" column. This 'normalization' process involves dividing the measure data of all principal components by the standard deviation of the first PCA component for this measure. You may also specify a relative weight (versus other measures). For instance if you use two measures (A and B) and you want A to have twice the "weight" of B, you would normalize both measures and enter a weight of 2 for A and 1 for B. If you estimate that measure A has more relevant information than measure B, you could also enter a greater number of PCA dimension for A than for B. Below, for illustration we elect to cluster on all six allowed activity measures. TIP: All the measures described below, once computed, can be used for clustering and/or for cluster visualization (see the following section of the tutorial, Edit/Visualize Component Cluster Information). If you do not wish to use some of the measures in clustering but still want to be able to visualize it, select it and enter 0 for the PCA dimension. This measure will then be available for cluster visualization although it will not have been used in the clustering process itself. This allows an easy way of performing exploratory clustering on different measure subsets. Spectra: The first checkbox in the middle right of the pre-clustering window (above) allows you to include the log mean power spectrum for each condition in the pre-clustering measures. Clicking on the checkbox allow 151
VI.2.3. Preparing to cluster (Pre-clustering) you to enter power spectral parameters. In this case, a frequency range [lo hi] (in Hz) is required. Note that for clustering purposes (but not for display), for each subject individually, the mean spectral value (averaged across all selected frequencies) is subtracted from all selected components, and the mean spectral value at each frequency (averaged across all selected components) is subtracted from all components. The reason is that some subjects have larger EEG power than others. If we did not subtract the (log) means, clusters might contain components from only one subject, or from one type of subject (e.g., women, who often have thinner skulls and therefore larger EEG than men). ERPs: The second checkbox computes mean ERPs for each condition. Here, an ERP latency window [lo hi] (in ms) is required. Dipole locations: The third checkbox allows you to include component equivalent dipole locations in the pre-clustering process. Dipole locations (shown as [x y z]) automatically have three dimensions ( Note: It is not yet possible to cluster on dipole orientations). As mentioned above, the equivalent dipole model for each component and dataset must already have been pre-computed. If one component is modeled using 2 symmetrical dipoles, the preclustering function will use the average location of the two dipoles for clustering purposes. Scalp maps: The fourth checkbox allows you to include scalp map information in the component 'cluster location' measure. You may choose to use raw component map values, their laplacians, or their spatial gradients. ( Note: We have obtained some good results using laplacian scalp maps, though there are theoretic advantages to using equivalent dipole locations in place of scalp maps). You may also select whether or not to use only the absolute map values, their advantage being that they do not depend on component map polarities. As explained in the ICA component section, ICA component scalp maps themselves have no absolute scalp map polarity. ERSPs and/or ITCs: The last two checkboxes allow you to include event-related spectral perturbation information (event-related power changes, ERSP, and phase consistency, ITC) for each condition. To compute the ERSP and/or ITC measures, several time/frequency parameters are required. To choose these values, you may enter the relevant timefreq() keywords and arguments in the text box. You may for instance enter 'alpha', 0.01 for significance masking. Final number of dimensions: An additional checkbox at the bottom allows you to further reduce the number of dimensions. Most clustering algorithms do not work well with more than 10 to 20 dimensions, so if for example you select all the options above and retain all their dimensions, the accumulated distance measures will have a total of 53 dimensions. This number may be reduced (e.g., to a default 10) using the PCA decomposition invoked by this option. Note that, since this will distort the cluster location space (projecting it down to its smaller dimensional 'shadow'), it is preferable to use this option carefully. For instance, if you decide to use reduced-dimension scalp maps and dipole locations that together have 13 dimensions (13 = the requested 10 dimensions for the scalp maps plus 3 for the dipole locations), you might experiment with using fewer dimensions for the scalp maps (e.g., 7 instead of 10), in place of the final dimension reduction option (13 to 10). Finally, the pop_preclust() gui allows you to choose to save the updated STUDY to disk. In the pop_preclust() select all methods and leave all default parameters (including the dipole residual variance filter at the top of the window), then press OK. As explained below, for this tutorial study measure values are already stored on disk with each dataset, so they need not be recomputed, even if the requested clustering limits (time, frequency, etc.) for these measured are reduced. Re-using component measures computed during pre-clustering: Computing the spectral, ERP, ERSP, and ITC measures for clustering may, in particular, be time consuming -- requiring up to a few days if there are many components, conditions, and datasets! The time required will naturally depend on the number and size of the datasets and on the speed of the processor. Future EEGLAB releases will implement parallel computing of these measures for cases in which multiple processors are available. Measures previously computed for a given dataset and stored by std_preclust() will not be recomputed, even if you narrow the time and/or frequency ranges considered. Instead, the computed measure information will be loaded from the respective Matlab files in which it was saved by previous calls to pop_preclust(). Measure data files are saved in the same directory/folder as the dataset, and have the same dataset name -- but different filename extensions. For example, the file that stores component ERSP information for the dataset 152
VI.2.4. Finding clusters syn02-S253-clean.set is named syn02-S253-clean.icaersp. As mentioned above, for convenience it is recommended that each subject's data be stored in a different directory/folder. If all the possible clustering measures have been computed for this dataset, the following Matlab files should be in the /S02/ dataset directory: syn02-S253-clean.icaerp (ERPs) syn02-S253-clean.icaspec (power spectra) syn02-S253-clean.icatopo (scalp maps) syn02-S253-clean.icaersp (ERSPs) syn02-S253-clean.icaitc (ITCs) The parameters used to compute each measure are also stored in the file, for example the frequency range of the component spectra. Measure files are standard Matlab files that may be read and processed using standard Matlab commands. The variable names they contain should be self-explanatory. Note: For ERSP-based clustering, if a parameter setting you have selected is different than the value of the same parameter used to compute and store the same measure previously, a query window will pop up asking you to choose between recomputing the same values using the new parameters or keeping the existing measure values. Again, narrowing the ERSP latency and frequency ranges considered in clustering will not lead to recomputing the ERSP across all datasets.
Currently, two clustering algorithms are available: 'kmeans' and 'neural network' clustering. As explained earlier, 'kmeans' requires the Matlab Statistics Toolbox, while 'neural network' clustering uses a function from the Matlab Neural Network Toolbox. Both algorithms require entering a desired number of clusters (first edit box). An option for the kmeans() algorithm can relegate 'outlier' components to a separate cluster. Outlier components are defined as components further than a specified number of standard deviations (3, by default) from any of the cluster centroids. To turn on this option, click the upper checkbox on the left. Identified outlier components will be put into a designated 'Outliers' cluster. Click on the lower left checkbox to save the clustered studyset to disk. If you do not provide a new filename in the adjacent text box, the existing studyset will be overwritten. In the pop_clust() gui, enter "10" for the number of clusters and check the "Separate outliers ..." checkbox to detect and separate outliers. Then press 'OK' to compute clusters (clustering is usually quick). The cluster editing interface detailed in the next section will automatically pop up. Alternatively, for the sample data, load the provided studyset 'N400clustedit.study' in which pre-clustering information has already been stored.
153
Of the 305 components in the sample N400STUDY studyset, dipole model residual variances for 154 components were above 15%. These components were omitted from clustering. The remaining 151 components were clustered on the basis of their dipole locations, power spectra, ERPs, and ERSP measures into 10 component clusters. Visualizing clusters : Selecting one of the clusters from the list shown in the upper left box displays a list of the cluster components in the text box on the upper right. Here, SO2 IC33 means "independent component 33 for subject SO2," etc. The "All 10 cluster centroids" option in the (left) text box list will cause the function to display results for all but the 'ParentCluster' and 'Outlier' clusters. Selecting one of the plotting options below (left) will then show all 10 cluster centroids in a single figure. For example, pressing the "Plot scalp maps" option will produce the figure below:
In computing the mean cluster scalp maps (or scalp maps centroids), the polarity of each of the cluster's component maps was first adjusted so as to correlate positively with the cluster mean (recall that component maps have no absolute polarity). Then the map variances were equated. Finally, the normalized centroids were computed. 154
VI.2.5. Viewing component clusters To see individual component scalp maps for components in the cluster, select the cluster of interest in the left column (for example, Cluster 8 as in the figure above (Note that your "Cluster 8" scalp map may differ once you have recomputed the clusters for the sample data). Then press the 'Plot scalp maps' option in the left column. The following figure will appear.
To see the relationship between one of the cluster mean maps and the individual scalp maps in the cluster, select the cluster of interest (for instance Cluster 8), and press the 'Plot scalp maps' option in the right pop_clustedit() column. Note: Channels missing from any of the datasets do not affect clustering or visualization of cluster scalp maps. Component scalp maps are interpolated by the toporeplot() function, avoiding the need to restrict STUDY datasets to a 'always clean' channel subset or to perform channel interpolation on individual datasets.
You may also plot scalp maps for individual components in the cluster by selecting components in the right column and then pressing 'Plot scalp maps' (not shown). A good way to visualize all the average cluster measures at once is to first select a cluster of interest from the cluster list on the left (e.g., Cluster 8), and then press the 'Plot cluster properties' push button. The left figure below 155
VI.2.5. Viewing component clusters presents the Cluster-8 mean scalp map (same for both conditions), average ERP and spectrum (for these, the two conditions are plotted in different colors), average ERSP and ITC (grand means for both conditions; the individual conditions may be plotted using the 'Plot cluster properties' push button). The 3-D plot on the bottom left presents the locations of the centroid dipole (red) and individual component equivalent dipoles (blue) for this cluster.
To quickly recognize the nature of component clusters by their activity features requires experience. Here Cluster 8 accounts for some right occipital alpha activity -- note the strong 10-Hz peak in the activity spectra. The cluster ERPs show a very slow (1-Hz) pattern peaking at the appearance of first words of the word pairs (near time -1 s). The apparent latency shift in this slow wave activity between the two conditions may or may not be significant. A positive (though still quite low, 0.06) ITC follows the appearance of the first word in each word pair (see Experimental Design), indicating that quite weakly phase-consistent theta-band EEG activity follows first word onsets. Finally, blocking of spectral power from 7 Hz to at least 25 Hz appears just after onset of the second words of word pairs (at time 0) in the grand mean ERSP plot (blue region on top right) To review all "Cluster 8" component dipole locations, press the 'Plot dipoles' button in the left column. This will open the plot viewer showing all the cluster component dipoles (in blue), plus the cluster mean dipole location (in red). You may scroll through the dipoles one by one, rotating the plot in 3-D or selecting among the three cardinal views (lower left buttons), etc. Information about them will be presented in the left center side bar (see the image below).
156
As for the scalp maps, the pop_clustedit() gui will separately plot the cluster ERPs, spectra, ERSPs or ITCs. Let us review once more the different plotting options for the data spectrum. Pressing the 'Plot spectra' button in the left column will open a figure showing the two mean condition spectra below.
Pressing the 'Plot spectra' button in the right column with "All components" selected in the left column will open a figure displaying for each condition all cluster component spectra plus (in bold) their mean.
157
Finally, to plot the condition spectra for individual cluster components, select one component from the 'Select component(s) to plot' list on the right and press 'Plot spectra' in the right column. For example, selecting component 37 from subject S02 (SO2 IC37) will pop up the figure below. Here, the single component spectra are shown in light blue as well as the mean cluster spectrum (in black).
158
Rename a cluster: The 'Rename selected cluster' option allows you to rename any cluster using a (mnemonic) name of your choice. Pressing this option button opens a pop-up window asking for the new name of the selected cluster. For instance, if you think a cluster contains components accounting for eye blinks you may rename it "Blinks". Automatically rejecting outlier components: Another editing option is to reject 'outlier' components from a cluster after clustering. An 'outlier' can be defined as a component whose cluster location is more than a given number of standard deviations from the location of the cluster centroid. Note that standard deviation and cluster mean values are defined from the N-dimensional cluster space data created during the pre-clustering process. For example, if the size of the pre-clustering cluster location matrix is 10 by 200 (for 200 components), then N = 10. The default threshold for outlier rejection is 3 standard deviations. To reject 'outlier' components from a cluster, first select the cluster of interest from the list on the left and then press the 'Auto-reject outlier components' option button. A window will open, asking you to set the outlier threshold. 'Outlier' components selected via either the 'Reject outlier components' option or the 'Remove selected outlier component(s)' option (below) are moved from the current cluster '[Name]' to a cluster named 'Outlier [Name]'. Removing selected outlier components manually: Another way to remove 'outlier' components from a cluster is to do so manually. This option allows you to de-select seeming 'outlier' components irrespective of their distance from the cluster mean. To manually reject components, first select the cluster of interest from the list on the left, then select the desired 'outlier' component(s) from the component list on the right, then press the 'Remove selected outlier comps.' button. A confirmation window will pop up. Creating a new cluster: To create a new empty cluster, press the 'Create new cluster' option, this opens a pop-up window asking for a name for the new cluster. If no name is given, the default name is 'Cls #', where '#' is the next available cluster number. For changes to take place, press the 'OK' button in the pop-up window. The new empty cluster will appear as one of the clusters in the list on the left of the editing/viewing cluster window. Reassigning components to clusters: To move components between any two clusters, first select the origin cluster from the list on the left, then select the components of interest from the component list on the right, and press the 'Reassign selected component(s)' option button. Select the target cluster from the list of available clusters. Saving changes: As with other pop_ functions, you can save the updated STUDY set to disk, either overwriting the current version - by leaving the default file name in the text box - or by entering a new file name. 159
At this point, we might try further clustering only the 'Artifact' cluster components, e.g., attempting to separate eye movement processes from heart and muscle activity processes, or etc. A schematic of a possible (but probably again not realistic) further decomposition is shown schematically above. In this case, the parent of the identified eye movement artifact cluster is the 'Artifact' cluster; the child cluster of 'eye' artifacts itself has no child clusters. On the other hand, clustering the 'Non-artifact' cluster produces three child clusters which, presumably after careful inspection, we decide to rename 'Alpha', 'Mu' and 'Other'. To refine a clustering in this way, simply follow the same sequence of event as described above. Call the pre-clustering tools using menu item Study > Build preclustering array. You may now select a cluster to refine. in the example above, we notice that there seemed to be components with different spectra in Cluster 8, so let us try to refine the clustering based on differences among the Cluster-8 component spectra.
160
Select the Study > Cluster components menu item. Leave all the defaults (e.g., 2 clusters) and press OK.
The visualization window will then pop up with 2 new clusters under Cluster 8.
161
Below the component spectra for Cluster 13 are plotted. Note that Cluster-13 components have relatively uniform spectra.
You may also plot the scalp map of Cluster 13. All the cluster components account for occipital activity and have similarly located equivalent dipole sources.
162
163
VI.3.1. The STUDY structure STUDY = name: filename: filepath: datasetinfo: session: subject group: condition: setind: cluster: notes: task: history etc: 'N400STUDY 'OctN400ClustEditHier.study' '/eeglab/data/N400/' [1x10 struct] [] {1x5 cell} {'old' 'young'} {'non-synonyms' 'synonyms'} [2x5 double] [1x40 struct] '' 'Auditory task: Synonyms Vs. Non-synonyms, N400' [1x4154 char] [1x1 struct]
The field STUDY.datasetinfo is an array of structures whose length is the number of datasets that are part of the STUDY. Each structure stores information on one of the datasets -- its subject and subject group labels and its condition and session codes. It also includes a pointer to the dataset file itself (as explained below in more detail). STUDY.datasetinfo sub-fields 'subject', 'session', 'group' and 'condition' label the subject, subject group, session, and condition that is associated with each dataset in the study. This information must be provided by the user when the STUDY structure is created. Otherwise, default values are assumed. The 'setind' field holds the indices of the datasetinfo cells, ordered in a 2-D matrix in the format [conditions (subjects x sessions)]. The 'cluster' field is an array of cluster structures, initialized when the STUDY is created and updated after clustering is performed (as explained below in more detail). The 'history' field is equivalent to the 'history' field of the EEG structure. It stores all the commandline calls to the functions from the gui. For basic script writing using command history information, see the EEGLAB script writing tutorial. The 'etc' field contains internal information that helps manage the use of the STUDY structure by the clustering functions. For example, pre-clustering data is stored there before clustering is performed.
This information is posted by the user when the STUDY is created. The 'filepath' and 'filename' fields give the location of the dataset on disk. The 'subject' field attaches a subject code to the dataset. Note: Multiple datasets from the same subject that belong to a studyset must be distinguished as being for different experimental conditions and/or as coming from different experimental sessions. The 'group' field attaches a subject group label to the dataset. This field is currently (v5.0b) not used by EEGLAB functions, but will be be used in future for statistical testing of multi-group studies. The 'condition' and 'session' fields hold dataset condition and session labels. If the 'condition' field is empty, all datasets are assumed to represent the same condition. If the 'session' field is empty, each dataset is assumed to have been recorded in a different session. The 'index' field holds the dataset index in the current ALLEEG vector. Note that currently, datasetinfo(1) must correspond to ALLEEG(1), dataset(2) to ALLEEG(2), etc. This constraint will be removed in the future. The 'comps' field holds indices of selected components in the dataset available for clustering. If it is empty, all components are considered.
165
VI.3.3. The STUDY.cluster sub-structure The 'cluster.name' sub-field of each cluster is initialized according to the cluster number, e.g. its index in the cluster array (for example: 'cls 2', 'cls 3', etc.). These cluster names may be changed to any (e.g., more meaningful) names by the user via the command line or via the pop_clustedit() interface. The 'cluster.comps' and 'cluster.sets' fields describe which components belong to the current cluster: 'cluster.comps' holds the component indices and 'cluster.sets' the indices of their respective datasets. Note that several 'sets' might be present for each component - for instance two datasets containing different experimental conditions for the same subject and having the same ICA decomposition. The 'cluster.preclust' sub-field is a sub-structure holding pre-clustering information for the component contained in the cluster. This sub-structure includes the pre-clustering method(s), their respective parameters, and the resulting pre-clustering PCA data matrices (for example, mean component ERPs, ERSPs, and/or ITCs in each condition). Additional information about the preclust sub-structure is given in the following section. It is used for further (hierarchic) sub-clustering. The 'cluster.centroid' field holds the cluster measure centroids for each measure used to cluster the components (e.g., the mean or centroid of the cluster component ERSPs, ERPs, ITCs, spectra, etc. for each STUDY condition), plus measures not employed in clustering but available for plotting in the interactive cluster visualization and editing function, pop_clustedit(). The 'cluster.algorithm' sub-field holds the clustering algorithm chosen (for example 'kmeans') and the input parameters that were used in clustering the pre-clustering data. The 'cluster.parent' and 'cluster.child' sub-fields are used in hierarchical clustering (see hierarchic clustering). The 'cluster.child' sub-field contains indices of any clusters that were created by clustering on components from this cluster (possibly, together with additional cluster components). The 'cluster.parent' field contains the index of the parent cluster. Continuing with the hierarchic design introduced briefly in hierarchic clustering, suppose that Cluster 2 ('artifacts') comprises 15 components from four of the datasets. The cluster structure will have the following values: >> STUDY.cluster(2) ans = name: parent: child: comps: sets: algorithm: centroid: preclust: 'artifacts' {'ParentCluster 1'} {'muscle 4' 'eye 5' 'heart 6'} [6 10 15 23 1 5 20 4 8 11 17 25 3 4 12] [1 1 1 1 2 2 2 3 3 3 3 3 4 4 4] {'Kmeans' [2]} [1x1 struct] [1x1 struct]
This structure field information says that this cluster has no other parent cluster than the ParentCluster (as always, Cluster 1), but has three child clusters (Clusters 4, 5, and 6). It was created by the 'Kmeans' 'algorithm' and the requested number of clusters was '2'. Preclustering details are stored in the STUDY.cluster(2).preclust sub-structure (not shown above but detailed below). For instance, in this case, the 'cluster.preclust' sub-structure may contain the PCA-reduced mean activity spectra (in each of the two conditions) for all 15 components in the cluster.
166
VI.4.1. Creating a STUDY { 'index' 2 'load' 'S05/syn05-S253-clean.set' 'subject' 'S05' 'condition' 'synonyms' }, ... { 'index' 3 'load' 'S07/syn07-S253-clean.set' 'subject' 'S07' 'condition' 'synonyms' }, ... { 'index' 4 'load' 'S08/syn08-S253-clean.set' 'subject' 'S08' 'condition' 'synonyms' }, ... { 'index' 5 'load' 'S10/syn10-S253-clean.set' 'subject' 'S10' 'condition' 'synonyms' }, ... { 'index' 6 'load' 'S02/syn02-S254-clean.set' 'subject' 'S02' 'condition' 'non-synonyms' }, ... { 'index' 7 'load' 'S05/syn05-S254-clean.set' 'subject' 'S05' 'condition' 'non-synonyms' }, ... { 'index' 8 'load' 'S07/syn07-S254-clean.set' 'subject' 'S07' 'condition' 'non-synonyms' }, ... { 'index' 9 'load' 'S08/syn08-S254-clean.set' 'subject' 'S08' 'condition' 'non-synonyms' }, ... { 'index' 10 'load' 'S10/syn10-S254-clean.set' 'subject' 'S10' 'condition' 'non-synonyms' }, ... { 'dipselect' 0.15 } }); Above, each line of the command loads a dataset. The last line preselects components whose equivalent dipole models have less than 15% residual variance. See >> help std_editset for more information. Once you have created a new studyset (or loaded it from disk), both the STUDY structure and its corresponding ALLEEG vector of resident EEG structures will be variables in the Matlab workspace. Typing >> STUDY on the Matlab commandline will list field values: >> STUDY = name: filename: filepath: datasetinfo: group: session: subject: condition: setind: cluster: notes: task: history: etc: 'N400STUDY' 'N400empty.study' './' [1x10 struct] [] [] {'S02' 'S05' 'S07' 'S08' 'S10'} {'non-synonyms' 'synonyms'} [2x5 double] [1x1 struct] '' 'Auditory task: Synonyms Vs. Non-synonyms, N400' '' ''
168
VI.4.2. Component clustering and pre-clustering >> [STUDY ALLEEG] = std_preclust(STUDY, ALLEEG, [], ... {'spec' 'npca' 10 'norm' 1 'weight' 1 'freqrange' [3 25]} , ... {'erp' 'npca' 10 'norm' 1 'weight' 1 'timewindow' [100 600]} , ... {'dipoles' 'norm' 1 'weight' 10} , {'ersp' 'npca' 10 'freqrange' [3 25] 'cycles' [3 0.5] ... 'alpha' NaN 'padratio' 4 'timewindow' [-1600 1495] 'norm' 1 'weight' 1}); Alternatively, to enter these values in the graphic interface, type: >> [STUDY ALLEEG] = pop_preclust(STUDY, ALLEEG); The equivalent commandline call to cluster the STUDY is: >> [STUDY] = pop_clust(STUDY, ALLEEG, 'algorithm', 'kmeans', 'clus_num', 10); or to pop up the graphic interface: >> [STUDY] = pop_clust(STUDY, ALLEEG);
169
VI.4.4. Modeling condition ERP differences with std_envtopo() >> std_envtopo(STUDY, ALLEEG, 'clusters', [],'subclus',[3 4 6 7 8 ], ... 'env_erp', 'all', 'vert', -1100, 'baseline', [-200 0], ... 'diff', [1 2], 'limits', [-1300 1500 -5 5], 'only_precomp', 'on', ... 'clustnums' , -4,'limcontrib', [300 600]); The example above searches among all the clusters ('clusters', []) for the four component clusters that contribute most to the grand ERP ('clustnums', -4) in the time window [300 600] ms. In constructing the grand ERPs, five designated artifact component clusters are excluded ('subclus', [3 4 6 7 8 ]). The computation uses all the datasets in the STUDY ('env_erp', 'all') but only the components that were actually clustered ('only_precomp', 'on'). In this example, components with residual dipole model variance above 15% (0.15) were not clustered and thus were also not included in the grand mean ERPs. We also ask for the largest contributing clusters to the difference wave between the two conditions ('diff', [1 2]). For more information type: >> help std_envtopo Below are the three resulting figures, one for each condition and a third for the ERP difference between the two conditions. The N400 can be easily distinguished in the grand difference ERP on the right.
(Click on images to view details) In the three cases above, the four largest contributing clusters together account for 40%, 77%, and 67% of the respective grand mean ERP variances (pvaf). Three clusters (Cls 5, Cls 9, Cls 12) are among the four largest contributors to both conditions (left and middle images). These three, plus Cluster 10, account for roughly equal parts of the N400 difference (right image), implying that the N400 effect is not spatially focal or unitary, in line with results from invasive recordings. Note that the percent variance accounted for (pvaf) values for the four clusters add to over 100%, though together they account for only 67% of difference-ERP variance. This is because the scalp projections of the four clusters are spatially correlated, not orthogonal. Therefore, their projections can cancel each other. Here, for example, the positive right frontocentral channel projections of components in Cluster 10 partially cancel the spatially overlapping negative projections of Clusters 9, 12, and 5 at the same scalp locations. In this sense, ICA can re-capture more of the source data than is captured directly in the recorded scalp channel signals.
170
Above, we have italized several important fields. See the help message of the eeg_checkset() function (which checks the consistency of EEGLAB datasets) for the meaning of all the fields.
171
A1.1. EEG and ALLEEG EEGLAB variable " ALLEEG" is a Matlab array that holds all the datasets in the current EEGLAB/Matlab workspace. In fact " ALLEEG" is a structure array of " EEG" datasets (described above). If, in the current EEGLAB session you have two datasets loaded, typing >> ALLEEG on the Matlab command line returns: ALLEEG = 1x2 struct array with fields: setname filename filepath pnts nbchan trials srate xmin xmax data icawinv icasphere icaweights icaact event epoch chanlocs comments averef rt eventdescription epochdescription specdata specicaact reject stats splinefile ref history urevent times Typing >> ALLEEG(1) returns the structure of the first dataset in ALLEEG, and typing >> ALLEEG(2) returns the structure of the second dataset. See the script tutorial for more information on manipulating these structures. Most fields of the " EEG" structure contain single values (as detailed in eeg_checkset()). However some important fields of the " EEG" structure contain sub-structures. We will describe briefly three of those below: " EEG.chanlocs", " EEG.event", and " EEG.epoch".
A1.2. EEG.chanlocs
This EEG-structure field stores information about the EEG channel locations and channel names. For example, loading the tutorial dataset and typing >> EEG.chanlocs returns ans = 172
A1.2. EEG.chanlocs 1x32 struct array with fields: theta radius labels sph_theta sph_phi sph_radius X Y Z Here, EEG.chanlocs is a structure array of length 32 (one record for each of the 32 channels in this dataset). Typing >> EEG.chanlocs(1) returns ans = theta:0 radius:0.4600 labels:'FPz' sph_theta:0 sph_phi:7.200 sph_radius:1 X:.9921 Y:0 Z:0.1253
These values store the channel location coordinates and label of the first channel ('FPz'). You may use the pop_chanedit() funciton or menu item Edit > Channel locations to edit or recompute the channel location information. The value of any EEG structure field may also be modified manually from the Matlab command line. See also the EEGLAB channel location file database page and the tutorial section I.2 Using channel locations
A1.3. EEG.event
The EEG structure field contains records of the experimental events that occurred while the data was being recorded, plus possible additional user-defined events. Loading the tutorial dataset and typing >> EEG.event returns ans = 1x157 struct array with fields: type position latency urevent
In general, fields "type", "latency", and "urevent" are always present in the event structure. "type" contains the event type. "latency" contains the event latency in data point unit. "urevent" contains the index of the event in the 173
A1.3. EEG.event original (= "ur") urevent table (see below). Other fields like "position" are user defined and are specific to the experiment. The user may also define a field called "duration" (recognized by EEGLAB) for defining the duration of the event (if portions of the data have been deleted, the field "duration" is added automatically to store the duration of the break (i.e. boundary) event). If epochs have been extracted from the dataset, another field, "epoch", is added to store the index of the data epoch(s) the event belongs to. To learn more about the EEGLAB event structure, see the event tutorial. There is also a separate "ur" (German for "original") event structure, EEG.urevent (in EEGLAB v4.2 and above), which holds all the event information that was originally loaded into the dataset plus events that were manually added by the user. When continuous data is first loaded, the content of this structure is identical to contents of the EEG.event structure (minus the "urevent" pointer field of EEG.event). However, as users remove events from the dataset through artifact rejection or extract epochs from the data, some of the original (ur) events continue to exist only in the urevent structure. The "urevent" field in the EEG.event structure above contains the index of the same event in the EEG.urevent structure array. For example: If a portion of the data containing the second urevent were removed from a dataset during artifact rejection, the second event would not remain in the EEG.event structure -- but would still remain in the EEG.urevent structure. Now, the second event left in the data might be the original third event, and so will be linked to the third EEG.urevent, i.e. checking >> EEG.event(2).urevent ans = 3 WARNING: Datasets created under EEGLAB 4.1 and loaded into 4.2 had an EEG.urevent structure created automatically. If some data containing events had been rejected BEFORE this time, then the urevent structure information IS INCOMPLETE (i.e. to some degree wrong!). Most new datasets created under 4.2 had the urevent structure saved correctly when the event information was first added. Be cautious about using urevent information from legacy 4.1 datasets. You may refer to the event tutorial for more details on the event and urevent stuctures.
A1.4. EEG.epoch
In an epoched dataset, this structure is similar to the EEG.event structure, except that there is only one record for each epoch. Note that EEGLAB functions never use the epoch structure. It is computed from the EEG.event structure by the eeg_checkset() function (using flag 'eventconsistency') as a convenience for users who may want to use it to write advanced EEGLAB scripts. For the tutorial dataset, after extracting data epochs the epoch structure looks like this: >> EEG.epoch ans = 1x80 struct array with fields: event eventlatency eventposition eventtype eventurevent Note that this dataset contains 80 epochs (or trials). Now type >> EEG.epoch(1) ans = 174
A1.4. EEG.epoch event:[1 2 3] eventlatency:{[0] [695.2650] [1.0823e+03]} eventposition:{[2] [2] [2]} eventtype:{'square' 'square' 'rt'} eventurevent:{[1] [2] [3]}
The first field " EEG.epoch.event" is an array containing the indices of all dataset events that occurred during this epoch. The fields " EEG.epoch.eventtype", " EEG.epoch.eventposition" and " EEG.epoch.eventlatency" are cell arrays containing values for each of the events ( EEG.epoch.event) that occurred during the epoch. Note that the latencies in " EEG.epoch.eventlatency" have been recomputed in units of milliseconds with respect to the epoch time-locking event. When there is only one event in an epoch, the epoch table is more readable. You may refer to the EEGLAB event tutorial for more details. The next section will cover the supervening data structure, new as of EEGLAB v5.0b, the STUDY or studyset.
175
Simply press Yes. A copy of eeg_options.m will be stored in the local directory and modified when you change any of the EEGLAB options. ( Note: For EEGLAB to use this file, the current directory (.) must appear BEFORE the EEGLAB toolbox directory in the Matlab path; see path()). If the original eeg_option.m file is writable, EEGLAB will modify it instead. If the original distribution copy of the options file is modified, the new options will affect all EEGLAB sessions using that file. If, however, EEGLAB (or the user from the Matlab or shell commandline) copies the options file to the current working directory, then only EEGLAB sessions having this directory in their Matlab path (before the EEGLAB distribution directory) will follow the modified options. It is advised to have only one such option file to avoid confusion. Now the following window will pop up.
When the top option is set, EEGLAB can hold in memory more than one dataset at a time. New datasets are created by most of the operations called under the Tools menu. With this option set, users can undo dataset changes immediately by going back to working with the parent (previous) dataset (unless they set the "overwrite dataset" option when they saved the new dataset). Processing multiple datasets may be necessary when comparing datsets from separate subjects or experimental conditions. The second option allow to save the raw data in a separate file. This will be useful in future version of EEGLAB to read one channel at a time from disk. This also allow faster reading of dataset when they are part of a STUDY. If the 3rd option is set, all the ICA activitations (time courses of activity) will be pre-computed each time the ICA weights and sphere matrices are specified or changed. This may nearly double the main memory (RAM) required to work with the dataset. Otherwise, ICA activitations will be computed by EEGLAB only as needed, e.g. each time EEGLAB calls a function that requires one or more activations. In this case, only the activations needed will be computed, thus using less main memory. The bottom option is used to remember folder when reading datasets.
176
You can also change the colors of the EEGLAB interface using other options located in the icadefs file.
177
A3.1. Dipole fitting with DIPFIT2 Channel Co-registration: A new function has been adding for performing manual or automated alignment of measured dataset channel locations to stored spherical or BEM head model template channel montages.
There are three steps required to create equivalent dipole models for independent components: Setting model and preferences: This involves choosing the model (spherical or boundary element) and excluding some channels from the fitting procedure (e.g., eye channels). 179
A3.2. Setting up DIPFIT model and preferences Grid scanning: This involves scanning possible positions in a coarse 3-D grid to determine an acceptable starting point for fitting equivalent dipoles to each component. Non-linear interactive fitting: This involves running an optimization algorithm to find the best position for each equivalent dipole. Below we describe these three steps in detail. Note that the grid scanning and non-linear optimization may also be performed automatically for a group of selected components. This is described later in this chapter.
The top edit box, "Model (click to select)," specifies the type of head model -- spherical or boundary element (BEM). By default, the spherical head model uses four spherical surfaces (skin, skull, CSF, cortex) to model the brain. The BEM model is composed of three 3-D surfaces (skin, skull, cortex) extracted from the MNI (Montreal Neurological Institute) caconical template brain also used in SPM (see here for details, the brain used is referred to as "collin27"). In many case, the BEM model is more realistic than the four concentric spheres model, and will return more accurate results. However the BEM model is a numerical model and sometimes leads to incorrect solutions due to numerical instabilities, whereas the spherical model is an analytical model. Furthermore, the spherical model returns results that are comparable with the BESA tool (see validation study below). For this example, select Boundary element model. Clicking on the model name updates the fields below. The entry "Model file" contains the head model parameters (surface information, conductances, etc...). These are Matlab files and may be edited. See the FieldTrip documentation for more information on the head model files. The entry "Output coordinates" contains the format of the output dipole coordinates. Note that all dipoles are always plotted in MNI/Talairach coordinates. These parameters should only be updated for custom brain models. The entry "MRI" contains the name of the MRI image to plot dipoles within. You may enter a custom or individual subject MR image file, assuming this file has first been normalized to the MNI brain. See a tutorial page on How to normalize an MR brain image to the MNI brain template using SPM2. Note that the SPM2 software directory must be in your Matlab path to use the resulting file in DIPFIT. The entry "Template channel .loc file" contains the name of the template channel location file associated with the head model. This information is critical, as your dataset channel location file may be different from the template. If so, a co-registration transform is required to align your channel locations using the template locations associated with the model. Before we move on to co-registration, note the last edit box "Omit channels for dipole fit". By pressing List, a list of channels appears that allows users to exclude eye channels (or other, possibly non-head channels) from the dipole fitting procedure. 180
A3.2. Setting up DIPFIT model and preferences Channel co-registration is the most important part and critical part of the DIPFIT setting procedure. If your channel locations are not aligned with the surface of the selected head model, the coordinates of the dipoles returned by DIPFIT will be meaningless. Solution 1 (required for fitting the sample data): If all your electrode locations are within the International 10-20 System, the easiest way to align your channels to the head model is to simply use the standard channel coordinates associated with the head model. Here, no co-registration is required. To do this, press the "No coreg" checkbox and close the DIPFIT settings window (by pressing "OK"). Then go to the channel editing window (select menu item Edit > Channel location). The resulting channel editor window is shown below:
Press the "Look up locs" to look up your channel locations (by matching the channel labels) in the template channel location file.
If you had wanted to use the template channel locations for the spherical model, you would have selected the first option in the pop-up menu "Use BESA file for four-shell DIPFIT spherical model". If you want to use the template channel locations for the BEM model, scroll down the pop-up menu and click on the button labeled "Use MNI coordinate file for the BEM DIPFIT model", then press "OK. At this point you may perform coarse grid scanning and non-linear fine fitting as explained in the next section. Solution 2: If you are using channel locations and/or labels not in the International 10-20 System -- for example, scanned electrode positions, or some commercial high-density electrode cap file -- you will need to align or co-register your electrode locations with the selected head model. DIPPLOT does not actually allow you to align your electrode locations to the head model itself, but rather allows you to align your electrode locations to matching template 181
A3.2. Setting up DIPFIT model and preferences electrode locations associated with the head model. To try this, click on "Manual coreg." in the DIPFIT settings window. The following instruction window will first appear:
If you have selected the spherical head model and pressed "OK," the following co-registration window will appear. Here, the electrode locations are plotted on the sphere that represents the head. Note the schematic nose on the lower right; this will rotate with the head sphere. Each small red or green sphere indicates an electrode location, with fiducial locations (conventionally, the nasion and ear canal centers) drawn as bigger and darker spheres (more visible in the second image below).
If you have selected the BEM model, the following window will appear:
182
Use the "Warp" button to align and scale your electrode locations file so that it becomes best aligned with the template electrode file associated with the head model. If you have no channels with labels that are common to the labels in the template montage, a channel correspondance window will pop up:
The channel labels from your dataset electrode structure are shown in the right column, while the left column shows channel labels from the template channel file associated with the head model. Arrows in both colums indicate electrodes with the same labels in the other column. If your channels labels do not correspond to the International 10-20 System labels used in the template montage, press the "Pair channels" button and choose the nearest channel to each of your dataset channels in the template montage. See here and Oostenveld 2001 for more information about 10-20 channel locations. When you press "OK," the function will perform the optimal linear 3-D warp (translation, rotation, and scaling) to align your channel montage to the template montage associated with the head model. The warping procedure uses the Fieldtrip toolbox which is installed by default with EEGLAB. The result will be shown in the channel montage window (see below). You may press the "Labels on" button to toggle display of the channel labels for your channel structure (green) or the template channel file associated with the head model (red). You may also restrict the display to subsets of channels using the "Electrodes" buttons.
183
A3.3. Initial fitting - Scanning on a coarse-grained grid Fine tuning: To finely tune the alignment manually, repeatedly edit the values in the edit boxes. Here: Yaw means rotation in the horizontal plane around the z axis. Pitch and Roll are rotations around the x and y axes. The resulting co-registration window should look something like this:
Note about fiducials: Your channel structure may contain standard fiducial locations (nasion and pre-auricular points). If you import a channel file with fiducial locations into the channel editor, in EEGLAB v4.6- give them the standard 'fiducial' channel type "FID" and they will be stored in the channel information structure, EEG.chaninfo. This will also be done automatically if your fiducials have the standard names, "Nz" (nasion), "LPA" (left pre-auricular point), and "RPA" (right pre-auricular point ). Note that fiducial locations are stored outside the standard channel location structure, EEG.chanlocs, for compatibility with other EEGLAB plotting functions. Thereafter, fiducial locations will appear in the channel co-registration window (above) and may be used (in place of location-matched scalp channels) to align your electrode montage to the template locations associated with the head model. Use the "Align fiducials" button to do this. Press "OK" to update the DIPFIT settings window. This will display the resulting talairach transformation matrix, a vector comprised of nine fields named [shiftx shifty shiftz pitch roll yaw scalex scaley scalez]. Then press "OK" in the DIPFIT settings window and proceed to localization.
184
The first edit box "Component(s)" allows you to select a subset of components to fit. Note: selecting only a few components does not increase the speed of the computation, since the forward model still has to be computed at each location on the grid. The "Grid in X-direction," "Grid in Y-direction," and "Grid in Z-direction" edit boxes allow you to specify the size and spacing of the coarse grid. By default, DIPFIT uses 10 steps equally spaced between -radius and +radius of the sphere that best matches the electrode positions. Since equivalent dipoles are not likely to be in the lower hemisphere of the model head, by default DIPFIT only scans through positive Z values. The last edit box, "Rejection threshold RV(%)," allows you to set a threshold on the maximum residual variance that is accepted. Using this threshold, components that do not resemble a dipolar field distribution will not be assigned a dipole location. Press OK and a bar will pop up to show the progress of the coarse grid scanning. Note: during dipole localization, the electrode positions are projected to the skin surface of the spherical or BEM head model, though the electrode positions as saved in the dataset itself are not altered. DIPFIT starts the grid scan by first excluding all 3-D grid locations that are outside the head. It then computes the forward model (dipole-to-electrode projections) at each remaining grid location and compares it with all component topographies. The progress of this process is shown in the text window. When the process is completed, select menu item Tools > Locate dipoles using DIPFIT > Plot component dipoles to call the window below:
185
Here, all the dipoles plotted had a residual variance (vis a vis their component maps) below 40% (as we specified in the coarse grid search interactive window). Note that some components end up having the same x, y and z coordinates because of the coarseness of the grid. You may view individual components by pressing the "Plot one" button. The component index and its residual variance are then indicated in the top-left corner (see the dipplot() visualization tutorial in A3.5. below for further details).
Prior to fitting the component, press the "Plot map" button to show the component scalp map. The following window pops up.
186
This component, showing a clear left-right symmetric activity, cannot be accurately modeled using a single dipole. To fit this component using two dipoles constrained to be located symmetrically across the (corpus callosum) midline, set both dipole 1 and 2 to active and fit (by checking the relevant checkboxes in the pop window). Then press the "Fit selected dipole position(s)" button. If fitting fails, enter different starting positions (e.g., [-10 -68 17] for first dipole and [10 -68 17] for the second dipole and refit). When fitting is done, note the low residual variance for the two-dipole model on the top right corner of the interactive interface (0.53 %). Then, press the "Plot dipole(s)" button. The following plot pops up (see the dipplot() visualization tutorial in A3.5. below).
Note that the polarity of components is not fixed (but their orientation is): the product of the component scalp map value and the component activitation value (i.e., the back-projected contribution of the component to the scalp data) is in the original data units (e.g., microvolts), but the polarities of the scalp map and of the activation values are undetermined. For example, you may multiply both the scalp map and the component activity by -1 while preserving the component back-projection to the scalp (since the two negative factors cancel out). As a result, you may choose to flip the visualized dipole orientations (use the pop-up window for fitting, then press the "Flip in|out" button and then the "Plot dipole(s)" button to re-plot the dipoles with indicated orientations reversed. 187
A3.5. Automated dipole fitting Important note: when you are done, press the OK button in the interactive interface for dipole fitting. Do not press Cancel or close the window -- if you do, all the dipole locations that you have computed using this interface will be lost! Also, this DIPFIT menu is the only one that does not generate EEGLAB history. The first menu item, Tools > Locate dipoles using DIPFIT > Autofit component, uses the same method for dipole fitting but also generates an EEGLAB history command that can be re-used in batch scripts.
The function starts by scanning a 3-D grid to determine acceptable starting positions for each component. Then it uses the non-linear optimization algorithm to find the exact dipole position for each component. At the end of the procedure, the following window pops up.
The residual variance "RV: 2.75%" is shown below the component number "Comp: 5" on the right top corner indicates that the component being plotted is component 5 and that the residual variance is 2.75%. The diplot() function above 188
A3.6. Visualizing dipole models allows you to rotate the head model in 3-D with the mouse, plot MRI slices closest to the equivalent dipole, etc... (See the dipplot() visualization tutorial in A3.6. for more details.)
A plot pops-up. After 3D rotation it may look like the following plot.
Press the "Plot one" button. You may scroll through the components by pressing the "Next/Prev" buttons. Note that the closest MRI slices to the dipole being currently plotted are shown. Note also that if you do not select the option "Plot closest MRI slices" in the graphic interface, and then press the "Tight view" button in the dipplot window, you will be able to see the closest MRI slices at the location of the plotted dipole as shown below. Try moving the 3-D perspective of the tight view plot with the mouse, and/or selecting the three cardinal viewing angles (sagittal, coronal, top) using the lower left control buttons. 189
Note that it is not yet possible to toggle the dipole "stems" or "projection lines" on and off from within the graphic interface. You need to use the EEGLAB menu again, unselecting the relevant checkboxes. Also, it is not yet possible to use the subject's own anatomical MRI as background (it will be possible in the future upon completion of a EEG/MRI co-registration function as described below). Finally, again call menu item Tools > Locate dipoles using DIPFIT > Plot component dipoles. Select "Summary mode" and press "OK".
For comparison, using the spherical model, the location of the dipoles would have been as shown in the following picture. Notice the similarity of the talairach coordinates for the two models. Notice also that the BEM model does not overestimate dipole depth compare to the spherical model (which is usually the case when the BEM model mesh is too coarse). The MRI used to plot the spherical result is the average MNI brain (over about 150 subjects) whereas the MRI used to plot the BEM is the average MNI brain of a single subject (which was used to generate the model 190
The entry "Background image" contains the name of the MRI in which to plot dipoles. You may enter a custom MRI file assuming this file has been normalized to the MNI brain (see How to normalize a subject MR image to the MNI brain using SPM2. Note that the SPM2 package directory in your network must be in your Matlab path to be able to use the resulting file in EEGLAB. This is true both for the spherical head model (co-registered to the MNI brain) and the BEM model (based on the MNI brain). Note: Co-registration of the MNI average MR image with landmark electrode positions for the spherical model. To plot dipole locations in the average MR image (as in the dipplot() plots above), we co-registered the MNI average brain MRI with landmark electrode positions. For the average MRI image, we used a publicly available average brain image (average of 152 T1-weighted stereotaxic volumes made available by the ICBM project) from the MNI database (Montreal Neurological Institute (MNI), Quebec). Co-registration of the MNI brain and the standard EEG landmarks was accomplished automatically using fiducials and the Cz (vertex) electrode position, then slightly adjusted manually. The co-registration differs slightly from that used in DIPFIT1; dipoles are localized about 10 mm deeper than in DIPFIT1. Other coordinates (x,y) are nearly identical. We believe the co-registration in DIPFIT2 to be more accurate than in DIPFIT1. You may also see the co-registered model head sphere plotted over the MNI brain in the dipplot() window by pressing the "Mesh on" button in the BEM model below (here in 'tight view').
191
Or, for the spherical model below (in summary mode). Note that the sphere model is stretched in the visualization to the ellipsoid that best matches the shape of the headsurface of the average MRI.
192
A3.8. DIPFIT structure and functions % Find the best-fitting dipole for the ERP scalp map at this timepoint erp = mean(EEG.data(:,:,:), 3); [ dipole model TMPEEG] = dipfit_erpeeg(erp(:,pt100), EEG.chanlocs, 'settings', EEG.dipfit, 'threshold', 100); % Show dipole information (spherical or MNI coordinate based on the model selected) dipole % plot the dipole in 3-D pop_dipplot(TMPEEG, 1); % Plot the dipole plus the scalp map figure; pop_topoplot(TMPEEG,0,1, [ 'ERP 100ms, fit with a single dipole (RV ' num2str(dipole.rv*100,2) '%)'], 0, 1); Click here to download the script above.
EEG.dipfit.coord_transform Contains the talairach transformation matrix to align the user dataset channel location structure (EEG.chanlocs) with the selected head model. This is a length-9 vector [shiftx shifty shiftz pitch roll yaw scalex scaley scalez]. Type ">> help traditional" in Matlab for more information. EEG.dipfit.model EEG.dipfit.model.posxyz A structure array containing dipole information. Contains the 3-D position of the dipole(s). If a two-dipole model is used for a given component, each row of this array contains the location of one dipole. Contains 3-D moment of the dipole(s). If a two-dipole model is used for a given component, each row of this array contains the moment of one dipole. Gives the relative residual variance between the dipole potential distribution and th ecomponent potential distribution, ranging from 0 to 194
EEG.dipfit.model.momxyz
EEG.dipfit.model.rv
A3.9. DIPFIT validation study using the spherical head model 1. EEG.dipfit.model.active EEG.dipfit.model.select Remembers which dipole was active when the component model was last fitted. Remembers which dipole was selected when the component model was last fitted.
The main DIPFIT functions are: pop_dipfit_settings() Specify DIPFIT parameters, i.e. head model details.
pop_dipfit_gridsearch() Perform initial coarse DIPFIT grid scan to find an acceptable starting positions for further fine fitting. pop_dipfit_nonlinear() Perform fine model fitting via an interactive interface using non-linear optimization. Note: This function cannot be called from the command line. For automated processing, use the function below. pop_multifit() Command the DIPFIT modeling process from a single function. This function allows the user to set parameters, initialize locations on a coarse grid, then perform non-linear optimization as in the separate functions above. This function can be used to automate batch fitting of components from one or more subjects.
Auxiliary DIPFIT functions used by the functions above: dipfitdefs() defines a set of default values used in DIPFIT.
dipfit_gridsearch() same as pop_dipfit_batch() but does not use a pop-up window and assumes that the input data is an EEG dataset structure. dipfit_nonlinear() same as pop_dipfit_manual() but does not use a pop-up window and assumes that the input data is an EEG dataset structure. Note: There is no auxiliary "dipfit_settings" function, since selecting DIPFIT settings mostly involves copying default values to EEG.dipfit fields.
195
A3.10. Literature references Distances between equivalent dipole locations returned by DIPFIT1 and BESA(3.0) were less than 3 mm (left panel) Note: The outliers were infrequent failures to converge by either algorithm. Dipole angle differences were below 2 degrees (middle panel). Residual variances (mismatch between the component scalp map and the model pole projection) were near equal (right panel). A few dipoles were localized with residual variance below 15% by DIPFIT but not by BESA (4 of 213 components); a few others with residual variance below 15% by BESA but not by DIPFIT (8 of 213 components). Optimization nonlinearities may account for these small differences between the two algorithms, as the solution models used in the two programs are theoretically identical. The main advantage of using DIPFIT over BESA for localization of equivalent dipoles for independent component scalp maps is that it is integrated into Matlab and EEGLAB, and can be used in batch processing scripts (see A3.7 and A3.8). BESA has additional capabilities not relevant to DIPFIT. Succeeding versions of BESA did not allow a batch processing option.
196
BESA dipole localization applied to these component maps, accounted for each map with a single equivalent dipole in a three-shell spherical model with low residual variance (R.V.) Note that unlike in many BESA analyses, we rarely need to ignore signals at some scalp electrodes since ICA typically isolates artifactual signals into separate independent components, and independent components likely account mainly for activity with a connected synchronous cortical domain whose scalp projection should match that of a single equivalent dipole. (Note: This does not mean, however, that some independent components may be generated by tightly linked bilateral activity in domains joined through e.g. corpus callosum. In this case, the source may often be well modelled by two symmetricly placed equivalent dipoles).
197
198
In the first edit box, enter the indices of the components to be localized using BESA. The other edit boxes are self explanatory. In case you choose to export the electrode locations from EEGLAB (by leaving blank the 4th edit box), it is very important to check that the polar coordinates have not been shrunk by any other program (e.g., the Fz radius value should be 0.25). If you imported a file with 3-D coordinates into EEGLAB, that should not be an issue. Note that under Windows the last edit box will not appear. After pressing OK, the following text will be displayed on the command line:
Accessing directory... Exporting electrode locations ... Exporting component maps... Exporting parameter file... Writing macro file... NOW RUN BESA, PRESS "A" (for automatic processing) and enter filename "E:\besatmp\macro" Now, run BESA on your Windows machine. In BESA, type "A" and then enter the filename given above ("E:\besatmp\macro"). Dipole localization will be performed automatically. Since the number of characters in each BESA macro file is limited, the EEGLAB Matlab function generates many macro files that are called by parent macro files. In this way, up to 900 components can be localized at a time. Also note that minimizing the BESA window will greatly speed up the computation. 199
A4.4. Importing BESA component locations Occasionally BESA will not optimize the dipole location (e.g., when residual variance remains 98% or more). If this happens, simply rerun the macro corresponding to the badly localized component (for instance macro10.aut for component 10).
In the upper edit box, you must provide the location of the directory in which the dipole information has been saved by BESA. In the lower edit box, you can either (1) import dipoles and erase all previous information ("no" option), (2) append the newly computed information ("yes" option), or (3) only import dipoles for components that do not have yet associated dipoles ("componly" option). Press OK and the function will return information about the components that have been imported: Reading component 1 (1 dipoles) residual variance 2.09 % Reading component 2 (1 dipoles) residual variance 15.67 % Reading component 3 (1 dipoles) residual variance 1.94 % Reading component 4 (1 dipoles) residual variance 1.23 % Reading component 5 (1 dipoles) residual variance 3.49 % Reading component 6 (1 dipoles) residual variance 12.88 % Note: We usually only trust dipole locations with low residual variance (e.g., below 5%, though this figure may vary with number of channels, montage, etc.).
200
Here, the dipoles are plotted in 3-D (Note: Use the buttons on the bottom-left to select a specific view). Note that the background images were captured from BESA and the scaling was adjusted manually using visual fitting of a sphere mesh and of the BESA images (press the "Mesh on" button (lower left) to display the mesh sphere). Note that the barlength of the dipole varies with the absolute component amplitude. We also fit the head sphere model to an average-brain MRI average images (available for download from the ICBM project). MRI images were first shrunk along the X or Y axis to match the 3-D sphere mesh. We then changed the aspect ratio of the axis so that the MRI images' original aspect ratio was preserved (and the sphere mesh became an ellipsoid). A dipole location summary, plotted on the top of the MRI image, can be shown using menu item Tools > Localize dipoles using BESA > Plot dipoles on BESA head.
A4.6. Miscellany many more options can be specified and one or more equivalent dipoles can be plotted individually for each component.
A4.6. Miscellany
Using other dipole localization software You may use the besaexport() function to export the electrode localization file and the component activations, then try to localize dipoles using some other localization software. If you succeed in doing this, or if you write dedicated functions for this, please contact us. Localizing dipoles from ERP averages or continuous EEG Because of the theoretical and practical advantages of using ICA for source localization, we have only implemented equivalent dipole localization for independent components. However, localizing ERP or EEG time series would simply involve exporting the data to BESA. For instance, to export an ERP raw data file that BESA can read, type in >> ERP = mean(EEG.data,3); >> save -ascii ERP.raw ERP You may also use the electrode location file generated by besaexport().
202
203
A5.2.2. The associated pop_ function 2 - Additional parameters should be optional. If they are left blank in the pop_function call, a window should pop-up to ask for their values. 3 - The pop_function must return a 'string' containing the resulting call to the signal processing function (or in some cases to the pop_function). When this string is evaluated (using the Matlab function 'eval)'), the result must be the same as that of the pop_function itself, e.g. including all the parameters the user may enter into the pop window. This string will be pushed into the EEGLAB command history stack. 4 - By convention, if the function draws a figure, calling the function without enough arguments should pop up a new figure. However, with enough arguments (macro call), the function should directly draw the output graphic in the current figure (thus allowing the user to build multi-part figures, e.g. using 'sbplot()' commands). Writing the pop_function is easy and can usually be done in a few minutes if you just modify the pop_sample.m function source.
204
Possible fields for 'catch_strings' are: catch_strings.add_to_hist : add the LASTCOM variable content (if not empty) to the EEGLAB history catch_strings.store_and_hist : add the LASTCOM variable content (if not empty) to the EEGLAB history and store the EEG dataset in the ALLEEG variable. catch_strings.new_and_hist : add the LASTCOM variable content (if not empty) to the EEGLAB history and pop up a window for a new dataset.
A5.3.4. Plugin examples sub-directory of EEGLAB (or the EEGLAB directory where eeglab.m is located) and restart EEGLAB (click here to download this .m file). % eegplugin_pca() - pca plugin function eegplugin_pca( fig, try_strings, catch_strings); % create menu toolsmenu = findobj(fig, 'tag', 'tools'); submenu = uimenu( toolsmenu, 'label', 'PCA plugin'); % build command for menu callback cmd = [ '[tmp1 EEG.icawinv] = runpca(EEG.data(:,:));' ]; cmd = [ cmd 'EEG.icaweights = pinv(EEG.icawinv);' ]; cmd = [ cmd 'EEG.icasphere = eye(EEG.nbchan);' ]; cmd = [ cmd 'clear tmp1;' ]; finalcmd = [ try_strings.no_check cmd ]; finalcmd = [ finalcmd 'LASTCOM = ''' cmd ''';' ]; finalcmd = [ finalcmd catch_strings.store_and_hist ]; % add new submenu uimenu( submenu, 'label', 'Run PCA', 'callback', finalcmd); Note that as of EEGLAB v4.3 you may add plugin menu items to different EEGLAB menus. Above, we add a sub-menu to the Tools menu by specifying "'tag','tools'" in the findobj() call. If the specified tag were "import data", EEGLAB would add the plugin to the File > Import data menu. Using the tag "import epoch" would add the plugin to the File > Import epoch info menu. The tag "import event" would add the plugin to the File > Import event info menu. The tag "export" would add the plugin to the File > Export data menu. Finally, the tag "plot" would add the plugin to the Plot menu. (Note that the tag call should be in lower case). After installing the plugin above, a new EEGLAB menu item Tools > PCA plugin will be created. Use this menu item to run PCA on the current EEG dataset. The resulting PCA decomposition will be stored in place of the ICA decomposition. (Note: This is possible since both PCA and ICA are linear decompositions). See the EEGLAB DIPFIT plugin eegplugin_dipfit() for an example of a more elaborate plugin. Note: In EEGLAB4.3 we slightly modified how EEGLAB handles plugins. As a result, EEGLAB might not be compatible with earlier plugin functions. Subsequent versions of EEGLAB have and will support backwards compatibility of the plugin conventions.
206