Why incorrect sampling with weighted randsample?

1 回表示 (過去 30 日間)
Kristin
Kristin 2014 年 2 月 21 日
コメント済み: the cyclist 2014 年 2 月 21 日
Depending on the distribution of the weights w used in randsample(population,k,true,w), the random sampling seems to be incorrect. For example, this problem arises if the weights are as weight2 below, but works correct with weight1:
%% --------------------------------------------------------- %%
values = [-5:5];
weight1 = [0.02 0.03 0.05 0.1 0.0 0.2 0.2 0.1 0.05 0.03 0.02];
weight2 = [0.02 0.00 0.05 0.1 0.35 0.28 0.2 0.0 0.00 0.00 0.00];
n = 1000000;
sample1 = randsample(values,n,true,weight1);
sample2 = randsample(values,n,true,weight2);
%% --------------------------------------------------------- %%
Has anyone else experienced this problem? Is there a workaround?
Best regards Kristin

採用された回答

the cyclist
the cyclist 2014 年 2 月 21 日
Can you please explain the evidence that makes you say that "the random sampling seems to be incorrect"?
When I run the commands
figure
hist(sample1,values)
figure
hist(sample2,values)
the results look as I would expect.
  2 件のコメント
Kristin
Kristin 2014 年 2 月 21 日
I'm so sorry, I made a simple mistake in plotting the distributions. Your reply helped me to see my mistake!
Thanks for taking your time!
/Kristin
the cyclist
the cyclist 2014 年 2 月 21 日
The best form of thanks is the acceptance of an answer. :-)

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by