-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathspmrt_shiftsub.m
135 lines (96 loc) · 3.7 KB
/
spmrt_shiftsub.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
function [xd, yd, delta, deltaCI] = spmrt_shiftsub(pair1,pair2,mask,plotshift,threshold)
% Compare pairs of test-retest images using a shift function analysis for dependent measures.
% For each pair, we compute the difference image, which tells how much different in each voxel.
% From the difference images, we run shift function analysis, which then
% tells if differences, i.e. reliability in measurements, are similar
% between pairs (for instance is the reliability of a given MRI sequence is
% the same as another sequence, tested for different level of
% reliability/values)
%
% FORMAT [dd delta deltaCI xd yd] = spmrt_shift(image1,image2,mask,plotshift,threshold)
%
% INPUT if no input the user is prompted
% threshold (optional) if mask is not binary, threshold to apply
%
% OUTPUT xd and yd are the Harell-Davis estimators of each pair difference
% delta and deltaCI the result of the shift function analysis between difference images
%
% Cyril Pernet
% --------------------------------------------------------------------------
% Copyright (C) spmrt
spm('defaults', 'FMRI');
if nargin < 5; threshold = []; end
if nargin < 4; plotshift = 'yes'; threshold = []; end
if nargin == 0
[pair1,sts] = spm_select(2,'image','select images for pair 1',{},pwd,'.*',1);
if sts == 0
return
end
[pair2,sts] = spm_select(2,'image','select images for pair 2',{},pwd,'.*',1);
if sts == 0
return
end
[mask,sts] = spm_select(1,'image','select mask image',{},pwd,'.*',1);
if sts == 0
return
end
plotshift = 'yes'; % if user if prompt to enter data then return a figure
end
%% Get the data
if exist('threshold','var') && ~isempty(threshold)
X = spmrt_getdata(pair1(1,:),pair1(2,:),mask,threshold);
Y = spmrt_getdata(pair2(1,:),pair2(2,:),mask,threshold);
else
X = spmrt_getdata(pair1(1,:),pair1(2,:),mask);
Y = spmrt_getdata(pair2(1,:),pair2(2,:),mask);
end
nx = size(X,1);
if any(sum(X,1) == 0)
error('at least one image in the 1st pair is empty')
end
A = X(:,2)-X(:,1);
ny = size(Y,1);
if any(sum(Y,1) == 0)
error('at least one image in the 2nd pair is empty')
end
B = Y(:,2)-Y(:,1);
if nx ~= ny
error('unexpectedly the number of voxels from each pairs differ despite using the same mask')
end
clear X Y
% Compute Harell-Davis estimates and Shift function
c=(37./n.^1.4)+2.75; % The constant c was determined so that the simultaneous
% probability coverage of all 9 differences is
% approximately 95% when sampling from normal
% distributions
nboot = 200; % default suggested by Wilcox
% Get >>ONE<< set of B bootstrap samples
% The same set is used for all nine quantiles being compared
btable = zeros(n,nboot);
for b=1:nboot
btable(:,b) = randsample(1:n,n,true);
end
xd = NaN(1,9);
yd = NaN(1,9);
delta = NaN(1,9);
deltaCI = NaN(9,2);
for d=1:9
fprintf('estimating decile %g\n',d)
xd(d) = spmrt_hd(A,d./10);
yd(d) = spmrt_hd(B,d./10);
delta(d) = yd(d) - xd(d);
bootdelta =spmrt_hd(B(btable),d./10)- spmrt_hd(A(btable),d./10);
delta_bse = std(bootdelta,0);
deltaCI(d,1) = yd(d)-xd(d)-c.*delta_bse;
deltaCI(d,2) = yd(d)-xd(d)+c.*delta_bse;
end
%% figure
if strcmpi(plotshift,'yes')
figure('Name','Shit function between image voxel values');set(gcf,'Color','w');
plot(xd,delta,'ko'); hold on
fillhandle=fill([xd fliplr(xd)],[deltaCI(:,1)' fliplr(deltaCI(:,2)')],[1 0 0]);
set(fillhandle,'LineWidth',2,'EdgeColor',[1 0 0],'FaceAlpha',0.2,'EdgeAlpha',0.8);%set edge color
refline(0,0); xlabel('pair 1 (image 2 - image 1)','FontSize',14)
ylabel('Delta','FontSize',14); set(gca,'FontSize',12)
grid on; box on
end