0001 function res = test_rig(design_paths, params)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 if nargin < 1
0029 design_paths = spm_get([0 Inf], 'SPM*.mat', 'Select SPM designs');
0030 end
0031 if nargin < 2
0032 params = struct('redo_covar', 0, ...
0033 'redo_whitening', 0);
0034 end
0035
0036 n_designs = size(design_paths, 1);
0037 res = zeros(n_designs, 1);
0038 for d = 1:n_designs
0039 d_path = deblank(design_paths(d,:));
0040 res(d) = sf_test_design(d_path, params);
0041 end
0042 return
0043
0044 function res = sf_test_design(d_path, params)
0045
0046
0047
0048 D = mardo(d_path);
0049 if ~is_spm_estimated(D)
0050 error('Need an SPM estimated design');
0051 end
0052 if ~has_contrasts(D)
0053 error(['Design ' d_path ' does not contain contrasts']);
0054 end
0055 if ~has_images(D)
0056 error(['Design ' d_path ' does not contain images']);
0057 end
0058
0059
0060 Swd = fileparts(d_path);
0061 xCon = get_contrasts(D);
0062 stats = [xCon(:).STAT];
0063 Ic = []; fnames = {};
0064 for t = 'TF'
0065 for c = fliplr(find(stats == t))
0066 F = xCon(c).Vspm;
0067 if ~isempty(F)
0068
0069 if isstruct(F), F = F.fname; end
0070
0071 con_pth = fileparts(F);
0072 if isempty(con_pth)
0073 F = fullfile(Swd, F);
0074 end
0075 if exist(F, 'file'), Ic = [Ic c]; fnames{end+1} = F; break, end
0076 end
0077 end
0078 end
0079 if isempty(Ic)
0080 error(['Could not find any contrast images for ' d_path]);
0081 end
0082
0083
0084 res = 1;
0085 for c = 1:length(Ic)
0086 V = spm_vol(fnames{c});
0087 img = spm_read_vols(V);
0088 [mx(c) i] = max(img(:));
0089 xyz(:, c) = mars_utils('e2xyz', i, V.dim(1:3));
0090 mx_roi(c) = maroi_pointlist(struct('XYZ', xyz(:, c), ...
0091 'mat', V.mat), 'vox');
0092 Y = get_marsy(mx_roi(c), D, 'mean');
0093 E = estimate(D, Y, params);
0094 [E n_Ic] = add_contrasts(E, D, Ic(c));
0095 marsS = compute_contrasts(E, n_Ic);
0096 fprintf('SPM statistic %7.4f; MarsBaR statistic %7.4f\n',...
0097 mx(c), marsS.stat(1));
0098 st_spm = mx(c);
0099 st_mars = marsS.stat(1);
0100 bad_test = abs(st_mars - st_spm) > 1e-5;
0101 if bad_test
0102 spmV = lower(mars_utils('spm_version'));
0103 if any(strcmp(spmV, {'spm8', 'spm12b', 'spm12'}))
0104 xCon = get_contrasts(E);
0105 this_con = xCon(n_Ic);
0106 if this_con.STAT == 'T' & (st_mars > st_spm)
0107
0108 fudge = (st_mars / st_spm - 1) / exp(-8);
0109 fprintf('Fudge value was %f\n', fudge);
0110
0111
0112 if fudge < 10
0113 bad_test = 0;
0114 end
0115 end
0116 end
0117 end
0118 if bad_test
0119 disp('MarsBaR gives a different result for contrast');
0120 res = 0;
0121 end
0122 end
0123 return