spm_vb_regionF.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. function [F] = spm_vb_regionF (Y,xY,SPM)
  2. % Get log model evidence over a region of data for a GLM
  3. % FORMAT [F] = spm_vb_regionF (Y,xY,SPM)
  4. %
  5. % Y Matrix of fMRI data (eg. from spm_summarise.m)
  6. % xY Coordinates etc from region (eg. from spm_voi.m)
  7. % SPM SPM data structure (this must be loaded in from an
  8. % SPM.mat file). If this field is not specified this function
  9. % will prompt you for the name of an SPM.mat file
  10. %
  11. % F Log model evidence (single number for whole region)
  12. %
  13. % Importantly, the design matrix is normalised so that when you compare
  14. % models their regressors will be identically scaled.
  15. %
  16. % Valid model comparisons also require that the DCT basis set used in high
  17. % pass filtering, as specified in SPM.xX.K.X0, is the same for all models
  18. % that are to be compared.
  19. %
  20. % W. Penny, G. Flandin, and N. Trujillo-Barreto. (2007). Bayesian Model
  21. % Comparison of Spatially Regularised General Linear Models. Human
  22. % Brain Mapping, 28(4):275-293.
  23. %__________________________________________________________________________
  24. % Copyright (C) 2005-2014 Wellcome Trust Centre for Neuroimaging
  25. % Will Penny
  26. % $Id: spm_vb_regionF.m 6079 2014-06-30 18:25:37Z spm $
  27. try
  28. SPM;
  29. catch
  30. [Pf, sts] = spm_select(1,'^SPM\.mat$','Select SPM.mat');
  31. if ~sts, return; end
  32. swd = spm_file(Pf,'fpath');
  33. load(fullfile(swd,'SPM.mat'))
  34. end
  35. s=length(SPM.Sess);
  36. if s>1
  37. disp('spm_vb_regionF: only works for single session data');
  38. return
  39. end
  40. % Normalise design matrices to have columns of unit
  41. % variance - except for last
  42. X=SPM.xX.X;
  43. X=norm_design(X);
  44. % Make residual forming matrix (to later remove drifts)
  45. X0=SPM.xX.K.X0;
  46. N=size(X0,1);
  47. iX0=pinv(X0);
  48. R=eye(N)-X0*iX0;
  49. % Remove drifts
  50. Y=R*Y;
  51. % Normalise Y to unit dev
  52. sigma=std(Y);
  53. N=size(Y,1);
  54. Y=Y./(ones(N,1)*sigma);
  55. xyz = xY.XYZmm;
  56. N = size(xyz,2);
  57. xyz = SPM.xVol.M\[xyz;ones(1,size(xyz,2))];
  58. xyz = xyz(1:3,:);
  59. vxyz = spm_vb_neighbors(xyz',1);
  60. priors.W='Voxel - Shrinkage';
  61. priors.A='Voxel - Shrinkage';
  62. block=spm_vb_init_volume(X,1);
  63. block=spm_vb_set_priors(block,priors,vxyz);
  64. block.maxits = 64;
  65. block.update_alpha = 1;
  66. block.update_w = 1;
  67. block.update_lambda = 1;
  68. block.update_F = 1;
  69. block=spm_vb_glmar(Y,block);
  70. F=block.F;
  71. function [Xout] = norm_design (Xin)
  72. % Normalise design matrix to have unit variance columns
  73. % FORMAT [Xout] = norm_design (Xin)
  74. X=Xin(:,1:end-1);
  75. s=std(X,[],1);
  76. iS=diag(1./s);
  77. Xout=[X*iS,Xin(:,end)];