# Creating Bins and Groups: Does Order Matter?

Suppose I have a dataset of medical patients that includes the following information - each row in this dataset contains the information about an individual patient:

  Patient_ID Gender    Status   Height    Weight Hospital_Visits Disease
1          1 Female   Citizen 145.0583 113.70725               1      No
2          2   Male Immigrant 161.2759  88.33188              18      No
3          3 Female Immigrant 138.5305  99.26961               6     Yes
4          4   Male   Citizen 164.8102  84.31848              12      No
5          5   Male   Citizen 159.1619  92.25090              12     Yes
6          6 Female   Citizen 153.3513 101.31986              11     Yes


I want to make non-overlapping "groups/bins" (i.e. an individual patient can only be assigned to a single group) out of these patients by using:

• The 2 categories within the Gender variable (Male, Female)
• The 2 categories within the Status variable (Citizen, Immigrant)
• Creating 5 equally populated groups out of the Height variable (i.e. patients with smallest 20% heights in one group, next 20% heights in second group, etc.)
• Creating 5 equally populated groups out of the Weight variable (i.e. patients smallest 20% weights in one group, etc.)
• Creating 5 equally populated groups of the Hospital Visits variable (i.e. patients with lowest 20% in one group, etc.)

In the end, this might look something like this:

   Gender Status  Height_ntile Height_range  Weight_ntile Weight_range Hospital_Visits_ntile Hospital_range count
<fct>  <fct>          <int> <chr>                <int> <chr>                        <int> <chr>          <int>
1 Female Citizen            1 115.86-188.48            1 58.99-121.02                     1 1-20              72
1 Female Citizen            2 201.12-225.6             1 58.99-121.02                     1 1-20              72
1 Female Citizen            1 115.86-188.48            1 58.99-121.02                     2 21-25              71


Part 1: Normally, if I were to do this - I could say that in total, after performing the binning, there will be : $$2 * 2 * 5 * 5 * 5 = 500$$ Groups. However, I think it is not necessary that each of these 500 groups will be equally populated in the end. For example, if there are significantly more males than females and in general a person is not likely to visit the hospital frequently - then this can result in unequally populated groups.

Part 2: Another approach I thought of is to make "Nested Groups". For example:

• First, select all males
• Then, select all male citizens
• Then, out of the set of all male citizens - identify a group of 20% of this set with the smallest heights
• Then, out of the set of all male citizens within the shortest 20% height - further isolate a group of 20% with the smallest weights
• Finally, out of the set of all male citizens within the shortest 20% height and within the shortest 20% height having the 20% smallest weight - further isolate them into a group with the 20% fewest number of hospital visits : This will now be the first group
• Repeat this process for all possible group combinations

Mathematically, I tried to represent this nested grouping/binning process (I think there will still be 500 groups?) as:

$$V_{ijkl} = \{x \in M : x \in C_i \cap H_{ij} \cap W_{ijk} \cap V_{ijkl}\}$$

• $$M$$ is the set of all individuals patients
• $$x$$ is a given individual
• $$C_i$$ is the set of all individuals in category $$i$$
• $$H_{ij}$$ is the set of all individuals in category $$j$$ within category $$i$$
• $$V_{ijkl}$$ isthe set of all individuals in category $$l$$ within category $$k$$ within category $$j$$ within category $$i$$

My Question: Regarding the binning approaches taken in Part 1 vs Part 2 - I am curious to see if any mathematical proofs can be written about:

• Can we mathematically prove the groups in Part 1 will not necessarily be equally sized but the groups made in Part 2 are more likely to be equally sized? (I use "more likely" to characterize situations with severe imbalances within the variables, e.g. very tall people, more females than males, etc.)?

• And regarding Part 2, can we mathematically prove that the "order in which we select variables to create the bins" has the ability to change the compositions and counts of the bins? As an example, if we choose to start creating bins using the "Gender" variable before the "Status" variable - could this result in bins with different patients and different numbers of patients being assigned to the final groupings compared to if "Status" is chosen before "Gender"? Is there a mathematical proof for this?

Thanks!

• Note: I am interested in understanding and proving these from an abstract and general idea - not necessarily for a specific dataset (e.g. skewed values, imbalance, ties, etc.)

Suppose there are only two variables, and eight patients, and the eight patients' measurements are $$(5,10),(5,30),(5,40),(5,50),(6,10),(7,15),(8,20),(10,50)$$. If you first bin on the first variable, getting one bin with $$(5,10),(5,30),(5,40),(5,50)$$ and one with $$(6,10),(7,15),(8,20),(10,50)$$, and then partition these two bins on the second variable, you get the four bins, $$(5,10),(5,30)$$; $$(5,40),(5,50)$$; $$(6,10),(7,15)$$; and $$(8,20),(10,50)$$.
If you first bin on the second variable, getting bins $$(5,10),(6,10),(7,15),(8,20)$$ and $$(5,30),(5,40),(5,50),(10,50)$$, and then bin these on the first variable, you get the four bins $$(5,10),(6,10)$$; $$(7,15),(8,20)$$; $$(5,30),(5,40)$$; $$(5,50),(10,50)$$.