canlab_dataset methods, organized by area

May 7, 2026 ยท View on GitHub

canlab_dataset is a generic subject-by-variable container for behavioral data and fMRI/study meta-data. It is not a subclass of image_vector; it organizes data at five potential levels of analysis: Experiment, Subject, Event (e.g. trial-level), Sub-Event, and Continuous. Each level stores a names, type, units, descrip, data, and textdata field, with cell arrays of one cell per subject for the trial- and continuous-level data. The most-used levels are Subj_Level (one row per subject) and Event_Level (one cell per subject, each with a trials-by-variables matrix), which together support multi-level mixed-effects analyses.

Constructing with the 'fmri' keyword pre-populates the standard demographic and fMRI event-level variable names (SessionNumber, EventOnsetTime, etc.) for fMRI design-matrix generation. Type methods(canlab_dataset) in MATLAB for the live list.

Properties

PropertyDescription
DescriptionStruct with Experiment_Name, Missing_Values, and per-level descriptive text
Subj_LevelStruct with id, names, type, units, descrip, data, textdata for subject-level variables
Event_LevelStruct (same fields, no id) for event/trial-level variables; data is a cell-per-subject
Sub_Event_LevelSame shape as Event_Level, for variable-size sub-event observations per trial
ContinuousSame shape as Event_Level, for time-series samples per subject
wh_keepStruct with logical inclusion masks for filtering subjects/events

Basic operations

MethodFromOne-liner
canlab_dataset@canlab_datasetConstructor; 'fmri' flag adds standard demographic + event variable names
add_vars@canlab_datasetAdd or replace one or more variables at a given level
concatenate@canlab_datasetFlatten Subject- and Event-level data across all subjects
replace_values@canlab_datasetReplace values matching a predicate with a fill value
select_trials_and_subjects@canlab_datasetFilter events by string-pattern match on a text variable; optionally extract another
spm2canlab_dataset@canlab_datasetPull Event_Level onsets/durations from a subject's SPM.mat

Display and visualization

MethodFromOne-liner
bars@canlab_datasetBar plot (wraps barplot_columns) for selected variables
histogram@canlab_datasetHistogram of one variable, subject- or event-level
plot_var@canlab_datasetMean and SE of a variable across events per subject
scatterplot@canlab_datasetScatter of two variables, single- or multi-line per subject
scattermatrix@canlab_datasetScatterplot matrix of pairwise event-level variables

Statistics

MethodFromOne-liner
glm@canlab_datasetPredict Y from X with a single-level GLM
glm_multilevel@canlab_datasetMultilevel (subject-as-random-effect) GLM
mediation@canlab_datasetSingle- or multilevel mediation (wraps mediation toolbox)
ttest2@canlab_datasetTwo-sample t-test on a subject-level variable across two wh_keep groups
correlation@canlab_datasetPairwise correlations between two variables (raw and within-subject-centered)
reliability@canlab_datasetOdd/even Spearman-Brown reliability of a within-subject variable

Tables and descriptives

MethodFromOne-liner
print_summary@canlab_datasetPrint summaries for every (or specified) variable
list_variables@canlab_datasetList variable names and descriptions
get_descriptives@canlab_datasetReturn descriptive stats per variable, per level

Data extraction

MethodFromOne-liner
get_var@canlab_datasetExtract one or more variables in matrix and per-subject cell formats; supports conditional filters

Misc utilities (I/O)

MethodFromOne-liner
read_from_excel@canlab_datasetRead from an Excel design + per-subject files into the dataset
write_text@canlab_datasetFlatten and write Subject- and Event-level data to text files