From 7674406334d0499220882c5cf1aeeef8ebbfc634 Mon Sep 17 00:00:00 2001 From: Th3Bust3r <34665453+Th3Bust3r@users.noreply.github.com> Date: Mon, 15 May 2023 17:13:59 +0000 Subject: [PATCH 1/2] Added Stratified Randomization as a sampling method for MultiCellMarketSelection. --- R/MultiCell.R | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/R/MultiCell.R b/R/MultiCell.R index 5fcea4f96..ed78e5573 100644 --- a/R/MultiCell.R +++ b/R/MultiCell.R @@ -147,7 +147,7 @@ MultiCellMarketSelection <- function(data, } # Check Sampling Method - if(!(tolower(sampling_method) %in% c("systematic"))){ + if(!(tolower(sampling_method) %in% c("systematic", "blockrand"))){ stop("\nEnter a valid sampling_method (check the function documentation for more details).") } @@ -202,6 +202,14 @@ MultiCellMarketSelection <- function(data, rank_by_loc$cell[seq(r[i], locs_N, k)] <- i } } + # Stratified or 'Block' Randomization + else if(tolower(sampling_method) == "blockrand"){ + rank_by_loc$strata <- ceiling((1:locs_N/k)) + + for (i in 1:max(rank_by_loc$strata)){ + suppressWarnings(rank_by_loc$cell[rank_by_loc$strata==i] <- sample(1:k,k)) + } + } # Initializing output objects GeoLift_Markets <- list() From 0b3c6588bbf65aa31dbb130e465c6d47591d203e Mon Sep 17 00:00:00 2001 From: Th3Bust3r <34665453+Th3Bust3r@users.noreply.github.com> Date: Mon, 15 May 2023 17:27:51 +0000 Subject: [PATCH 2/2] Added Stratified Randomization as a sampling method for MultiCellMarketSelection --- R/MultiCell.R | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/R/MultiCell.R b/R/MultiCell.R index ed78e5573..d3d3d6b6c 100644 --- a/R/MultiCell.R +++ b/R/MultiCell.R @@ -147,7 +147,7 @@ MultiCellMarketSelection <- function(data, } # Check Sampling Method - if(!(tolower(sampling_method) %in% c("systematic", "blockrand"))){ + if(!(tolower(sampling_method) %in% c("systematic", "stratified"))){ stop("\nEnter a valid sampling_method (check the function documentation for more details).") } @@ -203,8 +203,8 @@ MultiCellMarketSelection <- function(data, } } # Stratified or 'Block' Randomization - else if(tolower(sampling_method) == "blockrand"){ - rank_by_loc$strata <- ceiling((1:locs_N/k)) + else if(tolower(sampling_method) == "stratified"){ + rank_by_loc$strata <- ceiling(1:locs_N/k) for (i in 1:max(rank_by_loc$strata)){ suppressWarnings(rank_by_loc$cell[rank_by_loc$strata==i] <- sample(1:k,k))