Station 8 · Lesson 4

STUDY designs and variables

Core15 minBefore this lesson: Creating a STUDY (coming soon)Print the card
Starts from: animal_mine.study (D6) · Already applied: Creating a STUDYDownload the data (opens in a new tab)
Script to reach this state
MATLAB
[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;

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

A 2×2 grid. The columns animal and distractor are shaded in two colours, a within-subjects factor, with a double arrow between them labelled same participants: paired. The rows F and M are a between-subjects factor, separated by a dividing line labelled different participants: unpaired. Each cell holds small circles with participant codes: seven per row, and the same circles repeat in both columns.
Illustration, no data

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.

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

  1. Run the “Starting point” scriptA MATLAB file of commands that runs processing steps in order. if the STUDY is not open.
  2. Open Study then Select/Edit study design(s). The Edit STUDY design — pop_studydesign() window opens.
  3. The Design name list holds one design, STUDY.design 1. EEGLAB created it by itself when the STUDY was created.
  4. The Edit the independent variables for this design part has two lines: Categorical variable: condition - Values (animal - distractor) and Categorical 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

  1. Press New next to the design list. Design 2 appears with no variables.
  2. Press Rename, type image x gender in Study design name:, then Ok.
  3. In the variables part press New. The Add variable window opens.
  4. In Select independent variable choose condition. Both values, animal and distractor, are selected in Select variable values. Keep them selected, then Ok.
  5. Press New again, choose group, keep F and M selected, then Ok.

3. Create design 3 with one variable

  1. Press New next to the design list, then Rename it image only.
  2. Add one variable only: condition with both its values.

4. Choose the current design and save

  1. Click image x gender in the Design name list. The design selected when you press Ok becomes the current design.
  2. Keep Re-save STUDY file (if saved previously) ticked, so animal_mine.study is saved with its three designs.
  3. Press Ok. The command window shows Selecting STUDY design 2, then Resaving 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.

How do I write it as code?

The same steps in 25 lines of MATLAB
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;

Which value should I choose?

Suitable values for your analysis goal

Within subjects or between subjects?

Within subjectsBetween subjects
MeaningEach participant has every valueEach participant has one value
In D6Picture type: animal and distractorGender: F and M
Usually stored inconditiongroup
Testpaired: compares each participant with themselves, removing differences between peopleunpaired: compares two groups of different people
Statistical powerThe squared amplitude; how strong a signal is at a given frequency.Higher for the same numberLower, 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 questionDesignWhy
Does the ERPThe brain's average response to a given event across many trials. differ between animal pictures and the others?3, image onlyA 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 genderThe interaction between the two variables needs both in one design.
Does the ERP differ between women and men?A design with group onlyunpaired, 7 against 7.

How do I check it worked?

4 quick checks
  • The Design name list holds three designs: STUDY.design 1, image x gender and image only.
  • The script prints for design 2 the two lines condition paired: on and group paired: off.
  • The script prints Current design: 2.
  • After File then Clear study / Clear all and opening animal_mine.study again, the three designs are still in the window.
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 paired line reveals this: gender must be off.
  • 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 animal in 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.

How 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).

Where can I read more?

4 sources, official docs first

Written for EEGLAB 2026.1 · 2026-10-28

Need help?

Ask, share feedback, or report an error