# Analyze Left-, Right-, and Interval-Censored Data

A comparison of two Kaplan-Meier estimates, using SurvivalDistribution, for some right-censored data and the mean residual life at 10 for the two groups.
 In[1]:= Xm = {9, 13, 18, 23, 28, 31, 34, 45, 48, 161}; cm = {0, 1, 0, 0, 1, 0, 0, 1, 0, 1}; nm = {5, 5, 8, 8, 12, 16, 23, 27, 30, 33, 43, 45}; cnm = {0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0};
 In[2]:= X{\[ScriptD]1, \[ScriptD]2} = MapThread[ SurvivalDistribution[Censoring[#1, #2]] &, {{m, nm}, {cm, cnm}}];
 In[3]:= Xsm = SurvivalFunction[\[ScriptD]1, #1] &; snm = SurvivalFunction[\[ScriptD]2, #1] &; cPlot[t_, cens_, sf_, col_] := Block[{loc = Extract[t, Position[cens, 1]]}, Show[Table[ Graphics[{col, Line[{{i, sf[i] - .02}, {i, sf[i] + .02}}]}], {i, loc}]]]; tbl = Grid[ Join[{Text[Style[#, Bold, FontFamily -> "Verdana"]] & /@ { "\!\(\*SubscriptBox[\(t\), \(i\)]\)", "\!\(\*SubscriptBox[\(P\), \ \(T\)]\)[t>\!\(\*SubscriptBox[\(t\), \(i\)]\)]", "\!\(\*SubscriptBox[\(P\), \ \(C\)]\)[t>\!\(\*SubscriptBox[\(t\), \(i\)]\)]"}}, Table[{Text[Style[ToString@i, FontFamily -> "Verdana"]], PaddedForm[ Probability[t > i, t \[Distributed] \[ScriptD]1], {4, 3}], PaddedForm[ Probability[t > i, t \[Distributed] \[ScriptD]2], {4, 3}]}, {i, Range[0, 45, 5]}]], Alignment -> Right, Dividers -> {{False, True, False}, {False, True}}, ItemStyle -> {Automatic, Automatic, {{{2, -1}, {2, 2}} -> Directive[Blend[{Black, Red}], FontFamily -> "Verdana"], {{2, -1}, {3, 3}} -> Directive[Blend[{Black, Blue}], FontFamily -> "Verdana"]}}]; Grid[{{tbl, , Show[Plot[{sm[x], snm[x]}, {x, 0, 60}, PlotRange -> {0, 1}, Exclusions -> None, PlotStyle -> {Blend[{Black, Red}], Blend[{Black, Blue}]}, Filling -> {1 -> {{2}, Automatic}}, ImageSize -> 325], cPlot[m, cm, sm, Blend[{Black, Red}]], cPlot[nm, cnm, snm, Blend[{Black, Blue}]]]}}]
 Out[3]=
 In[4]:= XExpectation[x - 10 \[Conditioned] x > 10, x \[Distributed] \[ScriptD]1]
 Out[4]=
 In[5]:= XExpectation[x - 10 \[Conditioned] x > 10, x \[Distributed] \[ScriptD]2]
 Out[5]=