spm_mvb_p.m 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. function [p] = spm_mvb_p(MVB,k)
  2. % Classical p-value for MVB using null distribution of log-odds ratio
  3. % FORMAT [p] = spm_mvb_p(MVB,k)
  4. %
  5. % MVB - Multivariate Bayes structure
  6. % k - number of samples > 20
  7. %
  8. % p - p-value: of (relative) F using an empirical null distribution
  9. %
  10. % spm_mvb_p evaluates an empirical null distribution for the (fee-energy)
  11. % difference in log-evidences (the log odds ratio) by phase-shuffling the
  12. % target vector and repeating the greedy search. It adds the p-value as a
  13. % field (p_value) to MVB.
  14. %__________________________________________________________________________
  15. % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
  16. % Karl Friston
  17. % $Id: spm_mvb_p.m 4492 2011-09-16 12:11:09Z guillaume $
  18. %-number of samples
  19. %--------------------------------------------------------------------------
  20. try
  21. k;
  22. catch
  23. str = 'number of samples for null distribution';
  24. k = spm_input(str,'!+1','b',{'20','50','100'},[20 50 100]);
  25. end
  26. %-Get figure handles and set title
  27. %--------------------------------------------------------------------------
  28. Fmvb = spm_figure('GetWin','MVB');
  29. spm_clf(Fmvb);
  30. % get MVB results
  31. %==========================================================================
  32. try
  33. MVB;
  34. catch
  35. mvb = spm_select(1,'mat','please select models',[],pwd,'MVB_*');
  36. MVB = load(mvb(1,:));
  37. MVB = MVB.MVB;
  38. end
  39. % whiten target and predictor (X) variables (Y) (i.e., remove correlations)
  40. %--------------------------------------------------------------------------
  41. K = MVB.K;
  42. X = K*MVB.X;
  43. Y = K*MVB.Y;
  44. X0 = K*MVB.X0;
  45. U = MVB.M.U;
  46. % create orthonormal projection to remove confounds
  47. %--------------------------------------------------------------------------
  48. Ns = length(X);
  49. X0 = spm_svd(X0);
  50. R = speye(Ns) - X0*X0';
  51. R = spm_svd(R);
  52. Y = R'*Y;
  53. % F value (difference in log-evidence or log odds ratio)
  54. %--------------------------------------------------------------------------
  55. F = MVB.M.F;
  56. F = max(F) - F(1);
  57. % Randomisation testing
  58. %==========================================================================
  59. for i = 1:k
  60. % randomise target vector (using phase-shuffling if V ~= I)
  61. %----------------------------------------------------------------------
  62. if MVB.V(1,2)
  63. X0 = R'*spm_phase_shuffle(X);
  64. else
  65. X0 = R'*X(randperm(Ns),:);
  66. end
  67. % Optimise mapping
  68. %======================================================================
  69. M = spm_mvb(X0,Y,[],U,[],MVB.Ni,MVB.sg);
  70. % record F and compute p-value
  71. %----------------------------------------------------------------------
  72. F0(i) = max(M.F) - M.F(1);
  73. p = 1 - sum(F0 < F)/(1 + i);
  74. % plot
  75. %----------------------------------------------------------------------
  76. subplot(2,1,1)
  77. q = ceil(i/4);
  78. hist(F0,q); hold on
  79. plot([F F],[0 q],'r'); hold off;
  80. str = sprintf('p < %0.4f (%i samples)',p,i);
  81. title({[MVB.name ' (' MVB.contrast ')']; str},'FontSize',16)
  82. xlabel('log odds ratio')
  83. ylabel('null distribution')
  84. axis square
  85. drawnow
  86. end
  87. % display and assign in base memory
  88. %--------------------------------------------------------------------------
  89. str = sprintf('randomisation p-value = %.4f',p);
  90. xlabel({'log odds ratio';str},'FontSize',16)
  91. disp(['Thank you; ' str])
  92. MVB.p_value = p;
  93. % save results
  94. %--------------------------------------------------------------------------
  95. try
  96. save(MVB.name,'MVB', spm_get_defaults('mat.format'));
  97. end
  98. assignin('base','MVB',MVB)