# Resample from data with constraints to the marginal distribution

Motivation This problem comes from the situation where I have a non-random sample of individuals for which $$p$$ variables are measured. The target is to extract a subset of individuals which would be representative for a hypothetical population for which the marginal distribution of the variables is known (but not their joint distribution).

The problem Assume I have a sample of $$n$$ individuals, $$p$$ categorical variables are measured: $$X_1,\ldots,X_p$$. In the sample, each variable has an estimated probability mass function $$\hat{f}_1, \ldots, \hat{f}_p$$. I want to find the 'best' subsample of size $$m for which $$\hat{f}_1, \ldots, \hat{f}_p$$ are the closest possible to some fixed $$f_1, \ldots, f_p$$.

Distance between distributions As measure of distance between distributions I intend to use something along the difference between the proportions estimated in the data ($$\hat{f}$$) and the arbitrary proportions ($$f$$). If I denote $$f_{il}$$ as the proportion of category $$l$$ in $$X_i$$, then a measure of dissimilarity could be $$D(f_i, \hat{f}_i) = \sum_{l = 1}^{k_i} (f_{il} -\hat{f}_{il} )^2.$$

Toy Example Assume I gather a data set where I record sex (categorical, 2 levels) and education level (3 levels: low, medium, high). The two variables are not necessarily independent. For a given $$m < n$$, I want to select the best subsample so that there are approximately 30 / 70 males vs females, and 10% low education, 50% medium education and 40% high education individuals (or any arbitrary proportion).

One way would be to take all subsets of size $$m$$ and calculate some dissimilarity measure between the $$\hat f$$'s and $$f$$'s. But this would become quickly unfeasible. So would there be a smarter way of searching the space of all subsets?

The second way I thought about it is to assign some sampling weights to each observation, which would lead to $$\hat f$$'s that only approximately correspond to the $$f$$'s, but I don't know how to calculate these weights. But then how to calculate the weights?

• This question lacks two crucial pieces of information, which may be related; namely, (1) why do you want to do this and (2) exactly how do you intend to measure how close the $\hat f_i$ are to the $f_i$ in order to determine what "best" might mean? Please clarify. – whuber Dec 22 '18 at 2:05
• Thanks for your suggestions @whuber, I edited the main text with your answers to your two questions. – Theodor Dec 23 '18 at 13:46
• This sounds similar to the concept of "ranking" in survey sampling only, only you try to match your marginals to known population totals for obvious reasons: jstor.org/stable/2290793?seq=1#page_scan_tab_contents – StatsStudent Dec 23 '18 at 14:47