       Re: Mathematica code for survival functions

• To: mathgroup at smc.vnet.net
• Subject: [mg78316] Re: [mg78212] Mathematica code for survival functions
• From: Darren Glosemeyer <darreng at wolfram.com>
• Date: Thu, 28 Jun 2007 04:24:38 -0400 (EDT)
• References: <200706260809.EAA03911@smc.vnet.net>

```Coleman, Mark wrote:
> Greetings,
>
> Is anyone on MathGroup aware of Mathematica code that generates either
> Kaplan-Meier survival curves or life-table survival curves? Thanks.
>
> Best regards,
> Mark
>
>

Here is a function that will give the Kaplan Meier fit as a Piecewise
function. The first three arguments are lists of equal length for the
times, survivor counts, and death counts. Your data may require some
processing to get it into that form.

In:= KMFit[times_, survivors_, deaths_, var_] := Piecewise[
MapThread[{#1, #2 <= var < #3} &,
{Join[{1}, With[{list = (survivors - deaths)/survivors},
FoldList[Times, First[list], Drop[list, 1]]]], Join[{0},
times],
Join[times, {Infinity}]}]]

Here is an example based on data from Table 1.4 in The Statistical
Analysis of Failure Time Data by Kalbfleisch and Prentice.

In:= t = {143, 164, 188, 190, 192, 206, 209, 213, 216, 220, 227, 230,
234,
246, 265, 304};

In:= s = {19, 18, 17, 15, 14, 13, 12, 11, 10, 8, 7, 6, 5, 3, 2, 1};

In:= d = {1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1};

In:= KMFit[t, s, d, x]

18                    17
Out= Piecewise[{{1, 0 <= x < 143}, {--, 143 <= x < 164}, {--, 164 <=
x < 188},
19                    19

15                    14                    13
>     {--, 188 <= x < 190}, {--, 190 <= x < 192}, {--, 192 <= x < 206},
19                    19                    19

12                    11                    10
>     {--, 206 <= x < 209}, {--, 209 <= x < 213}, {--, 213 <= x < 216},
19                    19                    19

9                     63                     27
>     {--, 216 <= x < 220}, {---, 220 <= x < 227}, {--, 227 <= x < 230},
19                    152                    76

45                     9                     3
>     {---, 230 <= x < 234}, {--, 234 <= x < 246}, {--, 246 <= x < 265},
152                    38                    19

3
>     {--, 265 <= x < 304}}]
38

Darren Glosemeyer
Wolfram Research

```

• Prev by Date: Background color for plot area (not whole graphic) and white
• Next by Date: Re: System of differential-algebraic equations
• Previous by thread: Mathematica code for survival functions