# Calculate expectation from empirical cdf

I have a empirical cumulative probability distribution function for a random variable. The random variable is "time to failure" and I have the full curve i.e till the probability reaches $1$. I want to know Mean Time To Failure i.e expectation of that random variable. Is there any standard method to find mean from an empirical distribution.

I am getting the empirical CDF (as discrete values) as output from a "model checking tool" which uses iterative numerical computation techniques to get those probabilities. For example, let $F(t)=P(X \leq t)$ is the CDF of the random variable $X$ where $X$ stands for time between failure. To plot the curve of "$F(t)$ vs $t$" I am varying t with some step size, calculating $F(t)$ for that t using the "model checking tool" and adding the points to get the curve. I can use small step size to get the more accurate curve. So, I have access to only this CDF values at different$t$. From this values I want to do a good estimate of mean value of $X$.

Now the parameters will be:

1) $T$, the maximum value of t. We need to find this with some precision i.e if $F(T_1)-F(T_2)$ is less than some epsilon we set $T=T_1$.

2) Once we have found T we need to find suitable step size $h$ at which we will be calculating the CDF values.

How should I choose those parametrs?

Depending on how you've got your empirical cdf (discretized, formula) you might opt for Henning's answer, or also (given that the variable is positive) use this identity (obtained by applying integration by parts) :

$$E(X) = \int_0^\infty (1- F(x)) \; dx$$

• To improve this answer, you might consider supplying the explicit solution in the OP's case in terms of the atoms $\{x_i\}$ and the corresponding values of the empirical cdf $\hat{F}_n(x_i)$. – cardinal Sep 2 '11 at 22:36

Convert to a probability density by subtracting successive known values of the cdf and scaling appropriately. Then just compute $E(X)=\int x p(x) dx$ by multiplying and summing.

(Actually, telescoping the partial sums of this show that you can also just integrate the cdf: $$E(X) = b - \int_a^b CDF(x) dx$$ with the integration interval ${[a,b]}$ chosen wide enough to include all the entire probability mass.)

Relatively easily, if your empirical cdf has a maximum time T. Let P(t) be your cumulative distribution function: the probability of failure before time t. Then $p(t) = dP/dt$ is the probability density of failing at time t, and $E[t] = \int_0^T dt t p(t)$ is the Mean Time-To-Failure. Integrating by parts, you find $E[t] = T - \int_0^T dt P(t)$, which you can do numerically. If your empirical cdf has an arbitrarily long cutoff, it might be best to say, "our best estimate of Mean-Time-To-Failure is x, but 0.001% of our light bulbs still haven't burned out, so that mean could go up."

• @all Thanks for reply. I have made some additions to the main question regarding the "choice of parameters" to get an accurate estimate of E[X] – aaaaaa Oct 27 '11 at 14:17

I know this is an older question, but others may find the answer helpful.

Given the empirical CDF, $F_n(x)$, call the percent points of the CDF $\alpha$ (which range from $0$ to $1$) and their corresponding values $F_n^{-1}(\alpha)$ You can use the fact that: $$E(X) = \int_0^1 F_n^{-1}(\alpha);d\alpha$$

This is actually the dual of the relationship @leonbloy stated, however, instead of adding up vertical slices across the x-axis from $F(x)$ to $1$, you are adding horizontal slices from the y-axis to $F(x)$ up to $y=1$. It is the same area.

To actually do the integration, I'd recommend the trapezoid rule, so given $n$ entries in the CDF we have: $$E(X) \approx \sum_{k=0}^{n-1} \frac{F_n^{-1}(\alpha_{k+1}) + F_n^{-1}(\alpha_{k})}{2}\cdot\left(\alpha_{k+1}-\alpha_{k}\right)$$