I created a distribution by
pop <- rexp(1000)+rexp(1000)+rexp(1000)
Now an uniform random sample is
index <- floor(1000*runif(100))+1
samp1 <- pop[index]
and the histograms of pop and samp1 are very similar as expected, Now to simulate a sample obtained by point counting method I did
cupop <- cumsum(pop)
popmax <- cupop[1000]
index <- popmax * runif(100)
samp2 <- rep(0,100)
now for each value in index I have to find the last point in cupop that is less than , then the next one is the chosen
for( i in 1:100) {
xi <- which(cupop < index[i])
samp2[i] <- pop[xi[length(xi)]+1]
}
Q: is there a more elegant and general way to do this sampling?
As it is it works but look clumsy
Thanks
Heberto Ghezzo Ph.D.
Meakins-Christie Labs
McGill University
Montreal - Canada
______________________________________________ [EMAIL PROTECTED] mailing list https://www.stat.math.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
