Skip to content

Commit

Permalink
Merge pull request #19 from IndrajeetPatil/remove_groupedstats
Browse files Browse the repository at this point in the history
remove groupedstats; closes #18
  • Loading branch information
IndrajeetPatil committed Jan 24, 2020
2 parents fa0e23a + c380735 commit de42720
Show file tree
Hide file tree
Showing 34 changed files with 1,602 additions and 582 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,14 @@ Imports:
crayon (>= 1.3.4),
dplyr (>= 0.8.3),
ez (>= 4.4-0),
groupedstats (>= 0.1.1),
metaBMA (>= 0.6.2),
metafor (>= 2.1-0),
metaplus (>= 0.7-11),
psych (>= 1.9.12.31),
purrr (>= 0.3.3),
rcompanion (>= 2.3.21),
rlang (>= 0.4.2),
sjstats (>= 0.17.7),
stats,
tibble (>= 2.1.3),
tidyr (>= 1.0.0),
Expand Down
12 changes: 4 additions & 8 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export(expr_anova_robust)
export(expr_contingency_tab)
export(expr_corr_test)
export(expr_mann_nonparametric)
export(expr_meta_bayes)
export(expr_meta_parametric)
export(expr_meta_robust)
export(expr_onesample_proptest)
Expand All @@ -33,10 +34,7 @@ export(expr_t_onesample)
export(expr_t_parametric)
export(expr_t_robust)
export(expr_template)
export(lm_effsize_ci)
export(long_to_wide_converter)
export(set_cwd)
export(signif_column)
export(specify_decimal_p)
export(tibble)
importFrom(BayesFactor,anovaBF)
Expand Down Expand Up @@ -87,11 +85,6 @@ importFrom(dplyr,tibble)
importFrom(dplyr,ungroup)
importFrom(dplyr,vars)
importFrom(ez,ezANOVA)
importFrom(groupedstats,lm_effsize_ci)
importFrom(groupedstats,lm_effsize_standardizer)
importFrom(groupedstats,set_cwd)
importFrom(groupedstats,signif_column)
importFrom(groupedstats,specify_decimal_p)
importFrom(metaBMA,meta_random)
importFrom(metaBMA,prior)
importFrom(metafor,rma)
Expand Down Expand Up @@ -121,6 +114,9 @@ importFrom(rlang,expr)
importFrom(rlang,is_formula)
importFrom(rlang,new_formula)
importFrom(rlang,quo_is_null)
importFrom(sjstats,eta_sq)
importFrom(sjstats,omega_sq)
importFrom(stats,aov)
importFrom(stats,chisq.test)
importFrom(stats,cor)
importFrom(stats,cor.test)
Expand Down
6 changes: 5 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
# statsExpressions 0.2.1.9000

NEW FEATURES

- New functions to carry out meta-analysis: `expr_meta_bayes`.

# statsExpressions 0.2.1

NEW FEATURES

- New functions to carry out meta-analysis: `expr_meta_parametric`,
`expr_meta_robust`, `expr_meta_bayes`.
`expr_meta_robust`, `bf_meta`.

# statsExpressions 0.2.0

Expand Down
13 changes: 6 additions & 7 deletions R/helpers_anova_expressions.R
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@
#'
#' @importFrom dplyr select rename matches
#' @importFrom rlang !! enquo eval_tidy expr ensym
#' @importFrom stats lm oneway.test na.omit
#' @importFrom stats aov oneway.test na.omit
#' @importFrom ez ezANOVA
#' @importFrom groupedstats lm_effsize_standardizer
#'
#' @examples
#' \donttest{
Expand Down Expand Up @@ -236,7 +235,7 @@ expr_anova_parametric <- function(data,

# creating a standardized dataframe with effect size and its CIs
effsize_object <-
stats::lm(
stats::aov(
formula = rlang::new_formula({{ y }}, {{ x }}),
data = data,
na.action = na.omit
Expand All @@ -245,12 +244,12 @@ expr_anova_parametric <- function(data,

# creating a standardized dataframe with effect size and its CIs
effsize_df <-
groupedstats::lm_effsize_standardizer(
object = effsize_object,
aov_effsize(
model = effsize_object,
effsize = effsize,
partial = partial,
conf.level = conf.level,
nboot = nboot
ci = conf.level,
iterations = nboot
)

# preparing subtitle
Expand Down
67 changes: 42 additions & 25 deletions R/helpers_bf_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ bf_extractor <- function(bf.object, ...) {
#' set.seed(123)
#'
#' # dataframe containing results
#' bf_results <-
#' bf.df <-
#' statsExpressions::bf_extractor(BayesFactor::correlationBF(
#' x = iris$Sepal.Length,
#' y = iris$Petal.Length
Expand All @@ -66,15 +66,15 @@ bf_extractor <- function(bf.object, ...) {
#'
#' # creating caption (for null)
#' statsExpressions::bf_expr(
#' bf.df = bf_results,
#' bf.df = bf.df,
#' output = "null",
#' k = 3,
#' caption = "Note: Iris dataset"
#' )
#'
#' # creating caption (for alternative)
#' statsExpressions::bf_expr(
#' bf.df = bf_results,
#' bf.df = bf.df,
#' output = "alternative"
#' )
#' }
Expand Down Expand Up @@ -190,7 +190,7 @@ bf_corr_test <- function(data,
# ========================= subtitle preparation ==========================

# extracting results from Bayesian test and creating a dataframe
bf_results <-
bf.df <-
bf_extractor(
BayesFactor::correlationBF(
x = data %>% dplyr::pull({{ x }}),
Expand All @@ -206,7 +206,7 @@ bf_corr_test <- function(data,
if (output != "results") {
bf_message <-
bf_expr(
bf.df = bf_results,
bf.df = bf.df,
output = output,
k = k,
caption = caption
Expand All @@ -218,7 +218,7 @@ bf_corr_test <- function(data,
# return the text results or the dataframe with results
return(switch(
EXPR = output,
"results" = bf_results,
"results" = bf.df,
bf_message
))
}
Expand Down Expand Up @@ -358,7 +358,7 @@ bf_contingency_tab <- function(data,
)

# extracting results from Bayesian test and creating a dataframe
bf_results <-
bf.df <-
bf_extractor(
BayesFactor::contingencyTableBF(
x = table(
Expand Down Expand Up @@ -427,7 +427,7 @@ bf_contingency_tab <- function(data,
pr_y_h1 <- BayesFactor::logMeanExpLogs(tmp_pr_h1)

# computing Bayes Factor and formatting the results
bf_results <-
bf.df <-
dplyr::tibble(bf10 = exp(pr_y_h1 - pr_y_h0)) %>%
bf_formatter(.) %>%
dplyr::mutate(.data = ., prior.concentration = prior.concentration)
Expand All @@ -438,11 +438,11 @@ bf_contingency_tab <- function(data,
# changing aspects of the caption based on what output is needed
if (output %in% c("null", "caption", "H0", "h0")) {
hypothesis.text <- "In favor of null: "
bf.value <- bf_results$log_e_bf01[[1]]
bf.value <- bf.df$log_e_bf01[[1]]
bf.subscript <- "01"
} else {
hypothesis.text <- "In favor of alternative: "
bf.value <- -bf_results$log_e_bf01[[1]]
bf.value <- -bf.df$log_e_bf01[[1]]
bf.subscript <- "10"
}

Expand Down Expand Up @@ -472,7 +472,7 @@ bf_contingency_tab <- function(data,
bf.subscript = bf.subscript,
bf = specify_decimal_p(x = bf.value, k = k),
sampling.plan = sampling_plan_text,
a = specify_decimal_p(x = bf_results$prior.concentration[[1]], k = k)
a = specify_decimal_p(x = bf.df$prior.concentration[[1]], k = k)
)
)
}
Expand Down Expand Up @@ -500,7 +500,7 @@ bf_contingency_tab <- function(data,
top.text = caption,
bf.subscript = bf.subscript,
bf = specify_decimal_p(x = bf.value, k = k),
a = specify_decimal_p(x = bf_results$prior.concentration[[1]], k = k)
a = specify_decimal_p(x = bf.df$prior.concentration[[1]], k = k)
)
)
}
Expand All @@ -510,7 +510,7 @@ bf_contingency_tab <- function(data,
# return the text results or the dataframe with results
return(switch(
EXPR = output,
"results" = bf_results,
"results" = bf.df,
bf_message
))
}
Expand Down Expand Up @@ -675,7 +675,7 @@ bf_ttest <- function(data,
}

# extracting the Bayes factors
bf_results <-
bf.df <-
bf_extractor(bf.object = bf_object) %>%
dplyr::mutate(.data = ., bf.prior = bf.prior)

Expand All @@ -685,7 +685,7 @@ bf_ttest <- function(data,
if (output != "results") {
bf_message <-
bf_expr(
bf.df = bf_results,
bf.df = bf.df,
output = output,
k = k,
caption = caption
Expand All @@ -695,7 +695,7 @@ bf_ttest <- function(data,
# return the text results or the dataframe with results
return(switch(
EXPR = output,
"results" = bf_results,
"results" = bf.df,
bf_message
))
}
Expand Down Expand Up @@ -790,7 +790,7 @@ bf_oneway_anova <- function(data,
dplyr::mutate(.data = ., rowid = as.factor(rowid))

# extracting results from Bayesian test (`y ~ x + id`) and creating a dataframe
bf_results <-
bf.df <-
bf_extractor(BayesFactor::anovaBF(
formula = rlang::new_formula(
{{ rlang::enexpr(y) }}, rlang::expr(!!rlang::enexpr(x) + rowid)
Expand All @@ -812,7 +812,7 @@ bf_oneway_anova <- function(data,
data %<>% tidyr::drop_na(.)

# extracting results from Bayesian test and creating a dataframe
bf_results <-
bf.df <-
bf_extractor(
BayesFactor::anovaBF(
formula = rlang::new_formula({{ y }}, {{ x }}),
Expand All @@ -831,7 +831,7 @@ bf_oneway_anova <- function(data,
if (output != "results") {
bf_message <-
bf_expr(
bf.df = bf_results,
bf.df = bf.df,
output = output,
k = k,
caption = caption
Expand All @@ -841,7 +841,7 @@ bf_oneway_anova <- function(data,
# return the text results or the dataframe with results
return(switch(
EXPR = output,
"results" = bf_results,
"results" = bf.df,
bf_message
))
}
Expand All @@ -855,6 +855,7 @@ bf_oneway_anova <- function(data,
#' @inherit metaBMA::meta_random return Description
#'
#' @inheritParams expr_meta_parametric
#' @inheritParams bf_expr
#' @inheritParams metaBMA::meta_random
#' @inheritDotParams metaBMA::meta_random -y -SE
#'
Expand Down Expand Up @@ -894,7 +895,9 @@ bf_oneway_anova <- function(data,
#' data = df,
#' k = 3,
#' iter = 1500,
#' messages = TRUE
#' messages = TRUE,
#' # customizing analysis with additional arguments
#' control = list(max_treedepth = 15)
#' )
#' }
#'
Expand All @@ -905,6 +908,7 @@ bf_meta <- function(data,
d = prior("norm", c(mean = 0, sd = 0.3)),
tau = prior("invgamma", c(shape = 1, scale = 0.15)),
k = 2,
output = "null",
caption = NULL,
messages = TRUE,
...) {
Expand Down Expand Up @@ -935,18 +939,29 @@ bf_meta <- function(data,
dplyr::filter(.data = ., term == "d")

# dataframe with bayes factors
bf_results <-
bf.df <-
dplyr::tibble(bf10 = meta_res$BF["random_H1", "random_H0"]) %>%
bf_formatter(.)

# changing aspects of the caption based on what output is needed
if (output %in% c("null", "caption", "H0", "h0")) {
hypothesis.text <- "In favor of null: "
bf.value <- bf.df$log_e_bf01[[1]]
bf.subscript <- "01"
} else {
hypothesis.text <- "In favor of alternative: "
bf.value <- bf.df$log_e_bf10[[1]]
bf.subscript <- "10"
}

# prepare the Bayes factor message
bf_text <-
substitute(
atop(displaystyle(top.text),
expr = paste(
"In favor of null: ",
hypothesis.text,
"log"["e"],
"(BF"["01"],
"(BF"[bf.subscript],
") = ",
bf,
", ",
Expand All @@ -962,8 +977,10 @@ bf_meta <- function(data,
)
),
env = list(
hypothesis.text = hypothesis.text,
top.text = caption,
bf = specify_decimal_p(x = bf_results$log_e_bf01[[1]], k = k),
bf.subscript = bf.subscript,
bf = specify_decimal_p(x = bf.value, k = k),
d.pmean = specify_decimal_p(x = df_estimates$mean[[1]], k = k),
d.pmean.LB = specify_decimal_p(x = df_estimates$hpd95_lower[[1]], k = k),
d.pmean.UB = specify_decimal_p(x = df_estimates$hpd95_upper[[1]], k = k)
Expand Down
Loading

2 comments on commit de42720

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R/helpers_contingency_tabs_expressions.R:86:1: style: functions should have cyclomatic complexity of less than 15, this has 16.

expr_contingency_tab <- function(data,
^

R/helpers_effsize_ci.R:98:1: style: functions should have cyclomatic complexity of less than 15, this has 20.

effsize_t_parametric <- function(formula = NULL,
^

R/helpers_effsize_ci.R:440:3: warning: local variable ‘sample_size’ assigned but may not be used

sample_size <- nrow(data_wide)
  ^~~~~~~~~~~

@lintr-bot
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

R/helpers_contingency_tabs_expressions.R:86:1: style: functions should have cyclomatic complexity of less than 15, this has 16.

expr_contingency_tab <- function(data,
^

R/helpers_effsize_ci.R:98:1: style: functions should have cyclomatic complexity of less than 15, this has 20.

effsize_t_parametric <- function(formula = NULL,
^

R/helpers_effsize_ci.R:440:3: warning: local variable ‘sample_size’ assigned but may not be used

sample_size <- nrow(data_wide)
  ^~~~~~~~~~~

Please sign in to comment.