Solution (source code)

= Solution

At each distinct event time $t_j$, let $d_j$ events occur among $r_j$ people in the <risk set>. The <Kaplan–Meier estimator> is
$$
\widehat S(t)=\prod_{t_j\leq t}\left(1-\frac{d_j}{r_j}\right);
$$
censorings remove people from later risk sets but create no factor.

<Left truncation>, or delayed entry, means that an individual is observed only after surviving to an entry time. A registry assembled from patients alive when a clinic opens is a practical example. Adapt Kaplan–Meier by admitting each person to the risk set only at their entry time.

<Period survival analysis> is useful when recent prognosis is desired but complete long-term follow-up of a recent diagnosis cohort is unavailable. For a chosen calendar year, intersect every patient's observed follow-up with that year. Express the surviving pieces on the time-since-diagnosis scale, treat the beginning of the calendar window as delayed entry and its end as right censoring, and apply Kaplan–Meier with those entry and exit times.