Bob/All
The code below gives a uniform integer sample of 20 without replacement.
model
{
# assign a random uniform probability to each population member
for (j in 1:N){
p[j]~dunif(0,1);
}
for (i in 1:5){
sss[i]<-ranked(p[],i); # find the five lowest probabilities
for (j in 1:N){
order[i,j]<-equals(sss[i],p[j])*j; # find the ranks of the five
lowest probabilities
}
int.sss[i]<-sum(order[i,]); # collapse rank vector into scalar
chosen[i]<-sample[int.sss[i]];
}
}
# data
list(sample=c(1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20),N=20)
# initial values
list(p=c(0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5,0.5
,0.5,0.5,0.5))
Adrian Barnett
University of Queensland
-----Original Message-----
From: Anon. [mailto:[log in to unmask]]
Sent: Thursday, 22 May 2003 3:20 AM
To: [log in to unmask]
Subject: [BUGS] Sampling without replacement?
Hello everyone!
A couple of us have been struggling with a fiendishly difficult problem
- sampling without replacement. We have a vector of (say) 20 integers,
and we want to use WinBugs to sample 5 of them without replacement (the
context is model selection - having 20 possible covariates, but only
allowing a maximum of 5 in the model). We've tried a few things, but I
suspect there is a neat and cunning way of doing it. Any ideas, anyone?
Bob
--
Bob O'Hara
Rolf Nevanlinna Institute
P.O. Box 4 (Yliopistonkatu 5)
FIN-00014 University of Helsinki
Finland
Telephone: +358-9-191 23743
Mobile: +358 50 599 0540
Fax: +358-9-191 22 779
WWW: http://www.RNI.Helsinki.FI/~boh/
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at
www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
-------------------------------------------------------------------
This list is for discussion of modelling issues and the BUGS software.
For help with crashes and error messages, first mail [log in to unmask]
To mail the BUGS list, mail to [log in to unmask]
Before mailing, please check the archive at www.jiscmail.ac.uk/lists/bugs.html
Please do not mail attachments to the list.
To leave the BUGS list, send LEAVE BUGS to [log in to unmask]
If this fails, mail [log in to unmask], NOT the whole list
|