using mstage() in R to draw stratified samples

28 Views Asked by At

I trying to use the mstage() function in R to draw a multi-stage stratified sample and don't know how to. I wonder if anyone can help?

The data is in the end.

What I want to achieve is:

At the first stage, draw a stratified sample (stratified by A/B/C in the "group" column). Let's say we randomly draw

  • 10 records that belong to group A,
  • 20 from group B, and
  • 30 from group C.

At the second stage, do another stratified sample but only within the selected records. Let's say we randomly draw:

  • 5 from the 10 selected records in A
  • 10 from the 20 selected records in B, and
  • 15 from the 30 selected records in C.

Given the data below and what I want to achieve, how would you complete this mstage() function call in the end? I am assuming it can be done via mstage() but do let me know if it is not the case!

library(sampling)
library(data.table)

set.seed(345092123)

data_sample_frame <- 
  data.table(group = sample(LETTERS[1:3], 
                            500, 
                            prob = c(1, 2, 3),
                            replace = T))

data_sample_frame[, id := 1:.N]


setorder(data_sample_frame, group)

set.seed(2340598)

mstage(data_sample_frame,
       stage = list("stratified", ??, ??),
       varnames = list("group", ??, ??),
       size = list(size1 = table(data_sample_frame$group),
                   size2 = c(10, 20, 30),
                   size3 = ??),
       method = list("", ??, ??))

I know I can use two strata() calls separately to solve my question but just wonder if mstage() can do both stages in one go.

0

There are 0 best solutions below