Skip to contents

Takes repeated balanced samples with replacement from the population. See the Details section below for further information.

Usage

repeatedBalancedSampleWithReplacement(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 balancedSampleWithReplacement 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 

#Balanced random samples
i = repeatedBalancedSampleWithReplacement(
  k = 2,
  strata = strata,
  n = 6
)
#Check ratio
table(strata[i[[1]]])/length(strata[i[[1]]])
#> 
#>   a   b 
#> 0.5 0.5 
table(strata[i[[2]]])/length(strata[i[[2]]])
#> 
#>   a   b 
#> 0.5 0.5