Skip to content
Prev 206086 / 398503 Next

Conditional Sampling

On 12-Jan-10 12:58:13, ehcpieterse wrote:
If your second sampling is to be on the same footing as the first,
i.e. a random subset of 5 out of the remaining 90, then this is
equivalent to sampling 15 in the first place and using the first
10 of these as your first sample:

  set.seed(54321)
  x0 <- sample(1:100, 15, replace=F)
  x  <- x0[1:10]
  y  <- x0[-(1:10)]
  x0
  # [1] 43 50 18 27 21 83  5 20 32 34 13 61  4 57 86
  x
  # [1] 43 50 18 27 21 83  5 20 32 34
  y
  # [1] 13 61  4 57 86

  set.seed(54321)
  sample(1:100, 10, replace=F)
  # [1] 43 50 18 27 21 83  5 20 32 34

However, if the manner of taking the second sample from the
remainder will depend on the results of the first sample, then
further consideration is necessary. If this is the case, can you
indicate how the values in the first sample would influence how
the second sample is to be obtained?

Another approach, which leaves more options, is to use sample.int():

  set.seed(54321)
  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]
  y <- sample(Y,5,replace=FALSE)

  x
  # [1] 43 50 18 27 21 83  5 20 32 34 ## (as before)
  y
  # [1] 14 70  4 66 96                ## (as before)

Hoping this helps,
Ted.

--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 12-Jan-10                                       Time: 13:21:21
------------------------------ XFMail ------------------------------