0001
0002
0003
0004
0005
0006
0007 des_id = 1;
0008 desmat_dir = fullfile(dataroot, '/test/stats/');
0009
0010 DEMO_STATS = 1;
0011 total_prop_reg = 0.6;
0012
0013
0014
0015
0016
0017
0018
0019 opt.printfig = 0;
0020 opt.append_str = '-append';
0021
0022 opt.figstub = fullfile(desmat_dir,sprintf('pb_des%02d', des_id));
0023
0024
0025 [corrmat] = post_process_corrmat(fullfile(desmat_dir,'SPM_fMRIDesMtx'),opt);
0026
0027 if DEMO_STATS
0028
0029
0030 load(fullfile(desmat_dir,'SPM_fMRIDesMtx'))
0031 X = xX.X;
0032
0033
0034 X(:,end) = [];
0035
0036
0037
0038
0039 nreg = size(X,2);
0040 prop_per_reg = total_prop_reg/nreg
0041
0042
0043 weights = ones(1,nreg);
0044 weights(2:2:end) = 1;
0045
0046 fakeX = X .* repmat(weights,size(X,1),1);
0047
0048
0049
0050 reg_sum = sum(fakeX,2);
0051 reg_sum = reg_sum-min(reg_sum);
0052 reg_sum = reg_sum/max(reg_sum);
0053
0054
0055
0056 rand_vect = rand(size(reg_sum));
0057
0058
0059 fake_data = reg_sum*sqrt(total_prop_reg) +rand_vect*sqrt(1-total_prop_reg);
0060
0061
0062 figure(3), clf
0063 subplot(2,1,1)
0064 plot(reg_sum)
0065
0066 subplot(2,1,2)
0067 plot(fake_data)
0068 end
0069
0070 origX = X;
0071
0072
0073
0074
0075
0076
0077 use_reg = [1];
0078 X = origX(:,use_reg);
0079 [b_sub, dev, stats_sub] = glmfit(zscore(X), zscore(fake_data), 'normal');
0080 fprintf('Using regressors: %s\n', sprintf('%d ',use_reg));
0081 fprintf('Proportion of variance explained: %s\n', sprintf('%1.2e, ', b_sub(2:end).^2));
0082 fprintf('Significance (p<): %s\n', sprintf('%1.4f, ', stats_sub.p(2:end)))
0083
0084
0085
0086
0087 X = origX;
0088 [b, dev, stats] = glmfit(zscore(X), zscore(fake_data), 'normal');
0089
0090 z = zscore(fake_data);
0091 tss = z'*z;
0092 ess = stats.resid'*stats.resid;
0093
0094 fprintf('\nUsing all regressors\n');
0095 fprintf('Total SS via beta^2: %1.3f\n', sum(b(2:end).^2));
0096 fprintf('Total SS via resid: %1.3f\n', 1-ess/tss);
0097 fprintf('Proportion of variance explained: %s\n', sprintf('%1.2e, ', b(2:end).^2));
0098 fprintf('Significance (p<): %s\n', sprintf('%1.4f, ', stats.p(2:end)))
0099
0100
0101 bmat = zeros(length(b)-1,2);
0102 pmat = zeros(size(bmat));
0103
0104 bmat(use_reg,1) = b_sub(2:end);
0105 bmat(:,2) = b(2:end);
0106
0107 pmat(use_reg,1) = stats_sub.p(2:end);
0108 pmat(:,2) = stats.p(2:end);
0109
0110 figure(4),clf
0111 subplot(2,1,1)
0112 bar(bmat)
0113 title('Beta values')
0114
0115 subplot(2,1,2)
0116 bar(pmat)
0117 l = line([get(gca,'xlim')],[0.05 0.05]);
0118 set(l,'color','r')
0119 title('P values')