필터 지우기
필터 지우기

age matching between two groups

조회 수: 2 (최근 30일)
Mahmoud Zeydabadinezhad
Mahmoud Zeydabadinezhad 2016년 3월 17일
답변: Roger Stafford 2016년 3월 17일
Hi,
I have two vectors containing the age (integers) of subjects. At the beginning, there is a big difference between the average of two groups. My goal is to swap the elements of two vectors in a way that makes the two averages as close as possible together. Any idea how I can do this?
Thank you!

채택된 답변

Roger Stafford
Roger Stafford 2016년 3월 17일
There is a very crude brute force method, but it is only practical for a limited range of sizes of the two groups. I suppose first that you want to keep the respective sizes of the two groups unchanged. Let n1 be the number in one group and n2 that in the other group, and let s be the sum of all the ages in the two groups. Use Matlab's 'nchoosek' function to obtain all possible n1 subsets of the n1+n2 total. For each subset find the sum of its elements, s1, and compute abs(s1/n1-(s-s1)/n2) and then choose the minimum of all these absolute differences.
In case you allow the sizes to vary, do the above for all possible values of n1 in 0 < n1 < total_size, and choose the minimum of all these minima.
As I have indicated, I do not recommend the above for very large values of n1+n2.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by