spm_dcm_ui.m 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. function varargout = spm_dcm_ui(Action)
  2. % User interface for Dynamic Causal Modelling (DCM)
  3. % FORMAT spm_dcm_ui('specify')
  4. % FORMAT spm_dcm_ui('estimate')
  5. % FORMAT spm_dcm_ui('search')
  6. % FORMAT spm_dcm_ui('optimise')
  7. % FORMAT spm_dcm_ui('review')
  8. % FORMAT spm_dcm_ui('compare')
  9. % FORMAT spm_dcm_ui('average (BPA)')
  10. % FORMAT spm_dcm_ui('average (BMA)')
  11. %
  12. % * Specify a new model
  13. % * Estimate a specified model
  14. % * Review a previously estimated model
  15. % * Compare two or more estimated models
  16. % * Produce an aggregate model using Bayesian averaging
  17. %
  18. % DCM structure, as saved in DCM_???.mat:
  19. %
  20. % DCM.M - model specification structure (see spm_nlsi)
  21. % DCM.Y - output specification structure (see spm_nlsi)
  22. % DCM.U - input specification structure (see spm_nlsi)
  23. % DCM.Ep - posterior expectations (see spm_nlsi)
  24. % DCM.Cp - posterior covariances (see spm_nlsi)
  25. % DCM.a - intrinsic connection matrix
  26. % DCM.b - input-dependent connection matrix
  27. % DCM.c - input connection matrix
  28. % DCM.Pp - posterior probabilities
  29. % DCM.Vp - variance of parameter estimates
  30. % DCM.H1 - 1st order Volterra Kernels - hemodynamic
  31. % DCM.K1 - 1st order Volterra Kernels - neuronal
  32. % DCM.R - residuals
  33. % DCM.y - predicted responses
  34. % DCM.xY - original response variable structures
  35. % DCM.T - threshold for inference based on posterior p.d.f
  36. % DCM.v - Number of scans
  37. % DCM.n - Number of regions
  38. %
  39. %__________________________________________________________________________
  40. %
  41. % DCM is a causal modelling procedure for dynamical systems in which
  42. % causality is inherent in the differential equations that specify the
  43. % model. The basic idea is to treat the system of interest, in this case
  44. % the brain, as an input-state-output system. By perturbing the system
  45. % with known inputs, measured responses are used to estimate various
  46. % parameters that govern the evolution of brain states. Although there are
  47. % no restrictions on the parameterisation of the model, a bilinear
  48. % approximation affords a simple re-parameterisation in terms of effective
  49. % connectivity. This effective connectivity can be latent or intrinsic or,
  50. % through bilinear terms, model input-dependent changes in effective
  51. % connectivity. Parameter estimation proceeds using fairly standard
  52. % approaches to system identification that rest upon Bayesian inference.
  53. %
  54. % Dynamic causal modelling represents a fundamental departure from
  55. % conventional approaches to modelling effective connectivity in
  56. % neuroscience. The critical distinction between DCM and other approaches,
  57. % such as structural equation modelling or multivariate autoregressive
  58. % techniques is that the input is treated as known, as opposed to stochastic.
  59. % In this sense DCM is much closer to conventional analyses of neuroimaging
  60. % time series because the causal or explanatory variables enter as known
  61. % fixed quantities. The use of designed and known inputs in characterising
  62. % neuroimaging data with the general linear model or DCM is a more natural
  63. % way to analyse data from designed experiments. Given that the vast
  64. % majority of imaging neuroscience relies upon designed experiments we
  65. % consider DCM a potentially useful complement to existing techniques.
  66. %__________________________________________________________________________
  67. % Copyright (C) 2002-2012 Wellcome Trust Centre for Neuroimaging
  68. % Karl Friston
  69. % $Id: spm_dcm_ui.m 7481 2018-11-09 15:36:57Z peter $
  70. DCMversion = 'DCM12.5';
  71. if nargin == 1 && strcmpi(Action,'version')
  72. varargout = {DCMversion};
  73. return
  74. end
  75. % Get figure handles
  76. %--------------------------------------------------------------------------
  77. Finter = spm_figure('GetWin','Interactive');
  78. header = get(Finter,'Name');
  79. spm_clf(Finter);
  80. set(Finter,'Name',sprintf('Dynamic Causal Modelling (%s)',DCMversion));
  81. spm('Pointer','Arrow');
  82. % Temporary welcome message
  83. %--------------------------------------------------------------------------
  84. disp(['Please refer to this version as ' ...
  85. DCMversion ' in papers and publications.']);
  86. % Options, using pull-down menu
  87. %--------------------------------------------------------------------------
  88. if ~nargin
  89. str = 'Action: ';
  90. Actions = {'specify', ...
  91. 'estimate (time-series)', ...
  92. 'estimate (cross-spectra)', ...
  93. 'search', ...
  94. 'optimise', ...
  95. 'review', ...
  96. 'compare', ...
  97. 'average', ...
  98. 'quit'};
  99. selected = spm_input(str,1,'m',Actions);
  100. Action = Actions{selected};
  101. end
  102. switch lower(Action)
  103. %==========================================================================
  104. % Specify graph
  105. %==========================================================================
  106. case 'specify',
  107. spm('FnBanner','spm_dcm_specify');
  108. spm_dcm_specify;
  109. %==========================================================================
  110. % Estimate models - standard
  111. %==========================================================================
  112. case 'estimate (time-series)',
  113. %-estimate models
  114. %----------------------------------------------------------------------
  115. spm('FnBanner','spm_dcm_estimate');
  116. %-select DCM models
  117. %----------------------------------------------------------------------
  118. [P, sts] = spm_select([1 Inf],'^DCM.*\.mat$','select DCM_???.mat');
  119. if ~sts, return; else P = cellstr(P); end
  120. spm('Pointer','Watch');
  121. spm('FigName','Estimation in progress');
  122. %-loop over models
  123. %----------------------------------------------------------------------
  124. for i=1:numel(P)
  125. spm('SFnBanner',sprintf('spm_dcm_estimate: model %d',i));
  126. spm_dcm_estimate(P{i});
  127. end
  128. %==========================================================================
  129. % Estimate models - cross spectral density
  130. %==========================================================================
  131. case 'estimate (cross-spectra)',
  132. %-estimate models
  133. %----------------------------------------------------------------------
  134. spm('FnBanner','spm_dcm_fmri_csd');
  135. %-select DCM models
  136. %----------------------------------------------------------------------
  137. [P, sts] = spm_select([1 Inf],'^DCM.*\.mat$','select DCM_???.mat');
  138. if ~sts, return; else P = cellstr(P); end
  139. spm('Pointer','Watch');
  140. spm('FigName','Estimation in progress');
  141. %-loop over models
  142. %----------------------------------------------------------------------
  143. for i=1:numel(P)
  144. spm('SFnBanner',sprintf('spm_dcm_fmri_csd: model %d',i));
  145. spm_dcm_fmri_csd(P{i});
  146. end
  147. %==========================================================================
  148. % Esimate and search a model set
  149. %==========================================================================
  150. case 'search',
  151. spm('FnBanner','spm_dcm_search');
  152. spm_dcm_search;
  153. %==========================================================================
  154. % Post hoc model optimisation/selection
  155. %==========================================================================
  156. case 'optimise',
  157. spm('FnBanner','spm_dcm_post_hoc');
  158. spm_dcm_post_hoc;
  159. %==========================================================================
  160. % Review results
  161. %==========================================================================
  162. case 'review',
  163. spm('FnBanner','spm_dcm_review');
  164. spm_dcm_review;
  165. %==========================================================================
  166. % Compare different models
  167. %==========================================================================
  168. case 'compare',
  169. spm('FnBanner','spm_api_bmc');
  170. spm_jobman('Interactive','','spm.dcm.bms.inference');
  171. %==========================================================================
  172. % Average
  173. %==========================================================================
  174. case 'average',
  175. if spm_input('Average',1,'b',{'BPA','BMA'},[1 0])
  176. spm('FnBanner','spm_dcm_average');
  177. spm_dcm_average; % Average several models (Bayesian FFX)
  178. else
  179. spm('FnBanner','spm_dcm_bma_results');
  180. spm_dcm_bma_results; % Average model parameters from BMS (BMA)
  181. end
  182. %==========================================================================
  183. % Quit DCM GUI
  184. %==========================================================================
  185. case 'quit',
  186. %==========================================================================
  187. % Otherwise
  188. %==========================================================================
  189. otherwise
  190. error('Unknown action string.');
  191. end
  192. % Return to SPM
  193. %--------------------------------------------------------------------------
  194. spm_clf(Finter);
  195. spm('Pointer','Arrow');
  196. set(Finter,'Name',header);
  197. spm_input('Thank you',1,'d');