# Selecting a subset of the population such that the distribution of a certain variable in the subset matches a reference distribution?

I have a large population ($$P$$) of entries and I am given the distribution of a certain variable ($$x_0$$) for a specific subset ($$S$$) of the population. The subset $$S$$ is not a random sample and hence the distribution of $$x_0$$ for $$S$$ is not necessarily the same as that of $$x_0$$ for $$P$$.

I want to use all other available variables ($$x_1...x_n$$) to select another subset $$S'$$ from the set ($$P-S$$), such that the distribution of $$x_0$$ for $$S'$$ is the same as (or reasonably close to) that for $$S$$. That is, $$S'$$ mimics $$S$$ as far as the variable $$x_0$$ is concerned.

I am new to formal data science and I am not sure if machine learning is the best way to solve this problem. So far, my planned solution is to train a binary classifier on ($$P-S$$) that minimizes a loss that quantifies the difference in the target and obtained distributions' JS-divergences, the "obtained" being defined as entries with a predicted score $$y_0 > 0.5$$, or some other number, for instance. Then testing this model on separate test entries in ($$P-S$$) and applying a cut $$y_0 > 0.5$$ should give me $$S'$$.

Will this strategy work? Is there a more standard and elegant way to do this?

Maybe I don't understand your method well, but I suspect that there is a major flaw in it: if the model classifies instances based on whether they satisfy the distribution condition, it means that the instances (for the classifier) represent distributions themselves (i.e. subsets of elements), not individual elements of the population.

In this option, the real problem is how to generate these subsets. It's possible but not trivial. I would suggest a genetic algorithm (not a binary classifier) which optimizes the JS divergence (for instance) from a population of subsets at every generation, starting from a population of random subsets.

Another option is to calculate the empirical probability distribution and resample $$P-S$$ by applying it:

• Define some precision parameter $$\epsilon$$ for the size of the intervals.
• Estimate the empirical probability distribution $$p(x_0 \in I)$$ on $$S$$ for every interval I with length $$\epsilon$$.
• Count the initial frequency $$f(x_0 \in I)$$ for every interval $$I$$ (same intervals) on $$P-S$$. Note that if there is any $$I$$ for which $$f(x_0 \in I)=0$$ and $$p(x_0 \in I)>0$$, it means that $$\epsilon$$ must be increased.
• We want to achieve the distribution $$p(x_0 \in I)$$ on $$P-S$$, so we have to calculate the new frequency $$f'(x_0 \in I)$$ such that:
• $$f'(x_0 \in I) \leq f(x_0 \in I)$$ for every $$I$$, otherwise there are not enough available instances in $$P-S$$.
• $$f'(x_0 \in I) \approx n \times p(x_0 \in I)$$ for some $$n>0$$ to satisfy the distribution ($$n$$ should be as high as possible).

So we have:

$$n \leq \frac{f(x_0 \in I)}{p(x_0 \in I)}$$ for every $$I$$.

We obtain the highest coefficient $$n$$ which satisfies this condition:

$$n=min_I\left( \frac{f(x_0 \in I)}{p(x_0 \in I)}\right)$$

Once $$n$$ is found we randomly pick $$f'(x_0 \in I) \approx n \times p(x_0 \in I)$$ instances in $$P-S$$ for every interval $$I$$.

• I edited the equations, I had an error in the first version. Hopefully there's no error anymore ;) Mar 7, 2022 at 23:42