diff --git a/API b/API index 47000209..807089eb 100644 --- a/API +++ b/API @@ -6,6 +6,7 @@ add_expression_col(data, paired = FALSE, statistic.text = NULL, effsize.text = N centrality_description(data, x, y, type = "parametric", conf.level = NULL, tr = 0.2, digits = 2L, ...) contingency_table(data, x, y = NULL, paired = FALSE, type = "parametric", counts = NULL, ratio = NULL, alternative = "two.sided", digits = 2L, conf.level = 0.95, sampling.plan = "indepMulti", fixed.margin = "rows", prior.concentration = 1, ...) corr_test(data, x, y, type = "parametric", digits = 2L, conf.level = 0.95, tr = 0.2, bf.prior = 0.707, ...) +extract_stats_type(type) long_to_wide_converter(data, x, y, subject.id = NULL, paired = TRUE, spread = TRUE, ...) meta_analysis(data, type = "parametric", random = "mixture", digits = 2L, conf.level = 0.95, ...) one_sample_test(data, x, type = "parametric", test.value = 0, alternative = "two.sided", digits = 2L, conf.level = 0.95, tr = 0.2, bf.prior = 0.707, effsize.type = "g", ...) diff --git a/DESCRIPTION b/DESCRIPTION index a7c87acb..b4e46047 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Type: Package Package: statsExpressions Title: Tidy Dataframes and Expressions with Statistical Details -Version: 1.5.4 +Version: 1.5.4.9000 Authors@R: person(given = "Indrajeet", family = "Patil", diff --git a/NAMESPACE b/NAMESPACE index 5220c5d7..9f06f3ec 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -9,6 +9,7 @@ export(as_tibble) export(centrality_description) export(contingency_table) export(corr_test) +export(extract_stats_type) export(long_to_wide_converter) export(meta_analysis) export(one_sample_test) diff --git a/NEWS.md b/NEWS.md index aeb3b0fd..5ac63935 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# statsExpressions 1.5.4.9000 + # statsExpressions 1.5.4 ## MAJOR CHANGES diff --git a/R/add-expression-col.R b/R/add-expression-col.R index b38ab072..af8efc17 100644 --- a/R/add-expression-col.R +++ b/R/add-expression-col.R @@ -101,8 +101,8 @@ add_expression_col <- function( df_expr <- data %>% # convert needed columns to character type .data_to_char(digits, digits.df, digits.df.error) %>% mutate( - statistic.text = statistic.text %||% stat_text_switch(tolower(method)), - es.text = effsize.text %||% estimate_type_switch(tolower(effectsize)), + statistic.text = statistic.text %||% extract_statistic_text(tolower(method)), + es.text = effsize.text %||% extract_estimate_type(tolower(effectsize)), prior.distribution = prior_switch(tolower(method)), n.obs = .prettyNum(n.obs) ) diff --git a/R/centrality-description.R b/R/centrality-description.R index 3c844362..532d633f 100644 --- a/R/centrality-description.R +++ b/R/centrality-description.R @@ -40,7 +40,7 @@ centrality_description <- function( # styler: off centrality <- case_match( - stats_type_switch(type), + extract_stats_type(type), "parametric" ~ "mean", "nonparametric" ~ "median", "robust" ~ "trimmed", diff --git a/R/contingency-table.R b/R/contingency-table.R index b31eb365..8e787d7c 100644 --- a/R/contingency-table.R +++ b/R/contingency-table.R @@ -66,7 +66,7 @@ contingency_table <- function( ...) { # data ------------------------------------------- - type <- stats_type_switch(type) + type <- extract_stats_type(type) test <- ifelse(quo_is_null(enquo(y)), "1way", "2way") data %<>% diff --git a/R/corr-test.R b/R/corr-test.R index 9d9eba52..88121e12 100644 --- a/R/corr-test.R +++ b/R/corr-test.R @@ -37,7 +37,7 @@ corr_test <- function( tr = 0.2, bf.prior = 0.707, ...) { - type <- stats_type_switch(type) + type <- extract_stats_type(type) stats_df <- correlation::correlation( data = select(ungroup(data), {{ x }}, {{ y }}) %>% tidyr::drop_na(), diff --git a/R/meta-analysis.R b/R/meta-analysis.R index 44ffc6b0..dc1b3b16 100644 --- a/R/meta-analysis.R +++ b/R/meta-analysis.R @@ -63,7 +63,7 @@ #' #' # ----------------------- Bayesian ---------------------------------- #' -#' suppressWarnings(meta_analysis(dat, type = "bayes")) +#' meta_analysis(dat, type = "bayes") #' #' @export meta_analysis <- function( @@ -73,7 +73,7 @@ meta_analysis <- function( digits = 2L, conf.level = 0.95, ...) { - type <- stats_type_switch(type) + type <- extract_stats_type(type) # nolint start: line_length_linter. c(.ns, .fn, .f.args) %<-% switch(type, @@ -85,7 +85,6 @@ meta_analysis <- function( check_if_installed(.ns) - # construct a call and then extract a tidy data frame stats_df <- eval(call2(.fn = .fn, .ns = .ns, data = data, !!!.f.args)) %>% tidy_model_parameters(include_studies = FALSE, ci = conf.level) diff --git a/R/one-sample-test.R b/R/one-sample-test.R index 285a66c1..58ac742b 100644 --- a/R/one-sample-test.R +++ b/R/one-sample-test.R @@ -7,7 +7,7 @@ #' @param effsize.type Type of effect size needed for *parametric* tests. The #' argument can be `"d"` (for Cohen's *d*) or `"g"` (for Hedge's *g*). #' @inheritParams long_to_wide_converter -#' @inheritParams stats_type_switch +#' @inheritParams extract_stats_type #' @inheritParams add_expression_col #' @inheritParams two_sample_test #' @inheritParams oneway_anova @@ -46,7 +46,7 @@ one_sample_test <- function( bf.prior = 0.707, effsize.type = "g", ...) { - type <- stats_type_switch(type) + type <- extract_stats_type(type) x_vec <- stats::na.omit(pull(data, {{ x }})) # parametric --------------------------------------- diff --git a/R/oneway-anova.R b/R/oneway-anova.R index d3fbcce1..7463cf73 100644 --- a/R/oneway-anova.R +++ b/R/oneway-anova.R @@ -18,7 +18,7 @@ #' ``` #' #' @inheritParams long_to_wide_converter -#' @inheritParams stats_type_switch +#' @inheritParams extract_stats_type #' @param conf.level Scalar between `0` and `1` (default: `95%` #' confidence/credible intervals, `0.95`). If `NULL`, no confidence intervals #' will be computed. @@ -145,7 +145,7 @@ oneway_anova <- function( ...) { # data ------------------------------------------- - type <- stats_type_switch(type) + type <- extract_stats_type(type) c(x, y) %<-% c(ensym(x), ensym(y)) data %<>% long_to_wide_converter( diff --git a/R/pairwise-comparisons.R b/R/pairwise-comparisons.R index fb31e83c..81e15b40 100644 --- a/R/pairwise-comparisons.R +++ b/R/pairwise-comparisons.R @@ -7,7 +7,7 @@ #' comparisons between group levels with corrections for multiple testing. #' #' @inheritParams long_to_wide_converter -#' @inheritParams stats_type_switch +#' @inheritParams extract_stats_type #' @inheritParams oneway_anova #' @param p.adjust.method Adjustment method for *p*-values for multiple #' comparisons. Possible methods are: `"holm"` (default), `"hochberg"`, @@ -153,7 +153,7 @@ pairwise_comparisons <- function( ...) { # data ------------------------------------------- - type <- stats_type_switch(type) + type <- extract_stats_type(type) c(x, y) %<-% c(ensym(x), ensym(y)) data %<>% long_to_wide_converter( diff --git a/R/switch-functions.R b/R/switch-functions.R index e90d2a0e..853ba5e4 100644 --- a/R/switch-functions.R +++ b/R/switch-functions.R @@ -1,4 +1,4 @@ -#' @name stats_type_switch +#' @name extract_stats_type #' @title Switch the type of statistics. #' #' @description @@ -19,22 +19,25 @@ #' @autoglobal #' #' @examples -#' stats_type_switch("p") -#' stats_type_switch("bf") +#' extract_stats_type("p") +#' extract_stats_type("bf") #' @export # styler: off -stats_type_switch <- function(type) { +extract_stats_type <- function(type) { case_when( - grepl("^n|^s", type) ~ "nonparametric", # s is for Spearman's rho - grepl("^r", type) ~ "robust", - grepl("^b", type) ~ "bayes", - TRUE ~ "parametric" + grepl("^n", type) ~ "nonparametric", + grepl("^r", type) ~ "robust", + grepl("^b", type) ~ "bayes", + TRUE ~ "parametric" ) } +#' @rdname extract_stats_type +#' @export +stats_type_switch <- extract_stats_type #' @noRd -estimate_type_switch <- function(x) { +extract_estimate_type <- function(x) { case_when( .grepl("pearson's c", x) ~ list(quote(widehat(italic("C"))["Pearson"])), .grepl("cohen's d", x) ~ list(quote(widehat(italic("d"))["Cohen"])), @@ -62,7 +65,7 @@ estimate_type_switch <- function(x) { } #' @noRd -stat_text_switch <- function(x) { +extract_statistic_text <- function(x) { case_when( grepl("^welch", x) ~ list(quote(italic("t")["Welch"])), grepl("afex| of means$", x) ~ list(quote(italic("F")["Fisher"])), @@ -93,7 +96,7 @@ prior_switch <- function(x) { ) } -#' @note Don't curry using `purrr::partial()` because it causes `Found a .Internal call` warning. +#' @note Don't curry using `purrr::partial()` because it causes `"Found a .Internal call"` warning. #' @noRd .grepl <- function(pattern, x) grepl(pattern, x, fixed = TRUE) diff --git a/R/two-sample-test.R b/R/two-sample-test.R index a39198ce..3a82c927 100644 --- a/R/two-sample-test.R +++ b/R/two-sample-test.R @@ -5,7 +5,7 @@ #' Parametric, non-parametric, robust, and Bayesian two-sample tests. #' #' @inheritParams long_to_wide_converter -#' @inheritParams stats_type_switch +#' @inheritParams extract_stats_type #' @inheritParams one_sample_test #' @inheritParams oneway_anova #' @inheritParams stats::t.test @@ -49,7 +49,7 @@ two_sample_test <- function( ...) { # data ------------------------------------------- - type <- stats_type_switch(type) + type <- extract_stats_type(type) c(x, y) %<-% c(ensym(x), ensym(y)) data %<>% long_to_wide_converter( diff --git a/man/stats_type_switch.Rd b/man/extract_stats_type.Rd similarity index 85% rename from man/stats_type_switch.Rd rename to man/extract_stats_type.Rd index 20c3c524..ed778707 100644 --- a/man/stats_type_switch.Rd +++ b/man/extract_stats_type.Rd @@ -1,9 +1,12 @@ % Generated by roxygen2: do not edit by hand % Please edit documentation in R/switch-functions.R -\name{stats_type_switch} +\name{extract_stats_type} +\alias{extract_stats_type} \alias{stats_type_switch} \title{Switch the type of statistics.} \usage{ +extract_stats_type(type) + stats_type_switch(type) } \arguments{ @@ -24,6 +27,6 @@ non-parametric, robust, and Bayesian. This switch function converts strings entered by users to a common pattern for convenience. } \examples{ -stats_type_switch("p") -stats_type_switch("bf") +extract_stats_type("p") +extract_stats_type("bf") } diff --git a/man/meta_analysis.Rd b/man/meta_analysis.Rd index da2fbb05..b8639021 100644 --- a/man/meta_analysis.Rd +++ b/man/meta_analysis.Rd @@ -128,6 +128,6 @@ meta_analysis(dat, type = "random", random = "normal") # ----------------------- Bayesian ---------------------------------- -suppressWarnings(meta_analysis(dat, type = "bayes")) +meta_analysis(dat, type = "bayes") \dontshow{\}) # examplesIf} } diff --git a/tests/testthat/test-meta-random-bayes.R b/tests/testthat/test-meta-random-bayes.R index e5cc5f9e..385f09ed 100644 --- a/tests/testthat/test-meta-random-bayes.R +++ b/tests/testthat/test-meta-random-bayes.R @@ -4,13 +4,13 @@ test_that( skip_if_not_installed("metaBMA") set.seed(123) - df <- suppressWarnings(meta_analysis( + df <- meta_analysis( type = "bayes", data = data_meta, digits = 3L, iter = 1000L, summarize = "integrate" - )) + ) expect_type(df, "list") diff --git a/tests/testthat/test-stats-type-switch.R b/tests/testthat/test-stats-type-switch.R index 0eed579a..91ce5b7e 100644 --- a/tests/testthat/test-stats-type-switch.R +++ b/tests/testthat/test-stats-type-switch.R @@ -1,12 +1,12 @@ test_that( desc = "switch for stats type works", code = { - expect_identical(stats_type_switch("p"), "parametric") - expect_identical(stats_type_switch("pearson"), "parametric") - expect_identical(stats_type_switch("non-parametric"), "nonparametric") - expect_identical(stats_type_switch("np"), "nonparametric") - expect_identical(stats_type_switch("r"), "robust") - expect_identical(stats_type_switch("bf"), "bayes") - expect_identical(stats_type_switch("xxx"), "parametric") + expect_identical(extract_stats_type("p"), "parametric") + expect_identical(extract_stats_type("pearson"), "parametric") + expect_identical(extract_stats_type("non-parametric"), "nonparametric") + expect_identical(extract_stats_type("np"), "nonparametric") + expect_identical(extract_stats_type("r"), "robust") + expect_identical(extract_stats_type("bf"), "bayes") + expect_identical(extract_stats_type("xxx"), "parametric") } )