Skip to contents

Takes repeated stratified samples without replacement from the population. See the Details section below for further information.

Usage

repeatedStratifiedSampleWithoutReplacement(k, strata, n, prob = NULL)

Arguments

k

integer, the number of repeated samples to generate

strata

vector of stratification variables. The population size is length(strata)

n

positive integer value, the sample size

prob

(optional) vector of positive numeric values, the probability weights for obtaining the strata elements. If provided, it must be the same length as strata

Value

A list of length k where each element is a vector of indices representing the sampled data.

Details

This function takes repeated samples by using the replicate function and the stratifiedSampleWithoutReplacement sampling function.

Author

Alessandro Barberis

Examples

#Set seed for reproducibility
set.seed(seed = 5381L)

#Define strata
strata = c(rep("a", 3),rep("b", 6))

#Check ratio
table(strata)/length(strata)
#> strata
#>         a         b 
#> 0.3333333 0.6666667 

#Stratified random samples
i = repeatedStratifiedSampleWithoutReplacement(
  k = 2,
  strata = strata,
  n = 3,
)
#Check ratio
table(strata[i[[1]]])/length(strata[i[[1]]])
#> 
#>         a         b 
#> 0.3333333 0.6666667 
table(strata[i[[2]]])/length(strata[i[[2]]])
#> 
#>         a         b 
#> 0.3333333 0.6666667