Theory of Mind and Pain Matrix Localizer (Narratives)

This script will localize theory-of-mind network areas and pain matrix areas by contrasting activation during stories in which characters are suffering from emotional pain (EP) and physical pain (PP). There are blocks of emotional pain (EP) stories in which a story is told involving a false belief, which is presented for 12 seconds. Rhen a response prompt appears for 4 seconds and the subjects is required to rank the protagonists’ level of suffering.

To run this script, you need Matlab and the PsychToolbox.

Note: If you use this localizer, please credit Nir Jacoby, Emile Bruneau, Jorie Koster-Hale, and Rebecca Saxe.


  • subjID: STRING The string you wish to use to identify the participant. “PI name”_”study name”_”participant number” is a common convention. This will be the name used to save the files.
  • run: NUMBER The current run number. (e.g., 1).

Example usage: 


The script outputs a behavioural file into the behavioural directory. This contains information about the IPS of the scan, when stories were presented, reaction time, and response info. It also contains information necessary to perform the analysis with SPM. The file is saved as

In the event of a crash, the script creates a running behavioural file of partial data after each trial.


  1. EP — Emotional Pain stories (10 total)
  2. PP — Physical Pain stories (10 total)


The run length can be calculated according to the following:
(trials per run)*(fixation duration + story duration)+(fixation duration)

The phrases used above are related to the variable values according to the following:
trials per run = trialsPerRun
fixation duration = fixDuration
story duration = storyDur

The default configuration is:
(10 trials per run) * (12 sec fixation + 16 sec story) + (12 sec fixation) =
10 * (12 + 16) + 12 = 292 seconds, 146 ips (given 2 sec TR).


Note 1
Make sure to change the inputs in the ‘Variables unique to scanner/computer’ section of the script.

Note 2
The use of intersect(89:92, find(keyCode)) determines if the keystroke found by KbCheck is one of the proper response set. Of course, these intersection values are a consequence of the workings of our MRI response button. Your response button may differ. Use KbCheck() to determine which button pushes from the response box correspond to numbers 1:4. Otherwise, you may not retain any behavioural data.

Note 3
For simplicity, we have set up the experiment so that the order of items and conditions is identical for every subject – they see design 1 in run 1, with stimuli 1 – 5 form each condition, in that order. In our own research, we typically counterbalance the order of items within a run, and the order of designs across runs, across subjects (so half of our participants see design 1 in run 2). If you are comfortable enough with matlab, we encourage you to add this counterbalancing back into the experiment – and make sure to save separate variables for each subject tracking the order of items and conditions across runs.

We analyze this experiment by modelling each trial as a block with a boxcar lasting 16 seconds, during the whole period from the initial presentation of the story to the end of the response presentation. These boxcars are flanked by non-jittered rest periods of 12 seconds each (the fixation duration in the script).

Analysis consists of five primary steps:

  1. Motion correction by rigid rotation and translation about the 6 orthogonal axes of motion.
  2. (optional) Normalization to the MNI template.
  3. Smoothing, FWHM, 5 mm smoothing kernel if normalization has been performed, 8 mm otherwise.
  4. Modeling
    • Each condition in each run gets a parameter, a boxcar plot convolved with the standard HRF.
    • The data is high pass filtered (filter frequency is 128 seconds per cycle)
  5. A simple contrast and a map of t-test t values is produced for analysis in each subject. We look for activations thresholded at p < 0.001 (voxelwise) with a minimum extent threshold of 10 contiguous voxels.

Random effects analyses show significant results with n > 10 participants, though it should be evident that the experiment is working after 3 – 5 individuals.

SPM Parameters

If using scripts to automate data analysis, these parameters are set in the SPM.mat file prior to modeling or design matrix configuration.

SPM.xGX.iGXcalc = {‘Scaling’} — global normalization: OPTIONS:’Scaling’|’None’ SPM.xX.K.HParam = filter_frequency — high-pass filter cutoff (secs) [Inf = no filtering] SPM.xVi.form = ‘none’ — intrinsic autocorrelations: OPTIONS: ‘none’|’AR(1) + w’ = ‘hrf’ — Basis function name SPM.xBF.T0 = 8 — reference time bin – samples to the middle of TR SPM.xBF.UNITS = ‘scans’ — OPTIONS: ‘scans’|’secs’ for onsets SPM.xBF.Volterra = 1 — OPTIONS: 1|2 = order of convolution; 1 = no Volterra

Download & Installation

  1. To download the script and its associated stimuli, click here [version: November 25, 2015]
  2. Extract the folder.
  3. From within matlab, cd into the extracted folder
  4. Type ‘setup’ and follow the onscreen instructions