Skip to content

Commit 44b9bd3

Browse files
committed
Example: DCM_ERP demo
1 parent 51dc39c commit 44b9bd3

1 file changed

Lines changed: 108 additions & 0 deletions

File tree

examples/DCM_ERP.py

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
"""
2+
analyse some ERP data (mismatch negativity ERP SPM file from SPM-webpages)
3+
This is an example batch script to analyse two evoked responses with an
4+
assumed 5 sources.
5+
To try this out on your data (the date of this example don't exist in your SPM8 distribution),
6+
you have to change 'Pbase' to your own analysis-directory, and choose a name ('DCM.xY.Dfile')
7+
of an existing SPM for M/EEG-file with at least two evoked responses.
8+
"""
9+
import os
10+
import spm
11+
12+
num = spm.Array.from_any
13+
14+
# Please replace filenames etc. by your own.
15+
# ----------------------------------------------------------------------
16+
spm.spm('defaults', 'EEG')
17+
18+
# Data and analysis directories
19+
# ----------------------------------------------------------------------
20+
21+
Pbase = os.path.dirname(__file__) # directory with your data,
22+
23+
Pdata = os.path.join(Pbase, '.') # data directory in Pbase
24+
Panalysis = os.path.join(Pbase, '.') # analysis directory in Pbase
25+
26+
os.chdir(Pbase)
27+
28+
# Data filename
29+
# ----------------------------------------------------------------------
30+
DCM = spm.Struct()
31+
DCM.xY.Dfile = 'maeMdfspm8_subject1'
32+
33+
# Parameters and options used for setting up model
34+
# ----------------------------------------------------------------------
35+
DCM.options.analysis = 'ERP' # analyze evoked responses
36+
DCM.options.model = 'ERP' # ERP model
37+
DCM.options.spatial = 'IMG' # spatial model
38+
DCM.options.trials = num([1, 2]) # index of ERPs within ERP/ERF file
39+
DCM.options.Tdcm[0] = 0 # start of peri-stimulus time to be modelled
40+
DCM.options.Tdcm[1] = 200 # end of peri-stimulus time to be modelled
41+
DCM.options.Nmodes = 8 # nr of modes for data selection
42+
DCM.options.h = 1 # nr of DCT components
43+
DCM.options.onset = 60 # selection of onset (prior mean)
44+
DCM.options.D = 1 # downsampling
45+
46+
# ----------------------------------------------------------------------
47+
# Data and spatial model
48+
# ----------------------------------------------------------------------
49+
DCM = spm.spm_dcm_erp_data(DCM)
50+
51+
# ----------------------------------------------------------------------
52+
# Location priors for dipoles
53+
# ----------------------------------------------------------------------
54+
DCM.Lpos = num([
55+
[-42, -22, 7],
56+
[46, -14, 8],
57+
[-61, -32, 8],
58+
[59, -25, 8],
59+
[46, 20, 8]
60+
]).T
61+
DCM.Sname = ['left AI', 'right A1', 'left STG', 'right STG', 'right IFG']
62+
Nareas = DCM.Lpos.shape[1]
63+
64+
# ----------------------------------------------------------------------
65+
# Spatial model
66+
# ----------------------------------------------------------------------
67+
DCM = spm.spm_dcm_erp_dipfit(DCM)
68+
69+
# ----------------------------------------------------------------------
70+
# Specify connectivity model
71+
# ----------------------------------------------------------------------
72+
os.chdir(Panalysis)
73+
74+
DCM.A = spm.Cell()
75+
DCM.B = spm.Cell()
76+
77+
DCM.A[0] = spm.Array(Nareas, Nareas)
78+
DCM.A[0][2, 0] = 1
79+
DCM.A[0][3, 1] = 1
80+
DCM.A[0][4, 3] = 1
81+
82+
DCM.A[1] = spm.Array(Nareas, Nareas)
83+
DCM.A[1][0, 2] = 1
84+
DCM.A[1][1, 3] = 1
85+
DCM.A[1][3, 4] = 1
86+
87+
DCM.A[2] = spm.Array(Nareas, Nareas)
88+
DCM.A[2][3, 2] = 1
89+
DCM.A[2][2, 3] = 1
90+
91+
DCM.B[0] = DCM.A[0] + DCM.A[1]
92+
DCM.B[0][0, 0] = 1
93+
DCM.B[0][1, 1] = 1
94+
95+
DCM.C = num([[1, 1, 0, 0, 0]]).T
96+
97+
# ----------------------------------------------------------------------
98+
# Between trial effects
99+
# ----------------------------------------------------------------------
100+
DCM.xU.X = num([[0, 1]]).T
101+
DCM.xU.name = ['rare']
102+
103+
# ----------------------------------------------------------------------
104+
# Invert
105+
# ----------------------------------------------------------------------
106+
DCM.name = 'DCMexample'
107+
108+
DCM = spm.spm_dcm_erp(DCM)

0 commit comments

Comments
 (0)