[R] Generating unordered, with replacement, samples
gpetris at uark.edu
Wed Sep 17 20:55:30 CEST 2014
Thank you, Rui, but I have the feeling that in this way you are drawing uniformly *ordered* samples, and you get a bias if you consider them to be unordered.
From: Rui Barradas [ruipbarradas at sapo.pt]
Sent: Wednesday, September 17, 2014 13:49
To: Giovanni Petris; r-help at R-project.org
Subject: Re: [R] Generating unordered, with replacement, samples
Try function ?sample. Something like, if 'x' is a vector of size n,
sample(x, k, replace = TRUE)
If you want indices into 'x', try instead
sample(n, k, replace = TRUE)
Hope this helps,
Em 17-09-2014 19:25, Giovanni Petris escreveu:
> I am trying to interface in my teaching some elementary probability with Monte Carlo ideas. In sampling from a finite population, the number of distinct samples of size 'k' from a population of size 'n' , when individuals are selected with replacement and the selection order does not matter, is choose(n + k -1, k). Does anyone have a suggestion about how to simulate (uniformly!) one of these possible samples? In a Monte Carlo framework I would like to do it repeatedly, so efficiency is of some relevance.
> Thank you in advance!
> Giovanni Petris
> Associate Professor
> Department of Mathematical Sciences
> University of Arkansas - Fayetteville, AR 72701
> Ph: (479) 575-6324, 575-8630 (fax)
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help