Having trouble with confidence bands on Kaplan-Meier curve
8 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 7 Dic 2023
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');
.
2 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su ANOVA in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!