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 F = fullfile(Swd, F);
0071 if exist(F, 'file'), Ic = [Ic c]; fnames{end+1} = F; break, end
0072 end
0073 end
0074 end
0075 if isempty(Ic)
0076 error(['Could not find any contrast images for ' d_path]);
0077 end
0078
0079
0080 res = 1;
0081 for c = 1:length(Ic)
0082 V = spm_vol(fnames{c});
0083 img = spm_read_vols(V);
0084 [mx(c) i] = max(img(:));
0085 xyz(:, c) = mars_utils('e2xyz', i, V.dim(1:3));
0086 mx_roi(c) = maroi_pointlist(struct('XYZ', xyz(:, c), ...
0087 'mat', V.mat), 'vox');
0088 Y = get_marsy(mx_roi(c), D, 'mean');
0089 E = estimate(D, Y, params);
0090 [E n_Ic] = add_contrasts(E, D, Ic(c));
0091 marsS = compute_contrasts(E, n_Ic);
0092 fprintf('SPM statistic %7.4f; MarsBaR statistic %7.4f\n',...
0093 mx(c), marsS.stat(1));
0094 if abs(marsS.stat(1) - mx(c)) > 1e-5
0095 disp('MarsBaR gives a different result for contrast');
0096 res = 0;
0097 end
0098 end
0099 return
0100