[R] Conditional Sampling

Greg Snow Greg.Snow at imail.org
Tue Jan 12 19:46:44 CET 2010


The last 2 lines of your code can be replaced with:

M <- replicate(1000, sample(Y,5,replace=FALSE) )



-- 
Gregory (Greg) L. Snow Ph.D.
Statistical Data Center
Intermountain Healthcare
greg.snow at imail.org
801.408.8111


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of Ted Harding
> Sent: Tuesday, January 12, 2010 7:34 AM
> To: r-help at r-project.org
> Cc: ehcpieterse
> Subject: Re: [R] Conditional Sampling
> 
> On 12-Jan-10 14:00:24, ehcpieterse wrote:
> > Thanks Ted, your solution does make perfect sense.
> >
> > The only question I still have is that I would like to sample
> > the remaining 5 observations after I have randomly selected the
> > first 10. Given the initial 10, I would like to sample the
> > following 5 say 1,000 times to get a simulated conditional sample,
> > if that makes any sense.
> >
> > I want to build this into an iterative process to see how the
> > first sample affects the resulting samples. Even though all the
> > observations have the same probabilty to get sampled, they each
> > have a different expected value.
> > --
> 
> OK, if I now understand you, you are interested in the properties
> of the remaining (90) observations, given that they do not include
> any of the (10) cases sampled in the first round.
> 
> In that case, I think you should adopt the sample.int() approach
> I also suggested:
> 
>   X <- (1:100) ## (or any other 100 values)
>   n <- sample.int(100,10,replace=FALSE) ## returns subset of (1:100)
>   x <- X[n]
>   Y <- X[-n]   ## The set remaining after the first 10 were taken
>   ## Now you can sample repeatedly from Y until your eyes fall out.
>   ## So build up a matrix of (say) 1000 samples from Y:
>   M <- sample(Y,5,replace=FALSE)
>   for(i in (2:1000)){ M <- rbind(M,sample(Y,5,replace=FALSE)) }
> 
> The repeated samples M of 5 from Y of course imply replacing each
> sample of 5 back in Y, so they are available at each turn. You can
> not, of course, sample 1000*5 from 100 without replacement! (Each
> sample of 5 is obtained without replacement, however).
> 
> I hope this is getting close!
> Ted.
> 
> --------------------------------------------------------------------
> E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
> Fax-to-email: +44 (0)870 094 0861
> Date: 12-Jan-10                                       Time: 14:34:13
> ------------------------------ XFMail ------------------------------
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> 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 mailing list