Switch to unified view

a b/deep_learning_multiscale_lstm_fig1.m
1
%% plot roc curves
2
clear
3
close all
4
load('\multi-lstm-summary-clinical_avg.mat','mean_curve_all','mean_curve_seperate_all','auc_micro','auc_micro_std','prob_all','label_all');
5
6
time_step = 6;
7
time_range = 12:time_step:72;
8
intervals= linspace(0, 1, 100);
9
colormaps = [{'[128,128,128]/255'};{'[0, 213, 255]/255'};{'[149, 0, 255]/255'};{'[123, 255, 0]/255'};{'[1,0,0]'};{'[0,0,1]'}];
10
count = 1;
11
for time_points = 66%12:12:72
12
index = find(time_range==time_points);
13
auc_micro(index);
14
mean_curve = mean_curve_all{index};
15
mean_curve_seperate = mean_curve_seperate_all{index};
16
ySEM = std(mean_curve_seperate)/sqrt(size(mean_curve_seperate,1));                              % Compute ‘Standard Error Of The Mean’ Of All Experiments At Each Value Of ‘x’
17
CI95 = tinv([0.025 0.975], size(mean_curve_seperate,1)-1);                    % Calculate 95% Probability Intervals Of t-Distribution
18
yCI95 = bsxfun(@times, ySEM, CI95(:));              % Calculate 95% Confidence Intervals Of All Experiments At Each Value Of ‘x’
19
20
% x is a vector, matrix, or any numeric array of data. NaNs are ignored.
21
% p is the confidence level (ie, 95 for 95% CI)
22
% The output is 1x2 vector showing the [lower,upper] interval values.
23
CIFcn = @(x,p)prctile(x,abs([0,100]-(100-p)/2));
24
25
auc_boostrap = [];
26
num_boostrap = 1000;
27
for iboost = 1:num_boostrap
28
    [labels, idx] = datasample(label_all{index},length(label_all{index}));
29
    preds = prob_all{index}(idx);
30
    [X_tmp,Y_tmp,T_tmp,AUC_tmp] = perfcurve(labels-1,preds,false);
31
    auc_boostrap = [auc_boostrap; AUC_tmp];
32
end
33
p = 95; 
34
CI = CIFcn(auc_boostrap,p);
35
36
% figure,
37
eval(['[l',num2str(count),', p] = boundedline(intervals, mean_curve, ySEM,''cmap'',' colormaps{count}, ',''alpha'')']);% -b r 'cmap', [123, 255, 0]/255 [149, 0, 255]/255 [0, 213, 255]/255 [128,128,128]/255
38
% h1 = outlinebounds(l,p);
39
40
hold on
41
%     
42
43
%     plot(intervals, mean_curve,'-r','linewidth',2);
44
    
45
    axis square
46
    box on
47
     grid on
48
    title('Average ROC Curves at Different Time Intervals')
49
    xlabel('1-Specificity')
50
    ylabel('Sensitivity')
51
% hold off
52
temp = [num2str(time_points),' h ',num2str(round(auc_micro(index),2)),' (',num2str(round(CI(1),2)),',' num2str(round(CI(2),2)),')'];
53
legend_disp{count} = temp;
54
% eval(['legend(l',num2str(index),',','''',legend_disp,'''',')'])
55
% legend boxoff 
56
count = count+1;
57
end
58
legend([l1 l2 l3 l4 l5 l6],legend_disp)
59
legend boxoff 
60
61
plot(intervals, intervals, 'k--')
62
63
%%
64
num_pts =[];
65
for i = 1:11
66
num_pts = [num_pts; size(label_all{i},1)];
67
68
end
69
70
figure, bar(num_pts);
71
set(gca,'xticklabel',num2cell(12:6:72));
72
73
xlabel('Hours After Cardiac Arrest');
74
ylabel('Number of Patients')
75
76
%% calibration curves
77
close all
78
clear
79
load('D:\Research\Cardiac_arrest_EEG\Codes\ComaPrognosticanUsingEEG-master\multiscale-lstm\multi-lstm-summary-clinical_avg.mat','mean_curve_all','mean_curve_seperate_all','auc_micro','auc_micro_std','prob_all','label_all');
80
81
time_step = 6;
82
time_range = 12:time_step:72;
83
intervals= linspace(0, 1, 100);
84
colormaps = [{'[128,128,128]/255'};{'[0, 213, 255]/255'};{'[149, 0, 255]/255'};{'[123, 255, 0]/255'};{'[1,0,0]'};{'[0,0,1]'}];
85
count = 1;
86
for time_points = 12:12:72
87
index = find(time_range==time_points);
88
yp = prob_all{index};
89
y = label_all{index};
90
y(y==2)=0;
91
% x is a vector, matrix, or any numeric array of data. NaNs are ignored.
92
% p is the confidence level (ie, 95 for 95% CI)
93
% The output is 1x2 vector showing the [lower,upper] interval values.
94
CIFcn = @(x,p)prctile(x,abs([0,100]-(100-p)/2));
95
96
M = 10;
97
xx = linspace(0, 1, M+1); 
98
yy = [];     
99
for k = 1:M
100
    y_k = y(yp>=xx(k) & yp<xx(k+1));
101
    yy(k) = sum(y_k)/length(y_k);
102
end
103
xx = linspace(0, 1, M+1);
104
xx = (xx(1:M)+xx(2:end))/2;
105
Brier_mean(index) = nansum(abs(xx-yy))/sum(~isnan(yy)); %% Brier's Score
106
107
hold on
108
109
eval(['l', num2str(count),' = plot(xx, yy,''Color'',',colormaps{count}, ',''linewidth'',2);']);
110
xx = linspace(0, 1, M+1); 
111
Brier_boostrap = [];
112
num_boostrap = 1000;
113
for iboost = 1:num_boostrap
114
    [labels, idx] = datasample(label_all{index},length(label_all{index}));
115
    yp = prob_all{index}(idx);
116
    yy = [];
117
    xx = linspace(0, 1, M+1); 
118
for k = 1:M
119
    y_k = y(yp>=xx(k) & yp<xx(k+1));
120
    yy(k) = sum(y_k)/length(y_k);
121
end
122
xx = linspace(0, 1, M+1);
123
xx = (xx(1:M)+xx(2:end))/2;
124
Brier_boostrap(iboost) = nansum(abs(xx-yy))/sum(~isnan(yy));
125
126
end
127
p = 95; 
128
CI = CIFcn(Brier_boostrap,p);
129
130
    
131
    axis square
132
    box on
133
    grid on
134
    title('Calibration')
135
    xlabel('Prediction')
136
    ylabel('Proportion of the positive')
137
138
temp = [num2str(time_points),' h ',num2str(round(Brier_mean(index),2)),' (',num2str(round(CI(1),2)),',' num2str(round(CI(2),2)),')'];
139
legend_disp{count} = temp;
140
% eval(['legend(l',num2str(index),',','''',legend_disp,'''',')'])
141
% legend boxoff 
142
count = count+1;
143
end
144
xx = linspace(0, 1, M+1); 
145
plot(xx, xx, 'k--')
146
147
legend([l1 l2 l3 l4 l5 l6],legend_disp)
148
legend boxoff 
149