Having trouble with confidence bands on Kaplan-Meier curve

8 ビュー (過去 30 日間)
Muhammad
Muhammad 2023 年 12 月 7 日
コメント済み: Star Strider 2023 年 12 月 7 日
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.

採用された回答

Star Strider
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')
datatable = 2056×7 table
TimeDays Cohort1SurvivalProbability Cohort1SurvivalProbability95CILower Cohort1SurvivalProbability95CIUpper Cohort2SurvivalProbability Cohort2SurvivalProbability95CILower Cohort2SurvivalProbability95CIUpper ________ __________________________ ___________________________________ ___________________________________ __________________________ ___________________________________ ___________________________________ 0 0.99928 0.99807 0.99973 0.99711 0.99529 0.99823 1 0.99873 0.99734 0.9994 0.99711 0.99529 0.99823 2 0.99837 0.99686 0.99915 0.99657 0.99463 0.99781 3 0.99764 0.99594 0.99863 0.99639 0.99441 0.99767 4 0.99745 0.99571 0.99849 0.99639 0.99441 0.99767 5 0.99691 0.99503 0.99807 0.99639 0.99441 0.99767 6 0.99691 0.99503 0.99807 0.99639 0.99441 0.99767 7 0.99691 0.99503 0.99807 0.99621 0.99419 0.99753 8 0.99654 0.99458 0.99779 0.99621 0.99419 0.99753 9 0.99635 0.99435 0.99765 0.99621 0.99419 0.99753 10 0.99598 0.99391 0.99735 0.99603 0.99397 0.99738 11 0.99561 0.99346 0.99706 0.99603 0.99397 0.99738 12 0.99561 0.99346 0.99706 0.99603 0.99397 0.99738 13 0.99543 0.99324 0.99691 0.99585 0.99376 0.99724 14 0.99543 0.99324 0.99691 0.99549 0.99333 0.99695 15 0.99543 0.99324 0.99691 0.99549 0.99333 0.99695
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');
.
  2 件のコメント
Muhammad
Muhammad 2023 年 12 月 7 日
Oh I missed that typo 😅 Thank-you so much!
Star Strider
Star Strider 2023 年 12 月 7 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeANOVA についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by