Repeated Stratified Random Samples
Source:R/2-resampling-functions.R
repeatedStratifiedSampleWithoutReplacement.Rd
Takes repeated stratified samples without replacement from the population. See the Details section below for further information.
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 asstrata
Details
This function takes repeated samples by using the replicate
function and the stratifiedSampleWithoutReplacement
sampling
function.
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