R/stratified-samplers.r
stratified-samplers.Rd
These functions generate stratified samples of any dimension including the unit line segment in 1-dimensional space, the unit square in 2-space, the unit cube in 3-space.
sample_strat_segment(n, bins) sample_strat_square(n, bins) sample_strat_cube(n, bins) sample_stratify(n, bins, dim)
n | Number of observations. |
---|---|
bins | Number of intervals per dimension for the stratification. |
dim | Dimensional space of sample. |
(Details.)
set.seed(28522L) #Stratified sample in 1-dimension with 10 intervals values <- sample_strat_segment(13, 10) x <- cbind(values, rep(0, 13)) plot(x, asp = 1, pch = 19, cex = .5, xlab = 'x', ylab = '')#Stratified sample of a unit square with 100 cells x <- sample_strat_square(110, 10) plot(x, asp = 1, pch = 19, cex = .5, xlab = 'x', ylab = 'y')#Stratified sample of a unit cube with 27 cells x <- sample_strat_cube(27, 3) #Bird's eye view of the cube plot(x[, c(1, 2)], asp = 1, pch = 19, cex = .5, xlab = 'x', ylab = 'y')#All of the same illustrations, but only using sample_stratify() #Stratified sample in 1-dimension with 10 intervals values <- sample_stratify(13,10,1) x <- cbind(values,rep(0,13)) plot(x, asp = 1, pch = 19, cex = .5, xlab = 'x', ylab = '')#Stratified sample of a unit square with 100 cells x <- sample_stratify(110,10, 2) plot(x, asp = 1, pch = 19, cex = .5, xlab = 'x', ylab = 'y')#Stratified sample of a unit cube with 27 cells x <- sample_stratify(27,3, 3) #Bird's eye view of the cube plot(x[,c(1,2)], asp = 1, pch = 19, cex = .5, xlab = 'x', ylab = 'y')#Stratified sample of a unit 4-cube with 81 cells x <- sample_stratify(81, 3, 4) #One view of the cube plot(x[,c(1,2)], asp = 1, pch = 19, cex = .5, xlab = 'x', ylab = 'y')