Repeated Balanced Random Samples
Source:R/2-resampling-functions.R
repeatedBalancedSampleWithoutReplacement.Rd
Takes repeated balanced 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 balancedSampleWithoutReplacement
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
#Balanced random samples
i = repeatedBalancedSampleWithoutReplacement(
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