Generate Stratified Bootstrap Samples for limRots
Source:R/Bootstrap_functions.r
bootstrapSamples.limRots.Rd
This function generates stratified bootstrap samples based on the groupings and additional factors in the metadata. The function ensures that samples are drawn proportionally based on strata defined by the interaction of factor columns in the metadata.
Arguments
- B
Integer. The number of bootstrap samples to generate.
- meta.info
Data frame. Metadata containing sample information, where each row corresponds to a sample. Factor columns in
meta.info
are used to define strata for sampling.- group.name
Character. The name of the column in
meta.info
that defines the grouping variable for the samples.
Value
A matrix of dimension B
x n
, where n
is the
number of samples. Each row corresponds to a bootstrap sample, and each
entry is a resampled row name from the metadata, stratified by group and
additional factors.
Details
The function works by first identifying the factors in the meta.info
data
frame that are used to create strata for sampling. Within each group defined
by group.name
, the function samples according to the strata proportions,
ensuring that samples are drawn from the correct groups and strata in a
proportional manner.
Examples
# Example usage:
set.seed(123)
meta.info <- data.frame(
group = rep(c(1, 2), each = 5),
batch = rep(c("A", "B"), 5),
row.names = paste0("Sample", 1:10)
)
meta.info$batch <- as.factor(meta.info$batch)
bootstrapSamples.limRots(B = 10, meta.info = meta.info, group.name = "group")
#> [,1] [,2] [,3] [,4] [,5] [,6] [,7]
#> [1,] "Sample5" "Sample5" "Sample5" "Sample4" "Sample2" "Sample9" "Sample9"
#> [2,] "Sample3" "Sample3" "Sample1" "Sample4" "Sample2" "Sample9" "Sample7"
#> [3,] "Sample1" "Sample1" "Sample1" "Sample2" "Sample4" "Sample9" "Sample7"
#> [4,] "Sample5" "Sample3" "Sample1" "Sample2" "Sample2" "Sample7" "Sample9"
#> [5,] "Sample5" "Sample1" "Sample1" "Sample4" "Sample2" "Sample7" "Sample9"
#> [6,] "Sample5" "Sample3" "Sample1" "Sample4" "Sample2" "Sample7" "Sample9"
#> [7,] "Sample1" "Sample1" "Sample5" "Sample2" "Sample4" "Sample7" "Sample7"
#> [8,] "Sample5" "Sample3" "Sample3" "Sample2" "Sample4" "Sample9" "Sample9"
#> [9,] "Sample3" "Sample3" "Sample1" "Sample4" "Sample4" "Sample7" "Sample7"
#> [10,] "Sample1" "Sample3" "Sample1" "Sample4" "Sample4" "Sample7" "Sample7"
#> [,8] [,9] [,10]
#> [1,] "Sample8" "Sample10" "Sample6"
#> [2,] "Sample10" "Sample10" "Sample6"
#> [3,] "Sample8" "Sample6" "Sample8"
#> [4,] "Sample10" "Sample8" "Sample6"
#> [5,] "Sample6" "Sample10" "Sample6"
#> [6,] "Sample10" "Sample6" "Sample8"
#> [7,] "Sample6" "Sample10" "Sample8"
#> [8,] "Sample10" "Sample10" "Sample6"
#> [9,] "Sample8" "Sample10" "Sample10"
#> [10,] "Sample10" "Sample8" "Sample10"