Having trouble with confidence bands on Kaplan-Meier curve
9 次查看(过去 30 天)
显示 更早的评论
I am trying to add 95% confidence bands to kaplan meier curves. I have attached a sample data file. The code I am using is as follows:
datatable=sampledata;
timeDays =datatable.TimeDays;
probability = datatable.Cohort1SurvivalProbability;
lower =datatable.Cohort1SurvivalProbability95CILower;
upper =datatable.Cohort1SurvivalProbability95CIUpper;
timeDays = timeDays';
lower = lower';
upper = upper';
probability = probability';
plot(timeDays,probability,'b', 'LineWidth', 5);
xlabel('Time');
ylabel('Survival probability');
title('Kaplan-Meier curve with confidence bands');
hold on
%% upper and lower confidence bands (shaded)
patch([timeDays, fliplr(timeDays)], [lower, fliplr(upper)],'b','FaceAlpha',0.1,'EdgeColor', 'none');
%% second curve now
timeDays2 =datatable.TimeDays;
probability2 = datatable.Cohort2SurvivalProbability;
lower2 =datatable.Cohort1SurvivalProbability95CILower;
upper2 =datatable.Cohort2SurvivalProbability95CIUpper;
timeDays2 = timeDays2';
lower2 = lower2';
upper2 = upper2';
probability2 = probability2';
plot(timeDays2,probability2,'r', 'LineWidth', 5);
hold off
patch([timeDays2, fliplr(timeDays2)], [lower2, fliplr(upper2)],'r','FaceAlpha',0.1,'EdgeColor', 'none');
legend('Cohort 1','','Cohort 2');
The output I get through this code is also attached. As can be seen, the confidence band for cohort 2 is above the km curve for cohort 2, rather than being around it, as is the case for cohort 1. In the dataset, the upper and lower 95% confidence interval values are above and below the corresponding probability values, so I do not understand why the confidence band is coming out this way. I shall be highly grateful for any help in this regard.
0 个评论
采纳的回答
Star Strider
2023-12-7
You have one typographical error.
This assignment:
lower2 =datatable.Cohort1SurvivalProbability95CILower;
should instead be:
lower2 =datatable.Cohort2SurvivalProbability95CILower;
then it works!
The code —
F = openfig('kmcurve.fig');
datatable=readtable('sampledata.xlsx')
timeDays =datatable.TimeDays;
probability = datatable.Cohort1SurvivalProbability;
lower =datatable.Cohort1SurvivalProbability95CILower;
upper =datatable.Cohort1SurvivalProbability95CIUpper;
timeDays = timeDays';
lower = lower';
upper = upper';
probability = probability';
plot(timeDays,probability,'b', 'LineWidth', 5);
xlabel('Time');
ylabel('Survival probability');
title('Kaplan-Meier curve with confidence bands');
hold on
%% upper and lower confidence bands (shaded)
patch([timeDays, fliplr(timeDays)], [lower, fliplr(upper)],'b','FaceAlpha',0.1,'EdgeColor', 'none');
%% second curve now
timeDays2 =datatable.TimeDays;
probability2 = datatable.Cohort2SurvivalProbability;
lower2 =datatable.Cohort2SurvivalProbability95CILower;
upper2 =datatable.Cohort2SurvivalProbability95CIUpper;
timeDays2 = timeDays2';
lower2 = lower2';
upper2 = upper2';
probability2 = probability2';
plot(timeDays2,probability2,'r', 'LineWidth', 5);
hold off
patch([timeDays2, fliplr(timeDays2)], [lower2, fliplr(upper2)],'r','FaceAlpha',0.1,'EdgeColor', 'none');
legend('Cohort 1','','Cohort 2');
.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 ANOVA 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!