Description Usage Arguments Author(s) Examples
View source: R/stratified_sampling.R
Perform a stratified sampling from a vector of group labels: each initial group is replaced by random labels proportional to the initial group proportions.
1 | StratifiedSampling(labels, size = length(labels))
|
labels |
a vector with labels to be resampled |
size=length(labels) |
size of the output (resampled) vector |
Jacques.van-Helden\@univ-amu.fr
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ## Generate a vector of group labels
labels <- rep(x = c("A", "B", "C", "D"), times = c(256, 64, 16, 4))
## Non-stratified sampling
nstr <- sample(labels, size = length(labels) , replace = FALSE)
table(labels, nstr)
## Repeat this several times: the proportions vary between iterations
## Stratified permutation of group labels
str1 <- StratifiedSampling(labels)
## str1 has same proportions as labels (except for rounding of group sizes)
table(labels, str1)
## Second stratified permutation
str2 <- StratifiedSampling(labels)
## str2 has same proportions as labels (except for rounding of group sizes)
table(labels, str2)
## str1 and str2 are different and independent
table(str1, str2)
## Subsampling
str3 <- StratifiedSampling(labels, size = length(labels) * 2/3)
## str3 has same proportions as labels (except for rounding of group sizes)
table(str3)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.