Distribution of Mean of the Combinations of a Set.

[This article was first published on Data R Value, and kindly contributed to R-bloggers]. (You can report issue about the content on this page here)
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.


 https://github.com/pakinja/Data-R-Value


To leave a comment for the author, please follow the link and comment on their blog: Data R Value.

R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.

Never miss an update!
Subscribe to R-bloggers to receive
e-mails with the latest R posts.
(You will not see this message again.)

Click here to close (This popup will not appear again)