Two Sides of The Same Distribution: Permutations
By: Phil Frederick
Tags: Data Science, Tutorial, Statistics, Python

Two Sides of The Same Distribution: Permutations

Recently, I’ve been spending more time getting to know the statistical side of the python programming language primarily in relation to visualizing certain characteristics and ideas. I thought I would share a quick tutorial on how one might go about determining whether two populations share a common distribution. The data that I will be using is NBA data sampled from the 2016 season and exhibits features such as the player’s name,the team they play for, their position, their age, their height, their weight, their salary and college attended.

For this example I will be focusing on player position in relation to salary earned.

First, you probably want to do an inspection of the features that you’re most interested in to get a feel for the spread of the data. Below is a boxplot showcasing the salary distribution as it relates to player position:

I should also note that all missing values had been discarded from the dataset reducing the number of observations to 364 rows from 458.

As you can see from the above boxplot many of the positions have similar distributions. The IQR’s for all plots seem to overlap, but there are some distinctions in that the center position appears to, on average, pay the most while the shooting guard position posesses the smallest median salary. That being said for this example, I’m interested in determining if the distributions between two groups are similar and by the looks of it the point guard position and power forward position have like distributions.

We can use permutations to recreate samples of both sets of salary information as it relates to the positions and reassign the new values to assist in the creation of an empirical cumulative distribution plot which will be subsequently compared to the individual ecdf’s of our original data.

First, we want to seperate salary information by each of the positions ultimately creating two seperate arrays. This is relatively straightforward using the pandas library of python

Secondly, we want to construct our function that will help in the construction of the ecdf’s.

then we would like to create a function that will take both arrays and combine them, permute them and then reassign them.

If the salary distributions for either position are essentially the same then it shouldn’t matter if we were to freely reassign samples from either distribution .

The above plot was generated by simulating fifty permutations and plotting each distributions respective ecdf. The dark blue line demonstrates the ecdf of the original point guard salary distribution while the red line denotes the ecdf of the original power forward salary distribution. The haze in between are the repeated ecdfs of the fifity permutions executed. If the two distributions were indeed similar then we would expect to see the original empirical distribution functions overlap with those of the permutations. In this graph we see just that! Implying that the distributions are indeed similar.

To further illustrate that the distributions are alike we can dig a little deeper by establishing a test statistic, the mean difference between the two original distributions. If we use the same logic as above we can use permutations to reconstruct this test statistic repeatedly and ultimately compare it to the actual or observed value.

Dummy function for test statistic

The above plot was constructed by generating 10,000 samples of our test statistic via the pre-defined functions we assembled earlier. The dashed line represents the observed value which is $456,081.27.

Where permuted_diff represents the permutation of 10,000 samples we can assess the probability of obtaining the observed value or some value more extreme, commonly known as the p-value. In this case the p-value is rather large and thus we have no evidence that suggest that the two distributions are not alike.