Station 8 · Lesson 4
STUDY designs and variables
animal_mine.study (D6) · Already applied: Creating a STUDYDownload the data (opens in a new tab)Script to reach this state
[ALLEEG, EEG, CURRENTSET, ALLCOM] = eeglab;
% Folder for the course data (change it)
dataFolder = 'C:\Users\me\Documents\eeg-course';
% Download the ready Go-nogo STUDY once and unzip it in its own folder
zipDir = fullfile(dataFolder, 'animal_study');
studyFile = dir(fullfile(zipDir, '**', 'animal.study'));
if isempty(studyFile)
zipFile = fullfile(dataFolder, 'animal_study.zip');
websave(zipFile, 'https://sccn.ucsd.edu/eeglab/download/animal_study.zip');
unzip(zipFile, zipDir);
studyFile = dir(fullfile(zipDir, '**', 'animal.study'));
end
studyDir = studyFile(1).folder;
% Convert the old .dat data files to .fdt once: resaving them in their old format damages the data in EEGLAB 2026.1
setFiles = dir(fullfile(studyDir, '*', '*.set'));
for k = 1:numel(setFiles)
[~, base] = fileparts(setFiles(k).name);
folder = setFiles(k).folder;
if ~exist(fullfile(folder, [base '.fdt']), 'file')
TMP = pop_loadset('filename', setFiles(k).name, 'filepath', folder);
pop_saveset(TMP, 'filename', setFiles(k).name, 'filepath', folder, 'savemode', 'twofiles');
if exist(fullfile(folder, [base '.fdt']), 'file') && exist(fullfile(folder, [base '.dat']), 'file')
delete(fullfile(folder, [base '.dat']));
end
end
end
% Rebuild animal_mine.study (create-study lesson) if it is missing
if ~exist(fullfile(studyDir, 'animal_mine.study'), 'file')
gender = containers.Map( ...
{'cba','clm','ega','fsa','gro','hth','lmi','mba','mma','mta','pla','sce','sph','wpa'}, ...
{'F', 'F', 'F', 'M', 'M', 'M', 'F', 'F', 'M', 'F', 'M', 'F', 'M', 'M'});
files = dir(fullfile(studyDir, '*', '*.set'));
commands = {};
for k = 1:numel(files)
hdr = pop_loadset('filename', files(k).name, 'filepath', files(k).folder, 'loadmode', 'info');
subj = hdr.subject;
if isempty(subj), [~, subj] = fileparts(files(k).folder); end
cond = hdr.condition;
if isempty(cond)
if contains(files(k).name, 'distractor'), cond = 'distractor'; else, cond = 'animal'; end
end
if ~isKey(gender, lower(subj))
error('No gender entry for subject %s (%s)', subj, files(k).name);
end
commands{end+1} = {'index', k, 'load', fullfile(files(k).folder, files(k).name), ...
'subject', subj, 'condition', cond, 'group', gender(lower(subj))};
end
[STUDY, ALLEEG] = std_editset([], [], 'name', 'Go-nogo animal (mine)', ...
'task', 'Go-nogo categorization', 'commands', commands, 'updatedat', 'on');
STUDY = pop_savestudy(STUDY, ALLEEG, 'filename', 'animal_mine.study', ...
'filepath', studyDir, 'resavedatasets', 'on');
end
[STUDY, ALLEEG] = pop_loadstudy('filename', 'animal_mine.study', 'filepath', studyDir);
CURRENTSTUDY = 1; EEG = ALLEEG; CURRENTSET = 1:length(EEG);
eeglab redraw;Your browser's back button takes you to the exact place you were, so open anything you like.
The idea in brief
The STUDYAn EEGLAB structure that groups many participants' datasets for joint analysis. knows each file’s participantThe person whose data were recorded in the study., conditionAn experimental situation compared with others, such as familiar vs unfamiliar. and group. But it does not know your question. The designThe definition of which conditions and groups a STUDY compares. is the question written in EEGLAB’s terms: which variables you compare, which of their values, and which participants.
Before and after
Your next questions, each answered in its own section:
Why do I need this step?
The reasons in detail, and the terms you need
Every plot and every test in the next lessons works on the current design. If you pick the wrong design, EEGLAB plots and computes without an error, but for a question that is not yours.
The design also decides the kind of test: do the values come from the same participants (paired) or from different participants (unpaired)? This changes the statistical result a lot.
Why do I need this step?
Every plot and every test in the next lessons works on the current design. If you pick the wrong design, EEGLAB plots and computes without an error, but for a question that is not yours.
The design also decides the kind of test: do the values come from the same participants (paired) or from different participants (unpaired)? This changes the statistical result a lot.
How do I do it in EEGLAB?
14 steps in the menus
About the data (D6): the same animal_mine.study from the creation lesson. Every participant saw both kinds of picture (animal and distractor), so picture type is within subjects. Each participant has one gender (7 women and 7 men), so gender is between subjects. Together: a 2×2 mixed design.
1. Look at the design EEGLAB created
- Run the “Starting point” scriptA MATLAB file of commands that runs processing steps in order. if the STUDY is not open.
- Open Study then Select/Edit study design(s). The Edit STUDY design — pop_studydesign() window opens.
- The Design name list holds one design,
STUDY.design 1. EEGLAB created it by itself when the STUDY was created. - The Edit the independent variables for this design part has two lines:
Categorical variable: condition - Values (animal - distractor)andCategorical variable: group - Values (F - M). EEGLAB puts every standard variable with more than one value into the first design.
2. Create design 2 with a clear name
- Press New next to the design list.
Design 2appears with no variables. - Press Rename, type
image x genderin Study design name:, then Ok. - In the variables part press New. The Add variable window opens.
- In Select independent variable choose
condition. Both values,animalanddistractor, are selected in Select variable values. Keep them selected, then Ok. - Press New again, choose
group, keepFandMselected, then Ok.
3. Create design 3 with one variable
- Press New next to the design list, then Rename it
image only. - Add one variable only:
conditionwith both its values.
4. Choose the current design and save
- Click
image x genderin the Design name list. The design selected when you press Ok becomes the current design. - Keep Re-save STUDY file (if saved previously) ticked, so
animal_mine.studyis saved with its three designs. - Press Ok. The command window shows
Selecting STUDY design 2, thenResaving STUDY.
If the STUDY came from BIDS, show definitionBIDS
A standard for naming and organizing neuroimaging data files. (the previous lesson), gender is in a field called gender, not in group. gender appears in the same Select independent variable list, and works the same way.
If the STUDY came from BIDS, show definitionBIDS
A standard for naming and organizing neuroimaging data files. (the previous lesson), gender is in a field called gender, not in group. gender appears in the same Select independent variable list, and works the same way.
How do I do it in EEGLAB?
About the data (D6): the same animal_mine.study from the creation lesson. Every participant saw both kinds of picture (animal and distractor), so picture type is within subjects. Each participant has one gender (7 women and 7 men), so gender is between subjects. Together: a 2×2 mixed design.
1. Look at the design EEGLAB created
- Run the “Starting point” script if the STUDY is not open.
- Open Study then Select/Edit study design(s). The Edit STUDY design — pop_studydesign() window opens.
- The Design name list holds one design,
STUDY.design 1. EEGLAB created it by itself when the STUDY was created. - The Edit the independent variables for this design part has two lines:
Categorical variable: condition - Values (animal - distractor)andCategorical variable: group - Values (F - M). EEGLAB puts every standard variable with more than one value into the first design.
2. Create design 2 with a clear name
- Press New next to the design list.
Design 2appears with no variables. - Press Rename, type
image x genderin Study design name:, then Ok. - In the variables part press New. The Add variable window opens.
- In Select independent variable choose
condition. Both values,animalanddistractor, are selected in Select variable values. Keep them selected, then Ok. - Press New again, choose
group, keepFandMselected, then Ok.
3. Create design 3 with one variable
- Press New next to the design list, then Rename it
image only. - Add one variable only:
conditionwith both its values.
4. Choose the current design and save
- Click
image x genderin the Design name list. The design selected when you press Ok becomes the current design. - Keep Re-save STUDY file (if saved previously) ticked, so
animal_mine.studyis saved with its three designs. - Press Ok. The command window shows
Selecting STUDY design 2, thenResaving STUDY.
If the STUDY came from BIDS
(the previous lesson), gender is in a field called gender, not in group. gender appears in the same Select independent variable list, and works the same way.
If the STUDY came from BIDS
(the previous lesson), gender is in a field called gender, not in group. gender appears in the same Select independent variable list, and works the same way.
How do I write it as code?
The same steps in 25 lines of MATLAB
% STUDY and ALLEEG come from the starting point script
% Design 2: image (within subjects) x gender (between subjects)
STUDY = std_makedesign(STUDY, ALLEEG, 2, 'name', 'image x gender', ...
'variable1', 'condition', 'values1', {'animal', 'distractor'}, 'vartype1', 'categorical', ...
'variable2', 'group', 'values2', {'F', 'M'}, 'vartype2', 'categorical');
% Design 3: image only, all participants in one group
STUDY = std_makedesign(STUDY, ALLEEG, 3, 'name', 'image only', ...
'variable1', 'condition', 'values1', {'animal', 'distractor'}, 'vartype1', 'categorical', ...
'variable2', 'none');
% Make design 2 the current design and save
STUDY = std_selectdesign(STUDY, ALLEEG, 2);
STUDY = pop_savestudy(STUDY, ALLEEG, 'savemode', 'resave');
% Every design with its variables, values and pairing
for k = 1:numel(STUDY.design)
d = STUDY.design(k);
fprintf('Design %d: %s\n', k, d.name);
for v = 1:numel(d.variable)
if ~isempty(d.variable(v).label)
fprintf(' %-10s paired: %-4s values: %s\n', d.variable(v).label, ...
d.variable(v).pairing, strjoin(d.variable(v).value, ' '));
end
end
end
fprintf('Current design: %d\n', STUDY.currentdesign);
eeglab redraw;How do I write it as code?
% STUDY and ALLEEG come from the starting point script
% Design 2: image (within subjects) x gender (between subjects)
STUDY = std_makedesign(STUDY, ALLEEG, 2, 'name', 'image x gender', ...
'variable1', 'condition', 'values1', {'animal', 'distractor'}, 'vartype1', 'categorical', ...
'variable2', 'group', 'values2', {'F', 'M'}, 'vartype2', 'categorical');
% Design 3: image only, all participants in one group
STUDY = std_makedesign(STUDY, ALLEEG, 3, 'name', 'image only', ...
'variable1', 'condition', 'values1', {'animal', 'distractor'}, 'vartype1', 'categorical', ...
'variable2', 'none');
% Make design 2 the current design and save
STUDY = std_selectdesign(STUDY, ALLEEG, 2);
STUDY = pop_savestudy(STUDY, ALLEEG, 'savemode', 'resave');
% Every design with its variables, values and pairing
for k = 1:numel(STUDY.design)
d = STUDY.design(k);
fprintf('Design %d: %s\n', k, d.name);
for v = 1:numel(d.variable)
if ~isempty(d.variable(v).label)
fprintf(' %-10s paired: %-4s values: %s\n', d.variable(v).label, ...
d.variable(v).pairing, strjoin(d.variable(v).value, ' '));
end
end
end
fprintf('Current design: %d\n', STUDY.currentdesign);
eeglab redraw;Which value should I choose?
Suitable values for your analysis goal
Within subjects or between subjects?
| Within subjects | Between subjects | |
|---|---|---|
| Meaning | Each participant has every value | Each participant has one value |
| In D6 | Picture type: animal and distractor | Gender: F and M |
| Usually stored in | condition | group |
| Test | paired: compares each participant with themselves, removing differences between people | unpaired: compares two groups of different people |
| Statistical powerThe squared amplitude; how strong a signal is at a given frequency. | Higher for the same number | Lower, and needs more participants |
EEGLAB decides paired or unpaired by itself from the data: if every participant has every value, it is paired. The script prints the decision in the line paired: on or paired: off.
Which design for which question?
| Your question | Design | Why |
|---|---|---|
| Does the ERPThe brain's average response to a given event across many trials. differ between animal pictures and the others? | 3, image only | A direct paired test on 14 participants, and a plot with two curves instead of four. The 2×2 design also computes the main effect of picture, but it is harder to read. |
| Does the picture effect differ between women and men? | 2, image x gender | The interaction between the two variables needs both in one design. |
| Does the ERP differ between women and men? | A design with group only | unpaired, 7 against 7. |
Which value should I choose?
Within subjects or between subjects?
| Within subjects | Between subjects | |
|---|---|---|
| Meaning | Each participant has every value | Each participant has one value |
| In D6 | Picture type: animal and distractor | Gender: F and M |
| Usually stored in | condition | group |
| Test | paired: compares each participant with themselves, removing differences between people | unpaired: compares two groups of different people |
| Statistical power | Higher for the same number | Lower, and needs more participants |
EEGLAB decides paired or unpaired by itself from the data: if every participant has every value, it is paired. The script prints the decision in the line paired: on or paired: off.
Which design for which question?
| Your question | Design | Why |
|---|---|---|
| Does the ERP differ between animal pictures and the others? | 3, image only | A direct paired test on 14 participants, and a plot with two curves instead of four. The 2×2 design also computes the main effect of picture, but it is harder to read. |
| Does the picture effect differ between women and men? | 2, image x gender | The interaction between the two variables needs both in one design. |
| Does the ERP differ between women and men? | A design with group only | unpaired, 7 against 7. |
How do I check it worked?
4 quick checks
- The Design name list holds three designs:
STUDY.design 1,image x genderandimage only. - The script prints for design 2 the two lines
condition paired: onandgroup paired: off. - The script prints
Current design: 2. - After File then Clear study / Clear all and opening
animal_mine.studyagain, the three designs are still in the window.
About the data
Data: STUDY version: SCCN/Delorme. Original data: OpenNeuro ds002680 (CC0).
About the data
Data: STUDY version: SCCN/Delorme. Original data: OpenNeuro ds002680 (CC0).
How do I check it worked?
- The Design name list holds three designs:
STUDY.design 1,image x genderandimage only. - The script prints for design 2 the two lines
condition paired: onandgroup paired: off. - The script prints
Current design: 2. - After File then Clear study / Clear all and opening
animal_mine.studyagain, the three designs are still in the window.
About the data
Data: STUDY version: SCCN/Delorme. Original data: OpenNeuro ds002680 (CC0).
About the data
Data: STUDY version: SCCN/Delorme. Original data: OpenNeuro ds002680 (CC0).
What mistakes do people make?
5 mistakes and how to avoid them
- Forgetting to choose the current design. Plots and statistics work on the design selected in the list at the last Ok. The script prints
Current design. - Putting a between-subjectA comparison between different groups of participants. variable in condition. If you type gender as a condition, EEGLAB treats it as within subjects. The
pairedline reveals this: gender must beoff. - One design for every question. The 2×2 design answers the interaction, but the picture effect alone is simpler to read in a one-variable design: two curves instead of four, and a direct paired test.
- Selecting too few values. If you select only
animalin Select variable values, there is nothing to compare. Make sure both values are selected. - Thinking a new design needs a new precomputation. Since EEGLAB 2019 trials are saved one by one, and the design selects them at plot time. Do not precomputeComputing and saving ERPs or spectra for each participant and condition before STUDY plotting and statistics. again because of a new design.
What mistakes do people make?
- Forgetting to choose the current design. Plots and statistics work on the design selected in the list at the last Ok. The script prints
Current design. - Putting a between-subject variable in condition. If you type gender as a condition, EEGLAB treats it as within subjects. The
pairedline reveals this: gender must beoff. - One design for every question. The 2×2 design answers the interaction, but the picture effect alone is simpler to read in a one-variable design: two curves instead of four, and a direct paired test.
- Selecting too few values. If you select only
animalin Select variable values, there is nothing to compare. Make sure both values are selected. - Thinking a new design needs a new precomputation. Since EEGLAB 2019 trials are saved one by one, and the design selects them at plot time. Do not precompute again because of a new design.
Your browser doesn't allow saving progress. All lessons are open, but completion marks won't be saved.
Done. Your progress is saved in this browser.UndoHow do I write it in my paper?
A Methods template: edit the data, settings and versions to match what you ran
A template: edit the data, settings and versions to match what you ran.
A 2 × 2 mixed design was defined in the STUDY, with image category (animal, distractor) as a within-subject factor and gender ([7] female, [7] male) as a between-subject factor (std_makedesign, EEGLAB 2026.1).How do I write it in my paper?
A template: edit the data, settings and versions to match what you ran.
A 2 × 2 mixed design was defined in the STUDY, with image category (animal, distractor) as a within-subject factor and gender ([7] female, [7] male) as a between-subject factor (std_makedesign, EEGLAB 2026.1).Where can I read more?
4 sources, official docs first
- EEGLAB TutorialDocumentation10. Group analysis > c. STUDY designs
- EEGLAB TutorialDocumentation11. Scripting > Creating a STUDY
- Introduction to the EEGLAB STUDY and Study Design by Arnaud DelormeVideoFull video · 39:05
- Go-nogo categorization and detection task (OpenNeuro ds002680)participants.tsv
Written for EEGLAB 2026.1 · 2026-10-28
Going further
- EEGLAB Tutorial: https://eeglab.org/tutorials/10_Group_analysis/working_with_study_designs.html (10. Group analysis > c. STUDY designs)
- EEGLAB Tutorial: https://eeglab.org/tutorials/11_Scripting/command_line_study_functions.html (11. Scripting > Creating a STUDY)
- Introduction to the EEGLAB STUDY and Study Design by Arnaud Delorme: https://www.youtube.com/watch?v=HAGrNeh-kgA (Full video)
- Go-nogo categorization and detection task (OpenNeuro ds002680): https://openneuro.org/datasets/ds002680 (participants.tsv)
Need help?
Ask, share feedback, or report an error
- Report a scientific error · Needs a GitHub account. Don't have one? Use "Share your thoughts".