SPM DCM demo
In this demo we will specify one subjectâ€™s dynamic causal model, compare several models across participants, and look at posterior estimates of parameters (connectivity weights).
With DCM for evoked responses one typically models smooth ERP/ERF deflections. The dataset prepared for you has been lowpass filtered with a 48Hz cutoff.
Now you can specify one DCM model for this subjectâ€™s data:

In the Menu window press the DCM button â€“ this will open a new window called â€śDCM for M/EEGâ€ť. A figure of this panel has been included at the end of the tutorial.

Click â€śnew dataâ€ť and select the file containing lowpass filtered data (â€śfwmPapMcbdspmeeg_run_01_sss.matâ€ť)

Select â€śMEGâ€ť as the modality to be modeled. The new popup window shows (on the left) the eventrelated field averaged across trials for single channels (separate lines), and (on the right) the same data in columns.

As we will model the evoked potentials (as opposed to e.g., induced responses or crossspectral density), in the first dropdown menu please select â€śERPâ€ť

We will want to use the standard neuronal model based on neural masses with three subpopulations per region, so in the second dropdown menu select â€śERPâ€ť

We will model the first 400ms of the data (time window: 1 â€“ 400ms) and use a Hanning window. This will force the signals to decay towards the window edges.

In the data file, the conditions are ordered as follows: 1 â€“ famous faces, 2 â€“ unfamiliar faces, 3 â€“ scrambled faces. You can access this information by loading the data into SPM (in Matlab: â€śD = spm_eeg_load(filename)â€ť) and inspecting the â€śD.conditionsâ€ť array. As we want to model the main effect of faces, under â€śbetweentrial effectsâ€ť we can leave all three conditions (i.e. [1 2 3]), and specify the effect in the window below as [1 1 0] â€“ this will model the modulatory effects of face presentation, with â€śscrambled facesâ€ť treated as a baseline. You can call this effect â€śfacesâ€ť in the window on the left.

There are several options to reduce the data before modeling. First, you can remove a number of subsequent polynomial trends (linear, quadratic, cubic etc.) from the data. Second, you can only use subsampled data (e.g., every 2nd or every 4th datapoint). Finally, you can model a limited number of spatiotemporal modes explaining the most variance in your data. Here, use linear detrending (1), no subsampling (1) and 8 eigenmodes.

Click the red arrow to continue  this will activate the next part of the â€śDCM for M/EEGâ€ť window where you will be able to specify the electromagnetic model.

We will use the equivalent current dipole (ECD) spatial model with the following dipoles and their prior locations:
 rOFA [27 93 6]
 lOFA [36 84 12]
 rFFA [39 57 15]
 lFFA [36 48 24]
 rSTS [51 39 18]

As we are modeling a visual response, use a prior onset of sensory input at 70ms with a standard deviation of 16ms determining its duration.

Click the red arrow to continue. The data youâ€™re working with should have a prespecified head model (mapping from sourcespace to sensorspace). If the head model for this dataset hasnâ€™t been computed, SPM will ask you to do it now. Letâ€™s use the â€śtemplateâ€ť model with a â€śnormalâ€ť cortical mesh. To specify Nasion position, click â€śselectâ€ť â€“> â€śnasâ€ť > â€śOKâ€ť. Please do the same for LPA and RPA. Use headshape points. After a couple of minutes, click on â€śdisplay MEGâ€ť, then use a â€ś3shell sphereâ€ť EEG head model and a â€śsingle shellâ€ť MEG head model and again click on â€śdisplay MEGâ€ť. This completes the head model.

You should now be able to define the neuronal model. We would like to compare several alternative models. However, depending on the number of sources, connections and effects to be modeled, the inversion of each model can take from several minutes up to a couple hours. For now letâ€™s define a single model and save it. This is the model that we would like to define:

In terms of the A (baseline connectivity), B (modulatory connectivity) and C (input) matrices, this model can be decomposed into the connections listed below. You can also turn to the last page of this instruction sheet to see if you have correctly defined the model.
A{1}  Forward: (3,1) rOFA > rFFA (4,2) lOFA > lFFA (5,1) rOFA > rSTS (5,3) rFFA > rSTS
A{2}  Backward: (1,3) rFFA > rOFA (2,4) lFFA > lOFA (1,5) rSTS > rOFA (3,5) rSTS > rFFA
A{3}  Lateral: (2,1) rOFA > lOFA (1,2) lOFA > rOFA (4,3) rFFA > lFFA (3,4) lFFA > rFFA
B{1} â€“ Modulatory: (3,1) rOFA > rFFA (4,2) lOFA > lFFA (5,1) rOFA > rSTS (1,3) rFFA > rOFA (2,4) lFFA > lOFA (1,5) rSTS > rOFA
C â€“ Input: (1) rOFA (2) lOFA

Finally, we do not impose constraints on dipolar symmetry, optimise source location, lock trialspecific effects or assume trialspecific inputs. You can ignore the wavelet options â€“ these are used when modeling spectral responses (e.g., with CSD or IND models).

You can now save this model definition as a file, e.g., as â€śDCM_inpO1F0_modF1B1â€ť.

Now letâ€™s modify this model by e.g., adding two more input connections to bilateral FFA and save it under another filename, e.g., as â€śDCM_inpO1F1_modF1B1â€ť. Loading the previous model will restore the previously defined connectivity structure.

As model inversion can take some time (several minutes up to a couple hours), instead of inverting the model now you can find all inverted models in your folder â€śPrecalc_DCMsâ€ť. Still, to see how model inversion looks like, you can now press â€śinvert DCMâ€ť. This will â€“ after some time â€“ save the posterior parameter estimates and other statistics (crucially, the freeenergy approximation to model evidence, which will be used to compare different models) in your DCM file. If you have already inverted some models, SPM will ask you if you would like to initialise the inversion with previous posteriors, priors or hyperpriors â€“ usually you should answer â€śnoâ€ť, unless you would like to e.g., user one subjectâ€™s posteriors as another subjectâ€™s priors. Then DCM will start to be estimated using an iterative model inversion technique called Variational Bayes. Usually the model inversion would converge (i.e., achieve the best model fit for the specified model structure) after several iterations. Below you can see an example of a window (updated with every iteration) showing the progress of model inversion. The panel at the top shows the estimated source activity for different neuronal sources and populations (separate lines) and experimental conditions (separate subplots). The middle panel shows the observed (dashed lines) and modelpredicted (solid lines) responses for all experimental conditions (separate subplots), with different colours representing different spatiotemporal modes. The lower panels show updates in parameter space (left: neuronal parameters of the model; right: spatial parameters of the model). After each iteration, Matlab will also display the current update of the freeenergy approximation to model evidence. If no convergence has been reached after 64 iterations, model inversion will stop automatically and save its current posterior parameter and model evidence estimates. You can press ctrl+c in Matlab to interrupt model inversion and load one of the already inverted models.
To compare different models and select the winning model, you should use Bayesian model selection. You will find a â€śBMSâ€ť button at the bottom of the â€śDCM for M/EEGâ€ť window. Also, you will find some inverted DCMs for several subjects in your folder.

You can load the â€śBMS_batch.matâ€ť file to use the prespecified batch structure. To specify it manually, first you will need to create and select a directory where you will store your BMS results.

Under â€śDataâ€ť, click â€śNew: Subjectâ€ť. Under â€śSubjectâ€ť, click â€śNew: Sessionâ€ť. Now select all the models that you would like to compare. Repeat this procedure for each subject, selecting the same models (and in the same order) for all subjects.

Select your inference method â€“ fixed effects will assume that single subjects have the same underlying winning model; random effects will assume that single subjects can differ with respect to their winning model. Although the random effects approach is often chosen as it provides better protection against outliers, the fixed effects approach is commonly used in studies using standard participant samples and sensory paradigms. Here please select the â€śrandom effectsâ€ť option.

Family inference is useful when dealing with large, structured model spaces. Here, for instance, we can divide our 9 models into 3 families with different inputs (OFA, FFA, or both) or into 3 families with different modulation patterns (forward, backward, or both). Letâ€™s look at the latter model space partition. To perform family inference, click â€śConstruct familyâ€ť, create 3 new families, assign 3 models to each family and name them accordingly. If you do not wish to perform family inference, this step can be skipped by pressing the green button directly.

Press the green button to run BMS. After several seconds, you should see a new plot with expected probability and exceedance probability for each family of models. Exceedance probability is the probability of each model being better than any other model. In the plot below on the left, you can see that the models with both forward and backward connections modulated by face presentation have higher evidence than the remaining models. The plot on the right shows single models.
Parameter inference
 First, you can inspect a single model from a single participant using the GUI. To do this, in Matlab go to the â€śprecomputedâ€ť directory, and in the GUI load one of Subject 15â€™s inverted models. Then use the dropdown menu in the lower left corner of the â€śDCM for M/EEGâ€ť window to view the results. For example, selecting â€śERPs (mode)â€ť will plot the observed (dashed lines) and modelpredicted (solid lines) responses for all experimental conditions and spatiotemporal modes you have modeled. â€śERPs (sources)â€ť will plot the activity modeled for each neuronal source, including its different neuronal populations â€“ in case of an ERP neuronal model, the solid lines will represent superficial pyramidal cells which contribute most strongly to the measured signals. Further options include e.g., â€śCoupling (B)â€ť which will show you posterior estimates of modulatory connectivity parameters (the B matrix), and â€śtrialspecific effectsâ€ť (see below) which will show you connection strengths for different conditions (here 100% represents the connection strength for the baseline condition). Finally, â€śResponse (image)â€ť will show you the model fits across all modeled time points and sensors. This is the end of our demo.
 To formally test whether your posterior parameter estimates are significant, you can use Bayesian parameter averaging (spm_dcm_average) of the winning model across all participants and inspect the posterior estimates and probabilities of parameters (e.g., DCM.Ep.B{1}(1,3) and DCM.Pp.B{1}(1,3) will give you the posterior estimate and probability of the strength of a forward modulatory connection from region 3 to region 1). In a random effects context, you can load the posterior estimates of parameters from single subjectsâ€™ DCM structures â€“ here, this would be one value of DCM.Ep.B{1}(1,3) per subject â€“ to perform a onesample ttest.
More examples and tutorials can be found in the SPM12 manual.