Skip to content

Example Scripts

Eric Fields edited this page Jun 28, 2018 · 17 revisions

Contents

Fully within-subjects designs

Below are sample scripts for a full mass univariate analyses for a within-subjects design. These scripts assume that you have processed your data in EEGLAB and ERPLAB and have ERPLAB .erp files with the averaged ERP for each subject. If you have processed your data via an alternative route, see the Mass Univariate Toolbox documentation on how to make a GND file.

The design used in these examples is as follows: You are interested in the effects of semantic priming and corpus frequency on the ERPs elicited by words. Your study uses a 3 (Frequency: low, medium, high) X 2 (Priming: primed, unprimed) design and you want to conduct an ANOVA that will test the two main effects as well as the two-way interaction.

Within each subject's ERPset, the bins representing the six relevant conditions are as follows:

  • Bin1: unprimed low frequency
  • Bin2: unprimed medium frequency
  • Bin3: unprimed high frequency
  • Bin4: primed low frequency
  • Bin5: primed medium frequency
  • Bin6: primed high frequency

Making the GND struct

First you need to import your .erp files into a GND struct that will be used for analysis. This script creates a GND and downsamples it from 512Hz to 128Hz.

%Make sure all EEGLAB functions are on the MATLAB path
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
close all;

%ERP sets to include in GND
subs = {'filepath\sub1.erp', ...
        'filepath\sub2.erp', ...
        'filepath\sub3.erp', ...
        'filepath\sub4.erp', ...
        'filepath\sub5.erp'};

%Create a GND structure
GND = erplab2GND(subs, ...
                'use_bins', 1:6, ...
                'exclude_chans', {'VEOG','HEOG'}, ...
                'exp_name', 'FreqPrime', ...
                'out_fname', 'FreqPrime.GND');
 
%Add bins for following up main effects of Frequency
GND = bin_mean(GND, 1, 4, 'Low Frequency'); %bin 7
GND = bin_mean(GND, 2, 5, 'Medium Frequency'); %bin 8
GND = bin_mean(GND, 3, 6, 'High Frequency'); %bin 9

%Downsample the data in the GND from 512Hz to 128 Hz using boxcar filter
%Filter averages together each time point with the surrounding 2 time
%points
GND = decimateGND(GND, 4, 'boxcar', [-200 -1], 'yes', 0);

% Visually examine data
gui_erp(GND)

Mass univariate analysis

%% Set-up

%Make sure all EEGLAB functions are on the MATLAB path
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
close all;

%Load GND file
load('filepath/FreqPrime.GND', '-mat');

%Define some variables
n_perm = 1e4;
time_wind = [250 550];
chan_hood = 75;

%% Full factorial design

GND = FclustGND(GND, ...
                'bins', 1:6, ...  
                'factor_names', {'Frequency', 'Priming'}, ...  
                'factor_levels', [3, 2], ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_factorial.xlsx');
            
%% Pair-wise follow-ups for Frequency main effect

%Low Frequency vs Medium Frequency
GND = FclustGND(GND, 'bins', [7, 8], ...  
                'factor_names', 'Frequency', ...  
                'factor_levels', 2, ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_LowVsMed.xlsx');
%Low Frequency vs High Frequency
GND = FclustGND(GND, 'bins', [7, 9], ...  
                'factor_names', 'Frequency', ...  
                'factor_levels', 2, ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_LowVsHigh.xlsx');
%Medium Frequency vs HighFrequency
GND = FclustGND(GND, 'bins', [8, 9], ...  
                'factor_names', 'Frequency', ...  
                'factor_levels', 2, ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_MedVsHigh.xlsx');
            
%% Interaction follow-ups: Effect of priming at each level of frequency

%Low frequency
GND = FclustGND(GND, 'bins', [1, 4], ...  
                'factor_names', 'Priming', ...  
                'factor_levels', 2, ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_Priming_LowFreq.xlsx');
%Medium frequency
GND = FclustGND(GND, 'bins', [2, 5], ...  
                'factor_names', 'Priming', ...  
                'factor_levels', 2, ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_Priming_MedFreq.xlsx');
%High frequency
GND = FclustGND(GND, 'bins', [3, 6], ...  
                'factor_names', 'Priming', ...  
                'factor_levels', 2, ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_Priming_HighFreq.xlsx');

Designs with a between-subjects factor

Below are example scripts for a mass univariate analysis of a design with a between subjects factor. The within-subjects component of the design is the Frequency X Priming paradigms described above. In this section, we are further concerned with the effects of age in this paradigm, and data has been collected from both young adults and older adults.

Making the GRP struct

Analyses with a between-subjects factor use the GRP struct. The GRP struct is created by first creating a GND for each group, and then combining them.

%Make sure all EEGLAB functions are on the MATLAB path
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
close all;

%% Make young adults GND

%ERP sets to include in GND
subs = {'filepath\subY1.erp', ...
        'filepath\subY2.erp', ...
        'filepath\subY3.erp', ...
        'filepath\subY4.erp', ...
        'filepath\subY5.erp'};

%Create a GND structure
GND_Y = erplab2GND(subs, ...
                   'use_bins', 1:6, ...
                   'exclude_chans',{'VEOG','HEOG'}, ...
                   'exp_name','FreqPrime', ...
                   'out_fname', 'FreqPrime_young.GND');
 
%Add bins for following up main effects of Frequency
GND_Y = bin_mean(GND_Y, 1, 4, 'Low Frequency'); %bin 7
GND_Y = bin_mean(GND_Y, 2, 5, 'Medium Frequency'); %bin 8
GND_Y = bin_mean(GND_Y, 3, 6, 'High Frequency'); %bin 9

%Downsample the data in the GND from 512Hz to 128 Hz using boxcar filter
%Filter averages together each time point with the surrounding 2 time
%points
GND_Y = decimateGND(GND_Y, 4, 'boxcar', [-200 -1], 'yes', 0);

% Visually examine data
gui_erp(GND_Y)


%% Make older adults GND

%ERP sets to include in GND
subs = {'filepath\subO1.erp', ...
        'filepath\subO2.erp', ...
        'filepath\subO3.erp', ...
        'filepath\subO4.erp', ...
        'filepath\subO5.erp'};

%Create a GND structure
GND_O = erplab2GND(subs, ...
                   'use_bins', 1:6, ...
                   'exclude_chans',{'VEOG','HEOG'}, ...
                   'exp_name','FreqPrime', ...
                   'out_fname', 'FreqPrime_old.GND');
 
%Add bins for following up main effects of Frequency
GND_O = bin_mean(GND_O, 1, 4, 'Low Frequency'); %bin 7
GND_O = bin_mean(GND_O, 2, 5, 'Medium Frequency'); %bin 8
GND_O = bin_mean(GND_O, 3, 6, 'High Frequency'); %bin 9

%Downsample the data in the GND from 512Hz to 128 Hz using boxcar filter
%Filter averages together each time point with the surrounding 2 time
%points
GND_O = decimateGND(GND_O, 4, 'boxcar', [-200 -1], 'yes', 0);

% Visually examine data
gui_erp(GND_O)

%% Make GRP

GRP = GNDs2GRP('gui', 'out_fname', 'FreqPrime.GRP');

Mass univariate analysis

%% Set-up

%Make sure all EEGLAB functions are on the MATLAB path
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
close all;

%Load GRP
load('filepath/FreqPrime.GRP', '-mat');

%Define some variables
n_perm = 1e4;
time_wind = [250 550];
chan_hood = 75;

%% Full design

GRP = FclustGRP(GRP, ...
                'bg_factor_name', 'Age', ...
                'bins', 1:6, ...
                'wg_factor_names', {'Frequency', 'Priming'}, ...
                'wg_factor_levels', [3, 2], ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GRP', 'yes', ...
                'output_file', 'FreqPrime_FullDesign.xlsx');
            
            
%% Within-group follow-ups

%Young
load('FrePrim_young.GND', '-mat');
GND = FclustGND(GND, ...
                'bins', 1:6, ...  
                'factor_names', {'Frequency', 'Priming'}, ...  
                'factor_levels', [3, 2], ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_young.xlsx');
            
%Old
load('FrePrim_old.GND', '-mat');
GND = FclustGND(GND, ...
                'bins', 1:6, ...  
                'factor_names', {'Frequency', 'Priming'}, ...  
                'factor_levels', [3, 2], ...
                'time_wind', time_wind, ...
                'chan_hood', chan_hood, ...
                'n_perm', n_perm, ...
                'save_GND', 'yes', ...
                'output_file', 'FreqPrime_young.xlsx');

For further follow-up within each group, see the within-subjects script above.

Clone this wiki locally