# R function to give me $P(X<x)$

I have this empirical discrete distribution with the respective percentiles (picture below). I want to know a R function which gives me $$P(X\lt0.58)$$ instead of $$P(X\le 0.58)$$ (given by ECDF function).

The ECDF function gives me around $$0.89$$ and $$0.90$$ but I want something between $$0.83$$ and $$0.84$$ (see the picture below).

Is there any functions that does this?

• Hint: how can you use the definition of the cumulative density function to determine the probability in an interval?
– Sycorax
Sep 16, 2020 at 14:26
• @Sycorax I subtract two cdf's Sep 16, 2020 at 14:37

There is a statistical question here.

Let the cumulative distribution function of a random variable be $$F_X$$, defined as

$$F_X(x) = \Pr(X \le x).$$

What is wanted is a variant of this with a strict inequality,

$$G_X(x) = \Pr(X \lt x).$$

The two differ when there is a nonzero chance that $$X=x.$$

Notice that the event $$X \lt x$$ is the same as the event $$-X \gt -x,$$ which is the complement of the event $$-X \le -x.$$ Therefore since the chance of an event and the chance of its complement must sum to unity,

$$G_X(x) = 1 - \Pr(-X \le -x) = 1 - F_{-X}(-x).$$

In this way we may find $$G_X$$ without having to do any more programming simply by computing the empirical CDF for the data $$-X.$$

In R, for instance, the empirical distribution $$F$$ of data x would be computed as

f <- ecdf(x)


Consequently we may compute $$G$$ as

g <- function(a) 1 - (ecdf(-x))(-a)


Here is an illustration of the difference using a dataset much like the one in the question with $$x_0=0.58$$ the value at which $$F_X$$ and $$G_X$$ are to be computed.

In this example, $$F_X(0.58)=0.9$$ while $$G_X(0.58)=0.8.$$ You can see that $$F_X$$ gives the height of the solid dot at $$x_0$$ while $$G_X$$ gives the height of the dot immediately to its left.

The dataset x consists of these 30 numbers:

0.24(7) 0.25(2) 0.26 0.27 0.28 0.29(2) 0.30 0.31 0.37 0.39
0.40 0.41 0.44(2) 0.49 0.52 0.58(3) 0.59 0.61 0.78


The values in parentheses give the counts of duplicated values.