Algorithm to match continuous variables

2 views (last 30 days)
johovishta
johovishta on 17 Mar 2011
Edited: Vasilisa Iatckova on 15 Sep 2023
Hi, I have data sampled from two different populations (say people) where I have measured several continuous variables (for example age and sex). In some cases the populations will have uneven sample sizes
In the simplest case what algorithm would I use to match (on a case by case basis) the individual samples. The critical thing is that the individual samples are closely-matched (ie under some set threshold) and I dont mind losing some of my samples in order to achieve this tight matching. Presumably the tighter I set my matching criteria the more samples I will lose. Any ideas how to program this?
In the more complex case I would like the individual samples to matched along two continuous variables (e.g. both age and sex). That is, individuals must be matched within thresholds for both variables.Any ideas?
Thanks in advance for any suggestions. I am guessing there are probably algorithms for this kind of thing, but its not something I have done before. Cheers, J

Answers (2)

Matt Tearle
Matt Tearle on 17 Mar 2011
I'm not completely sure if you want just to extract a subset of data, or group all samples into a set of bins. The former you can do with logical indexing:
xselect = x(age > 42 & age < 99 & height > 123);
One way to achieve the latter would be to use categorical arrays. You could group everyone from age x to age y in one category, age y to age z in another, etc.

Vasilisa Iatckova
Vasilisa Iatckova on 15 Sep 2023
Edited: Vasilisa Iatckova on 15 Sep 2023
For people still looking: compute distances between variables and select the minimal ones. For instance, I'll be matching the red and the blue dots only by the y-coordinate, but I can pretend their x-coordinates are 1 & 2, as in the image, to separate the groups. I'm going to compute all-to-all hypots between each blue dot to all red dots and select pairs with minimal distances, eliminating them from running, once selected.

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!