# ECDF for categorical data? [closed]

I have a data set of which contains the name of buyers. I want to plot a CDF that shows what percentage of buyers purchased up to what percentage of products. Something like bellow: , but I don't know how to do it with categorical data in R? Can some one please give me a clue?

The definition of a CDF requires that a random variable take values in a totally ordered set. However, the defining property of a categorical random variable is that its values are non-orderable. Therefore, CDF's do not exist for categorical RV's.

That said, if your primary interest is to provide a graphical representation of your data, you might want to look to the probability mass function instead. In order to present the PMF, you'll want to organize your data so that the probabilities are arranged in decreasing order. This approach is commonly used in fields like text mining. The R script below illustrates how to do this:

K <- 10  # Total number of possible categories
pop <- letters[1:K]  # Categorical sample space
n <- 50  # Sample size
f <- 1:K / sum(1:K)  # True PMF
X <- sample(pop, n, replace = T, prob = f)  # Sample data
f_hat <- table(X) / n  # Estimated PMF
f_hat_ord <- sort(f_hat, decreasing = T)  # Ordered estimated PMF
plot(f_hat_ord)


If you really wanted, you could generate something akin to a CDF by taking the cumulative sum of the ordered estimated PMF. However, I would imagine that you'd lose some of the visual appeal by doing that.

• And what is the set is ordered? Say a random variable can take on $n$ discrete values on reals $\mathbb{R}$? How do we express CDF in this case? And what is the name for such distribution if not categorical? Thank you Commented Oct 14, 2021 at 12:00