Hey guys, in this video I'm going to go over how we can use the Kaplan-Meier estimator to
estimate a survival function or a survival curve. I'm going to go over that using this example,
which has sample data for 10 observations. The Kaplan-Meier estimator for doing an empirical
estimation of the survival function at time t is equal to the product of Xj less than or equal to t
of 1 minus dJ / Yj. And I'm going to define X of j as the distinct event times, or if you're thinking
of this as survival versus death, you can think of this as the number of distinct death times.
I'm going to write distinct event a.k.a. death times. Dj is going to be the number of death or
event occurrences at X of j and Yj is going to be equal to follow-up times that are as least as big
as Xj. Basically at time Xj, how many observations in your sample have survived at least up to that
time or past that time. T of i is the follow-up time and the follow-up time has to be greater
than or equal to X of j. We have that formula and then let's go ahead and get into estimating the
survival function. The first thing I'm going to do for the observations is I'm going to order them.
We have 2, 2, 3, and this observation is censored because it has a plus next to it. Then we have 5,
5+, 7, 9, two 16s, and 18 is the last observation and it's censored. And then I'm just going to
estimate the survival curve, which changes at each time where a death or an event occurs.
I'm going to start from the smallest observation and go to the largest observation and on the side
I'm going to write a function of what the values would be. The first time an event occurs for the
sample data is at time 2. I'm going to estimate the survival curve at S of 2 and then I'm just
going to plug into the formula. We want all X of js less than or equal to 2 and we want to plug in
1 - Dj over Yj. Two is the smallest time at which an event occurs, so we only have to consider 2 in
our first formula and then we see that we defined D of j as the number of events that occur at X of
j exactly. At time 2, exactly two events occur. That's going to be 1 minus 2 over Y of j and Yj
is basically follow-up times that are greater than or equal to 2. All 10 of our observations,
since 2 is the smallest time at which an event occurs, all our other observations, the follow-up
time or the survival time is larger than 2. All 10 observations are greater than or equal to 2,
which means all the 10 observations have lasted at least up to time 2. Our denominator is going
to be 10. For S of 2, the estimated survival curve is going to be--or survival function--is
going to be 1 minus 0.2 or 0.8. Then we can plug in into the function. A survival curve before,
when time T is less than 2, it's going to be equal to 1. No events have occurred prior to time 2.
And then when T is greater than or equal to 2, we have that the estimated curve is going to be equal
to 0.8. We're done with time 2. At time 3, the observation is censored. If we were to check this,
the formula would be 1 minus--and then 0 would be in the numerator for this fraction because
no deaths or events occur at time 3. This observation is just censored. If we were to
try to estimate the survival function at 3, this would just be 1 minus 0, which would give you 1,
so we only estimate the survival curve at actual event times. We don't take into consideration
observations that were censored only. We're going to move past 3 and go to 5, which has
one event occurrence and one censored observation. We're going to do the estimate of S of 5 and then
just plug in T is equal to 5. Because 2 is less than 5, we also have to take into consideration
the previous events that have occurred. This is going to be equal to 0.8 for X of j less than
or equal to 2 and then we have to also consider the observations at X of j less than or equal
to 5. This is going to be 0.8 times 1 minus the number of events that occur at T is equal to 5,
which is--we have one observation and one censored observation--so that's just going to be 1 and then
over all the follow-up times that were as least as big as 5. That's going to be 2, 3, 4, 5, 6,
7. Our estimated survival function at S of 5 is going to be 0.8 times 1 minus 1 over 7,
which is approximately 0.857 and this multiplied is approximately equal to .69. We have 0.69 as
part of our function. This is going to be the value when T is greater than or equal to 2 and
less than 5 and then when T is greater than or equal to 5, the survival function is going to
be estimated at .69. We're done with observations at T is equal to 5. The next time an event occurs
is at 7. We're just going to repeat, doing similar steps. The survival function for T
of 7 is going to be the product of Xj less than or equal to 7, one minus Dj over Yj. We have to
consider all the events that have occurred before 7, so less than 7. We're going to do .69 times 1
minus the events that occur at 7. There's just one event that occurs at that time and then all
the follow-up times greater than or equal to that time, which are five. It's going to be .69 times 1
minus 1 over 5. This is 0.69 times 0.8, which is approximately 0.55. The estimated survival curve
is going to be 0.69 between 5 and less than 7. And then when T is greater than or equal to 7,
it's going to go down to 0.55. The next event occurs at 9. At this point we're just repeating
the same process over and over again. This is going to be 0.55 times 1 minus 1 over 4 and that
gives approximately 0.41. When T is greater than or equal to 9, the survivalship goes
down to 0.41. Then we have 2 events occurring at 16. That's going to be 0.41 times 1 minus
2--because there are two events that occur at this time--over 3 and that gives .14. And then
the last observation is censored. This is going to be true between 16 and less than 18. And then
since the last observation is censored, we're not going to plug it in because we only plug in times
where a death occurs or an event occurs to change the actual proportion. And for T greater than 18,
we can either do a tail correction. Sometimes people correct this and say that any value
that's greater than the last value is going to go to 0. Or sometimes people correct it and just
use the T max value. Sometimes people just say, this is going to continue on to 0.14 and never
reach 0. Or some people say that this value is undefined. Since this is a censored observation,
I'm just going to say that this continues on to be 0.14. Now this is our final answer and this
is a discrete estimator of the survival function. And if you plotted the estimated survival curve,
you would get a discrete function. You would get something like this where you have closed
dots on the left limits and open circles on the right-hand limits and then this continues on to
infinity. And this type of function is called a cadlag function, or sometimes it's called an RCLL,
which means "right continuous with left limits". And we're done with this problem!
*chiptune music*