Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

For some purpose I found myself generating and analyzing the average of the combinations of a set and when I generated the corresponding histogram I was surprised by its shape.

It should be remembered that the combinations C(m, n) of a set are the number of subsets of a set of m elements taken from n in n.

The number of combinations is calculated with:

This is the very simple code to generate the combinations, calculate their mean and generate the histogram:

m <- 50
n <- 6

COMBINATIONS <- t(as.data.frame(combn(m,n)))

C_M <- apply(COMBINATIONS, 1, mean)

hist_all <-hist(C_M, breaks = length(unique(C_M)), col = “blue”)

Interesting histogram. It’s as if there are two distributions.
But if we change the value of m by:

m <- 50
n <- 4

We obtain the following histogram:

Although it is a very simple math and programming exercise, the interesting thing is to interpret why histograms behave this way, so it becomes an exercise in understanding the visualization. 