fmri_data.ttest

May 7, 2026 · View on GitHub

← back to fmri_data methods · Object methods index · Recasting objects

One-sample t-test on every voxel of an fmri_data object. Returns a statistic_image carrying t-statistics, two-tailed p-values, standard errors, per-voxel sample sizes, and degrees of freedom — the canonical group-level summary map for a set of contrast images. Optionally thresholds the result before returning it.

Code map

ttest code map

Editable PowerPoint version

Usage

statsimg = ttest(fmridat)
statsimg = ttest(fmridat, pvalthreshold, thresh_type)

For a two-sample t-test, use fmri_data.regress with a group indicator regressor.

Inputs

ArgumentTypeDescription
fmridatfmri_dataObject with one image per row of the (eventual) test. fmridat.dat is [voxels × images].
pvalthresholdnumericOptional. p-value threshold (e.g. .05, .001, or a vector like [.001 .01 .05]).
thresh_typestringOptional. 'uncorrected', 'fwe', or 'fdr'. Required if pvalthreshold is supplied.

Outputs

FieldTypeDescription
statsimg.datcolumnt-statistic per voxel.
statsimg.pcolumnTwo-tailed p-value per voxel.
statsimg.stecolumnStandard error per voxel.
statsimg.NcolumnNumber of non-NaN, non-zero observations per voxel.
statsimg.dfescalarDegrees of freedom (n - 1).
statsimg.volInfostructInherited from fmridat.mask.volInfo so spatial position is preserved.

The returned object is a statistic_image (subclass of image_vector) and can be re-thresholded with statistic_image.threshold, turned into a region object with region(...), displayed with montage, surface, or orthviews, or registered into a layered montage with canlab_results_fmridisplay.

Notes

  • Two-tailed p-values are computed inside the statistic_image constructor.
  • Voxels that are all-NaN or all-zero get p = 1 and t = 0 so they will never survive a threshold.
  • For more elaborate designs (covariates, contrasts, robust regression), use fmri_data.regress instead.

Example: one-sample group analysis on the emotion-regulation sample

% Load 30 single-subject contrast images
imgs = load_image_set('emotionreg');

% QC: per-image montage and summary plots
slices(imgs);
plot(imgs);

% Voxelwise one-sample t-test (unthresholded)
t = ttest(imgs);

% Quick look at the unthresholded map
display_slices(t, 'axial'); colormap summer; colorbar;

% Layered slices + surfaces with registered handles
o2 = canlab_results_fmridisplay(t, 'full');
o2 = removeblobs(o2);

% Threshold and re-display the same montage
t  = threshold(t, .005, 'unc');
o2 = addblobs(o2, region(t), 'nolegend');
orthviews(t);

% Re-threshold at q < .05 FDR and tabulate clusters
t = threshold(t, .05, 'fdr');
r = table(t);
montage(r, 'regioncenters', 'colormap');

See also