Definition
Censoring is the situation in which a measurement shows only that a value lies beyond a limit, not what the value is. In timing, the usual case is right censoring: an operation is still unfinished when observation stops at a time limit , so its duration is known only to be greater than . A censored observation is recorded as a pair: the time observed, and a flag that says whether the event, such as completion, was seen. Recording the limit as if it were the duration understates the duration.
The idea
A test sends four requests to a server and waits at most 10 seconds for each answer. Three requests are answered after 1, 2 and 3 seconds. The fourth is still unanswered when its 10 seconds run out, and the test stops waiting. Writing 10 for the fourth request gives a mean of seconds, but the fourth request did not take 10 seconds; it took more than 10, perhaps much more. Leaving it out gives seconds, the mean of the answered requests, which hides the slowest request entirely.
A race whose finish line closes after 10 hours is a fair picture. A runner still on the course at closing time did not finish in 10 hours; the runner’s time is “more than 10 hours”. That is real information: the runner was slower than everyone who finished. Methods for censored data keep that information without inventing a finishing time. The picture also marks where censoring stops applying. If officials take a runner off the course at closing time, that runner will never finish, so there is no finishing time to estimate. The same holds for an operation that is canceled at the limit: its outcome is a failure, not a late completion.
How it works
Choose the target before the analysis, because censoring affects each target differently.
The distribution of the eventual completion time , including its mean.
The completion probability by a deadline: the fraction of operations that finish within the limit .
The capped time : the time an operation occupies before it either finishes or is given up.
The time of completed operations only. This is a different quantity, conditional on finishing.
Record two values for every operation: the observed time , which is the completion time if the operation finished within its limit and the limit otherwise, and the event flag , which is 1 if completion was seen and 0 if the observation was censored. Also record what happened at the limit: the operation was canceled, retried, or left running.
Report the number of censored operations next to every summary of durations.
Compute what the data determine exactly when every operation was watched for the same limit . The observed completion fraction by any time is the fraction of operations with and . For a nearest-rank sample percentile §11.16 at level , at least completions suffice. An interpolated percentile needs every order statistic it uses. With 19 of 20 completions, nearest-rank p95 uses rank 19. Type 7 interpolation uses ranks 19 and 20, so it still needs the censored duration. The mean capped time is the plain mean of the values.
Use survival analysis when the limits differ between operations, for example when a run ends while operations that started at different times are still in progress. Survival analysis is the branch of statistics for times until an event when some times are censored. Its basic tool, the Kaplan–Meier estimator §11.2 (formula below), estimates the probability that an operation is still unfinished at each time. An operation censored at time counts as in progress up to and is then dropped from the count, so the knowledge that it lasted at least is used and nothing beyond is assumed.
Two other forms of censoring occur in timing. In left censoring the value is known only to be below a limit, as when a timer reading of 0 ticks shows only that the operation took less than one tick. In interval censoring the value is known only to lie between two times, as when a program checks every 100 milliseconds whether an operation has finished, and finds it unfinished at the second check and finished at the third; the operation then finished between 200 and 300 milliseconds.
Worked example
One common limit. The four requests described above were each watched for seconds. The records are , , and .
Completion probability within 10 seconds: .
Median §11.13 completion time: sorted, the times are 1, 2, 3 and something above 10. The median of four values is the mean of the second and third, seconds, whatever the fourth value is.
Mean capped time: seconds. This is a correct estimate of the mean of .
Mean completion time: not determined. If the fourth request eventually finishes at a time , the mean is , which exceeds seconds. If , the mean is seconds. The data show only that the mean exceeds 4 seconds, and the mean is infinite if a never-finishing request is assigned infinite duration.
Different limits, Kaplan–Meier. Five operations give these records, in seconds: A completed at 2; B was censored at 3, because the run ended; C completed at 4; D completed at 5; E was censored at 6. Let be the estimated probability that an operation is unfinished at time .
At , all 5 operations are in progress and 1 completes: .
At , B leaves the count without completing.
At , 3 operations (C, D and E) are in progress and 1 completes: .
At , 2 operations (D and E) are in progress and 1 completes: .
At , E leaves the count without completing. Beyond 6 seconds the data say nothing.
The estimated median is the first time at which falls to 0.5 or below: 5 seconds. Two shortcuts give wrong answers. Dropping B and E leaves completions at 2, 4 and 5, which says that every operation is done by 5 seconds: . Treating B and E as completions at 3 and 6 gives , too low, because it counts B as finished at 3 seconds although B was only known to be unfinished then.
Stated precisely
Let be the time at which an operation would complete and the time at which observation of it stops. The record is together with if and otherwise. The survival function is , the probability that the operation is still unfinished at time .
Let be the distinct observed completion times, the number of completions at , and the number of operations at risk at , meaning those with . The Kaplan–Meier estimator [528] is the product over all completion times up to , with before the first completion. It is consistent, meaning that its error tends to zero as the number of operations grows, at every time at which operations can still be under observation, provided two assumptions hold.
Independent censoring: the time at which observation stops is independent of the completion time . Whether observation stops must not depend on how the operation is going.
Independent observations: operations are independent draws from the same distribution of , whatever their limits.
With a common limit , the mean of the values estimates the restricted mean where denotes the expected value (the probability-weighted average). The restricted mean never exceeds the mean . The mean depends on for , where the data contain no completions, so the data alone do not determine it. If some operations never complete, that is, , then is infinite.
Limits and common mistakes
A timeout §9.34 is not automatically censoring. A timeout is a limit on how long one party waits; when it expires, only the waiting ends, unless the system also cancels the work. Censoring assumes that the operation would have completed at some later time and that stopping the observation did not change it. If the timeout cancels the operation, the timed-out operation has no later completion time: count it as a failure, and report the completion probability by the deadline.
Censoring that depends on the outcome biases the Kaplan–Meier estimate. If a client gives up early on operations that already look slow, for example because the server reports that it is overloaded, slow operations leave the count more often than fast ones, and the estimate looks faster than the truth.
No method recovers the tail beyond the last observation time from the data. Estimating it requires a model of the distribution’s shape, such as an exponential distribution, and the answer is then a consequence of that assumption.
Censoring differs from truncation. A censored operation appears in the data with partial information. A truncated operation does not appear at all, as when a logger records only operations that complete; then even the number of slow operations is unknown.
An ECDF §11.17 (empirical cumulative distribution function), the curve that gives for each time the fraction of observations at or below it, rises to 1 when it is drawn from completed operations only. To show observed completions, divide by all attempts and label the curve accordingly. At thresholds beyond an early censoring time this curve may undercount actual completions.
A finite observation window cannot establish a worst-case completion time. Operations still running when the window closed may take any time, including forever.
Questions answered
Should a timed-out operation be recorded as exactly the timeout length?
No: a timed-out operation must not be recorded as a completion that took exactly the timeout length, because it did not complete within that time, and its true duration, if it ever completes, is longer. Record the time observed together with a flag that marks the operation as unfinished, and distinguish work still running from work canceled at the deadline, and count timeouts separately in every report.
The timeout length is the right value only for a capped target, the time each operation occupies before it finishes or is given up; the recorded values give the exact sample capped mean and estimate the population capped mean. For the completion time itself, report the completion probability within the limit, sample percentiles whose required ranks are observed, and survival-analysis estimates such as the Kaplan–Meier curve, which use the knowledge that the operation lasted at least the limit. If the timeout cancels the operation, the operation has no completion time: report it as a failure. For example, requests that complete in 1, 2 and 3 seconds plus one that times out at 10 give a capped mean of seconds; if the fourth request finishes at 30 seconds, the true mean is seconds.
Related entries: Estimand and estimator (§11.2), Missing data and attrition (§11.29), Survivorship bias (§11.30), Finite-window rate (§11.41), Deadline versus timeout (§9.34), Empirical cumulative distribution function (ECDF) (§11.17). Further reading: [528].