フィルターのクリア

How to select a random sample without replacement with imposed condition?

2 ビュー (過去 30 日間)
Christian
Christian 2015 年 10 月 24 日
コメント済み: Christian 2015 年 10 月 24 日
Hi,
I'd like to draw a random sample from my population. My population is a vector x of size (N x 1). My sample should satisfy
sum(x(sample)) = 0.7*sum(x);
So I do not care how many observations I draw from the sample, but I just want to make sure that the resulting sample covers 70 percent of total x in terms of value, not in terms of number.
Thanks, Christian
  2 件のコメント
Walter Roberson
Walter Roberson 2015 年 10 月 24 日
Is that exactly 0.7 ? If so then it might not be possible to satisfy the condition.
Christian
Christian 2015 年 10 月 24 日
Good point. Let's say at least 0.7, but as close as possible to 0.7. So stop sampling as soon as the sum is equal or greater than 0.7.

サインインしてコメントする。

採用された回答

Walter Roberson
Walter Roberson 2015 年 10 月 24 日
rp = randperm(N);
loc = find( cumsum(x(rp)) >= 0.7 * sum(x), 1, 'first');
samps = x(rp(1:loc));

その他の回答 (0 件)

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by