Skip to content

Commit b8b3265

Browse files
committed
Moved DeLong in Functions
1 parent bf9e255 commit b8b3265

20 files changed

+639
-0
lines changed
Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
function DeLongUserInterface()
2+
%%
3+
%% Reference:
4+
% @article{sun2014fast,
5+
% title={Fast Implementation of DeLong's Algorithm for Comparing the Areas Under Correlated Receiver Operating Characteristic Curves},
6+
% author={Xu Sun and Weichao Xu},
7+
% journal={IEEE Signal Processing Letters},
8+
% volume={21},
9+
% number={11},
10+
% pages={1389--1393},
11+
% year={2014},
12+
% publisher={IEEE}
13+
% }
14+
%% Edited by X. Sun.
15+
% Version: 2014/12
16+
17+
close all;
18+
clear all;
19+
20+
%% Initialize figure
21+
22+
hight = 500;
23+
width = 550;
24+
25+
mainf = figure;
26+
set(mainf, 'Name', 'ROC Analysis', 'NumberTitle', 'off');
27+
posf = get(mainf, 'Position');
28+
posf = [posf(1) + posf(3) / 2 - width / 2, ...
29+
posf(2) + posf(4) - hight, width, hight];
30+
set(mainf, 'Position', posf);
31+
set(gcf,'color','w');
32+
33+
%% External function
34+
35+
% Get filename list
36+
getFileList_ = @getFileList;
37+
% Load samples
38+
loadsamples_ = @loadsamples;
39+
% Plot ROC curves
40+
plotroc_ = @plotroc_discrete;
41+
% Calculate aucs and covariance matrix
42+
calroc_ = @fastDeLong;
43+
% Calculate p-value
44+
calpvalue_ = @calpvalue;
45+
46+
%% Initialize variables
47+
48+
fileList = getFileList_();
49+
samples = [];
50+
aucs = [];
51+
delongcov = [];
52+
rating1i = 1;
53+
rating2i = 1;
54+
filename = fileList{1};
55+
56+
%% Initialize uicontrol
57+
58+
% Titletext
59+
uicontrol('style','text',...
60+
'String', 'ROC Analysis',...
61+
'Position', [190, 450, 175, 40],...
62+
'Fontsize', 20,...
63+
'Backgroundcolor', 'w');
64+
65+
% Selectef File text
66+
uicontrol('style','text',...
67+
'String', 'Selectef File :',...
68+
'Position', [32, 410, 90, 19],...
69+
'Fontsize', 10,...
70+
'Backgroundcolor', 'w');
71+
72+
% Selected File popup
73+
uisfp = uicontrol('style','popup',...
74+
'String', fileList,...
75+
'Position', [127, 414, 90, 19],...
76+
'Fontsize', 8,...
77+
'Backgroundcolor', 'w',...
78+
'Callback', @clearAxes);
79+
80+
% Rating 1 text
81+
uicontrol('style','text',...
82+
'String', 'Rating 1 :',...
83+
'Position', [227, 410, 90, 19],...
84+
'Fontsize', 10,...
85+
'Backgroundcolor', 'w');
86+
87+
% Rating 1 popup
88+
uir1p = uicontrol('style','popup',...
89+
'String', 'No Ratings',...
90+
'Position', [311, 414, 90, 19],...
91+
'Fontsize', 8,...
92+
'Backgroundcolor', 'w',...
93+
'ForegroundColor', 'b',...
94+
'Callback', @setrating1);
95+
96+
% Rating 2 text
97+
uicontrol('style','text',...
98+
'String', 'Rating 2 :',...
99+
'Position', [227, 376, 90, 19],...
100+
'Fontsize', 10,...
101+
'Backgroundcolor', 'w');
102+
103+
% Rating 2 popup
104+
uir2p = uicontrol('style','popup',...
105+
'String', 'No Ratings',...
106+
'Position', [311, 380, 90, 19],...
107+
'Fontsize', 8,...
108+
'Backgroundcolor', 'w',...
109+
'ForegroundColor', [0, 0.5, 0],...
110+
'Callback', @setrating2);
111+
112+
% Update Data pushbotton
113+
uiudp = uicontrol('style','pushbutton',...
114+
'String', 'Update Data',...
115+
'Position', [74, 376, 106, 23],...
116+
'Fontsize', 8,...
117+
'Backgroundcolor', 'w',...
118+
'ForegroundColor', 'r',...
119+
'Callback', @update);
120+
121+
% Analysis pushbotton
122+
uiap = uicontrol('style','pushbutton',...
123+
'String', 'Analysis',...
124+
'Position', [437, 395, 81, 23],...
125+
'Fontsize', 8,...
126+
'Backgroundcolor', 'w',...
127+
'Enable', 'off',...
128+
'Callback', @analysis);
129+
130+
% Axes
131+
hax = axes('Units','pixels', 'position', [50, 50, 300, 300]);
132+
plot(1, 1)
133+
axis equal;
134+
135+
% analysis
136+
137+
% AUC 1 text
138+
uicontrol('style','text',...
139+
'String', 'AUC 1 :',...
140+
'Position', [370, 333, 52, 15],...
141+
'Fontsize', 10,...
142+
'Backgroundcolor', 'w');
143+
144+
% AUC 1 edit
145+
uie1 = uicontrol('style','edit',...
146+
'String', 'AUC 1',...
147+
'Position', [430, 330, 100, 22],...
148+
'Fontsize', 10,...
149+
'Enable', 'inactive',...
150+
'ForegroundColor', 'b',...
151+
'Backgroundcolor', 'w');
152+
153+
% AUC 2 text
154+
uicontrol('style','text',...
155+
'String', 'AUC 2 :',...
156+
'Position', [370, 283, 52, 15],...
157+
'Fontsize', 10,...
158+
'Backgroundcolor', 'w');
159+
160+
% AUC 2 edit
161+
uie2 = uicontrol('style','edit',...
162+
'String', 'AUC 2',...
163+
'Position', [430, 280, 100, 22],...
164+
'Fontsize', 10,...
165+
'Enable', 'inactive',...
166+
'ForegroundColor', [0, 0.5, 0],...
167+
'Backgroundcolor', 'w');
168+
169+
% VAR 1 text
170+
uicontrol('style','text',...
171+
'String', 'VAR 1 :',...
172+
'Position', [370, 233, 52, 15],...
173+
'Fontsize', 10,...
174+
'Backgroundcolor', 'w');
175+
176+
% VAR 1 edit
177+
uie3 = uicontrol('style','edit',...
178+
'String', 'VAR 1',...
179+
'Position', [430, 230, 100, 22],...
180+
'Fontsize', 10,...
181+
'Enable', 'inactive',...
182+
'ForegroundColor', 'b',...
183+
'Backgroundcolor', 'w');
184+
185+
% VAR 2 text
186+
uicontrol('style','text',...
187+
'String', 'VAR 2 :',...
188+
'Position', [370, 183, 52, 15],...
189+
'Fontsize', 10,...
190+
'Backgroundcolor', 'w');
191+
192+
% VAR 2 edit
193+
uie4 = uicontrol('style','edit',...
194+
'String', 'VAR 2',...
195+
'Position', [430, 180, 100, 22],...
196+
'Fontsize', 10,...
197+
'Enable', 'inactive',...
198+
'ForegroundColor', [0, 0.5, 0],...
199+
'BackgroundColor', 'w');
200+
201+
% COV12 text
202+
uicontrol('style','text',...
203+
'String', 'COV12 :',...
204+
'Position', [370, 133, 56, 15],...
205+
'Fontsize', 10,...
206+
'Backgroundcolor', 'w');
207+
208+
% COV12 edit
209+
uie5 = uicontrol('style','edit',...
210+
'String', 'COV12',...
211+
'Position', [430, 130, 100, 22],...
212+
'Fontsize', 10,...
213+
'Enable', 'inactive',...
214+
'BackgroundColor', 'w');
215+
216+
% TEST text
217+
% uicontrol('style','text',...
218+
% 'String', 'TEST : AUC 1 - AUC 2',...
219+
% 'Position', [380, 90, 138, 15],...
220+
% 'Fontsize', 10,...
221+
% 'Backgroundcolor', 'w');
222+
223+
% p-value text
224+
uicontrol('style','text',...
225+
'String', 'p-value :',...
226+
'Position', [370, 83, 56, 15],...
227+
'Fontsize', 10,...
228+
'Backgroundcolor', 'w');
229+
230+
% p-value edit
231+
uie6 = uicontrol('style','edit',...
232+
'String', 'p-value',...
233+
'Position', [430, 80, 100, 22],...
234+
'Fontsize', 10,...
235+
'Enable', 'inactive',...
236+
'BackgroundColor', [0.93, 0.84, 0.84]);
237+
238+
%% Callback functions
239+
240+
function clearAxes(hObj, event)
241+
fileIndex = get(uisfp, 'Value');
242+
filename = fileList{fileIndex};
243+
set(uiudp, 'ForegroundColor', 'r');
244+
set(uiap, 'Enable', 'off');
245+
set(uir1p, 'Value', 1);
246+
set(uir2p, 'Value', 1);
247+
set(uir1p, 'String', 'No Ratings');
248+
set(uir2p, 'String', 'No Ratings');
249+
cla;
250+
end
251+
252+
function update(hObj, event)
253+
set(hObj, 'ForegroundColor', 'k');
254+
set(uiap, 'ForegroundColor', 'r');
255+
samples = loadsamples_(filename);
256+
[aucs, delongcov] = calroc_(samples);
257+
plotroc_(samples);
258+
set(uiap, 'Enable', 'on');
259+
k = numel(aucs);
260+
ratingList = getRatingList(k);
261+
set(uir1p, 'Value', 1);
262+
set(uir2p, 'Value', 1);
263+
rating1i = get(uir1p, 'Value');
264+
rating2i = get(uir2p, 'Value');
265+
set(uir1p, 'String', ratingList);
266+
set(uir2p, 'String', ratingList);
267+
end
268+
269+
function analysis(hObj, event)
270+
set(uiudp, 'ForegroundColor', 'k');
271+
selectsamples.ratings = samples.ratings([rating1i, rating2i], :);
272+
selectsamples.spsizes = samples.spsizes;
273+
plotroc_(selectsamples);
274+
275+
set(uie1, 'String', aucs(rating1i));
276+
set(uie2, 'String', aucs(rating2i));
277+
set(uie3, 'String', delongcov(rating1i, rating1i));
278+
set(uie4, 'String', delongcov(rating2i, rating2i));
279+
set(uie5, 'String', delongcov(rating1i, rating2i));
280+
281+
pvalue = calpvalue_(aucs([rating1i, rating2i]), ...
282+
delongcov([rating1i, rating2i], [rating1i, rating2i]));
283+
if rating1i == rating2i
284+
pvalue = 1;
285+
end
286+
set(uie6, 'String', pvalue);
287+
288+
if pvalue < 0.05
289+
set(uie6, 'BackgroundColor', [0.76, 0.87, 0.78]);
290+
else
291+
set(uie6, 'BackgroundColor', [0.93, 0.84, 0.84]);
292+
end
293+
294+
set(uiap, 'ForegroundColor', 'k');
295+
end
296+
297+
function setrating1(hObj, event)
298+
rating1i = get(hObj, 'Value');
299+
set(uiap, 'ForegroundColor', 'r');
300+
end
301+
302+
function setrating2(hObj, event)
303+
rating2i = get(hObj, 'Value');
304+
set(uiap, 'ForegroundColor', 'r');
305+
end
306+
307+
%% Local functions
308+
309+
function ratingList = getRatingList(ratingnum)
310+
ratingList = 1 : ratingnum;
311+
end
312+
313+
end

Functions/DeLong/HOMCI.mat

1.26 MB
Binary file not shown.

Functions/DeLong/MCI.mat

389 KB
Binary file not shown.

Functions/DeLong/README.markdown

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
---
2+
layout: post
3+
title: "ROC Analysis Tool based on DeLong's Method"
4+
date: 2015-8-31
5+
categories: update
6+
---
7+
8+
### Introduction
9+
10+
This is a ROC analysis tool based on DeLong's method, implemented by [Xu Sun](http://pamixsun.github.io/).
11+
12+
To analysis your own data, you should firstly move your experiment results, saved as a **.mat** file in certain format, into the same dirrectory of the source codes of this tool. Then run the **DeLongUserInterface** function, and you will see you file is listed in the "Selected File" pop-up menu. Next, select your file and click the "Update Data" button below, several ROC curves will then be drawn according to you data. Now chose the two ratings that you would like to analysis in "Rating 1" and "Rating 2" and push the "Analysis" button, you will finally gain the statistical results. Note that all these results are calculated by DeLong's formulas with the fast implementation given by Sun and Xu.
13+
14+
If the color of the text in the push button is red, that means the results shown in the interface is not consistent with the options you chose in the pop-up menu. To fix this problem, all you need to do is just to click the correponding button.
15+
16+
The variables saved in the **.mat** file are *spsizes* and *ratings*:
17+
18+
- *spsizes* is a *2 * 1* vector, which represent the sizes of two samples, namely, *X* and *Y*. For ease of later reference, let *m*, *n* denote these two values.
19+
- *ratings* is a *K * N* matrix, where each row represents the ratings of one experiments. Note that *N* must be equal to the sum of *m* and *n*, and its first *m* elements is the ratings corresponding to *X*, while the last *n* corresponding to *Y*.
20+
21+
22+
![plot of chunk DeLongUI-image-1](images/delong/image_1.png)
23+
24+
![plot of chunk DeLongUI-image-2](images/delong/image_2.png)
25+
26+
27+
### Citation Request
28+
29+
Anyway, I hope that this tool could be helpful for researchers who using AUC in their work.
30+
31+
If you publish material based on these codes, then, please refer to [our paper](http://ieeexplore.ieee.org/xpl/articleDetails.jsp?reload=true&tp=&arnumber=6851192):
32+
33+
X. Sun, W. Xu, Fast implementation of DeLong's algorithm for comparing the areas under correlated receiver operating characteristic curves, IEEE Signal Processing Letters 21 (11) (2014) 1389-1393.
34+
35+
Here is a BiBTeX citation as well:
36+
37+
@article{sun2014fast,
38+
title={Fast Implementation of DeLong's Algorithm for Comparing the Areas Under Correlated Receiver Operating Characteristic Curves},
39+
author={Xu Sun and Weichao Xu},
40+
journal={IEEE Signal Processing Letters},
41+
volume={21},
42+
number={11},
43+
pages={1389-1393},
44+
year={2014},
45+
publisher={IEEE}
46+
}
47+
48+

Functions/DeLong/calpvalue.m

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
function pvalue = calpvalue(aucs, sigma)
2+
3+
% sigma
4+
l = [1, -1];
5+
% l * sigma * l'
6+
% diff(aucs)
7+
z = abs(diff(aucs)) / sqrt(l * sigma * l');
8+
9+
pvalue = 2 * (1 - normcdf(z, 0, 1));
10+
11+
end

0 commit comments

Comments
 (0)