Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added bootstrap options parallel and ncpus #87

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions R/kruskal_effesize.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,19 @@ NULL
#' group_by(supp) %>%
#' kruskal_effsize(len ~ dose)
#' @export
kruskal_effsize <- function(data, formula, ci = FALSE, conf.level = 0.95, ci.type = "perc", nboot = 1000){
kruskal_effsize <- function(data, formula, ci = FALSE, conf.level = 0.95, ci.type = "perc", nboot = 1000, parallel = "multicore", ncpus = parallel::detectCores()){
args <- as.list(environment()) %>%
.add_item(method = "kruskal_effsize")
data %>%
doo(
.kruskal_effsize, formula, ci = ci, conf.level = conf.level,
ci.type = ci.type, nboot = nboot
ci.type = ci.type, nboot = nboot, parallel = parallel, ncpus = ncpus
) %>%
set_attrs(args = args) %>%
add_class(c("rstatix_test", "kruskal_effsize"))
}

.kruskal_effsize <- function(data, formula, ci = FALSE, conf.level = 0.95, ci.type = "perc", nboot = 1000){
.kruskal_effsize <- function(data, formula, ci = FALSE, conf.level = 0.95, ci.type = "perc", nboot = 1000, parallel = "multicore", ncpus = parallel::detectCores()){
results <- eta_squared_h(data, formula)
# Confidence interval of the effect size r
if (ci == TRUE) {
Expand All @@ -67,7 +67,7 @@ kruskal_effsize <- function(data, formula, ci = FALSE, conf.level = 0.95, ci.ty
}
CI <- get_boot_ci(
data, stat.func, conf.level = conf.level,
type = ci.type, nboot = nboot
type = ci.type, nboot = nboot, parallel = parallel, ncpus = ncpus
)
results <- results %>%
add_columns(conf.low = CI[1], conf.high = CI[2], .after = "effsize")
Expand Down
6 changes: 3 additions & 3 deletions R/utilities.R
Original file line number Diff line number Diff line change
Expand Up @@ -701,10 +701,10 @@ get_pairwise_comparison_methods <- function(){
}

# Bootstrap confidence intervals -------------------------
get_boot_ci <- function(data, stat.func, conf.level = 0.95, type = "perc", nboot = 500){
get_boot_ci <- function(data, stat.func, conf.level = 0.95, type = "perc", nboot = 500, parallel = "multicore", ncpus = parallel::detectCores()){
required_package("boot")
Boot = boot::boot(data, stat.func, R = nboot)
BCI = boot::boot.ci(Boot, conf = conf.level, type = type, parallel = "multicore")
Boot = boot::boot(data, stat.func, R = nboot, parallel = parallel, ncpus = ncpus)
BCI = boot::boot.ci(Boot, conf = conf.level, type = type)
type <- switch(
type, norm = "normal", perc = "percent",
basic = "basic", bca = "bca", stud = "student", type
Expand Down
9 changes: 6 additions & 3 deletions R/wilcox_effsize.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ NULL
#'@param ci.type The type of confidence interval to use. Can be any of "norm",
#' "basic", "perc", or "bca". Passed to \code{boot::boot.ci}.
#'@param nboot The number of replications to use for bootstrap.
#'@param parallel The type of parallel operation to be used (if any) (Default: "multicore").
#'@param ncpus The number of processes to be used in parallel operation:
#' typically one would chose this to the number of available CPUs (Default: parallel::detectCores()).
#'@param ... Additional arguments passed to the functions
#' \code{coin::wilcoxsign_test()} (case of one- or paired-samples test) or
#' \code{coin::wilcox_test()} (case of independent two-samples test).
Expand Down Expand Up @@ -68,7 +71,7 @@ NULL
wilcox_effsize <- function(data, formula, comparisons = NULL, ref.group = NULL,
paired = FALSE, alternative = "two.sided",
mu = 0, ci = FALSE, conf.level = 0.95, ci.type = "perc",
nboot = 1000, ...){
nboot = 1000, parallel = "multicore", ncpus = parallel::detectCores(), ...){

env <- as.list(environment())
args <- env %>% .add_item(method = "wilcox_effsize")
Expand Down Expand Up @@ -100,7 +103,7 @@ wilcox_effsize <- function(data, formula, comparisons = NULL, ref.group = NULL,

# Wilcoxon test using coin R package; returns effect size
coin.wilcox.test <- function(x, y = NULL, mu = 0, paired = FALSE, alternative = c("two.sided", "less", "greater"),
ci = FALSE, conf.level = 0.95, ci.type = "perc", nboot = 1000, ...){
ci = FALSE, conf.level = 0.95, ci.type = "perc", nboot = 1000, parallel = "multicore", ncpus = parallel::detectCores(), ...){
required_package("coin")

alternative <- match.arg(alternative)
Expand Down Expand Up @@ -156,7 +159,7 @@ coin.wilcox.test <- function(x, y = NULL, mu = 0, paired = FALSE, alternative =
}
CI <- get_boot_ci(
data, stat.func, conf.level = conf.level,
type = ci.type, nboot = nboot
type = ci.type, nboot = nboot, parallel = parallel, ncpus = ncpus
)
results <- results %>% mutate(conf.low = CI[1], conf.high = CI[2])
}
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -125,3 +125,4 @@ Ss'
tidyverse
tidyverse'
Manova
detectCores
9 changes: 8 additions & 1 deletion man/kruskal_effsize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions man/wilcox_effsize.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.