Rで不等確率サンプリングに使用されているアルゴリズムについてもっと読みたいのですが、数時間検索しても何も見つかりませんでした。私はそれが Art of Computer Programming のアルゴリズムかもしれないと思っていましたが、それを実証することもできませんでした. R の random.c の特定の関数は と呼ばれProbSampleNoReplace()
ます。
確率のベクトルと、選択された項目のベクトルを使用しprob[]
た目的のサンプル サイズが与えられた場合n
ans[]
For each element j in prob[] assign an index perm[j]
Sort the list in order of probability value, largest first
totalmass = 1
For (h=0, n1= n-1, h<nans, h++,n1-- )
rt = totalmass * rand(in 0:1)
mass = 0
**sum the probabilities, largest first, until the sum is bigger than rt**
for(j=0;j<n1;j++)
mass += prob[j]
if rt <= mass then break
ans[h] = perm[j]
**reduce size of totalmass to reflect removed item**
totalmass -= prob[j]
**reset the indices to be sequential**
for(k=j, k<n1, k++)
prob[k] = prob[k+1]
perm[k] = perm[k+1]