Skip to content
This repository has been archived by the owner on Jun 25, 2021. It is now read-only.

Commit

Permalink
default to dataframe as output argument
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Oct 14, 2020
1 parent 8f9479c commit 2ba6b75
Show file tree
Hide file tree
Showing 27 changed files with 66 additions and 78 deletions.
10 changes: 5 additions & 5 deletions API
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

## Exported functions

bf_contingency_tab(data, x, y = NULL, counts = NULL, ratio = NULL, sampling.plan = "indepMulti", fixed.margin = "rows", prior.concentration = 1, caption = NULL, output = "results", k = 2L, ...)
bf_corr_test(data, x, y, bf.prior = 0.707, caption = NULL, output = "results", k = 2L, ...)
bf_contingency_tab(data, x, y = NULL, counts = NULL, ratio = NULL, sampling.plan = "indepMulti", fixed.margin = "rows", prior.concentration = 1, caption = NULL, output = "dataframe", k = 2L, ...)
bf_corr_test(data, x, y, bf.prior = 0.707, caption = NULL, output = "dataframe", k = 2L, ...)
bf_expr(bf.object, k = 2L, conf.level = 0.95, conf.method = "hdi", centrality = "median", output = "null", caption = NULL, anova.design = FALSE, ...)
bf_extractor(bf.object, ...)
bf_meta(data, d = prior("norm", c(mean = 0, sd = 0.3)), tau = prior("invgamma", c(shape = 1, scale = 0.15)), k = 2L, output = "results", caption = NULL, messages = TRUE, ...)
bf_oneway_anova(data, x, y, bf.prior = 0.707, caption = NULL, output = "results", paired = FALSE, k = 2L, ...)
bf_ttest(data, x, y = NULL, test.value = 0, paired = FALSE, bf.prior = 0.707, caption = NULL, output = "results", k = 2L, ...)
bf_meta(data, d = prior("norm", c(mean = 0, sd = 0.3)), tau = prior("invgamma", c(shape = 1, scale = 0.15)), k = 2L, output = "dataframe", caption = NULL, ...)
bf_oneway_anova(data, x, y, bf.prior = 0.707, caption = NULL, output = "dataframe", paired = FALSE, k = 2L, ...)
bf_ttest(data, x, y = NULL, test.value = 0, paired = FALSE, bf.prior = 0.707, caption = NULL, output = "dataframe", k = 2L, ...)
meta_data_check(data)

## Reexported objects
Expand Down
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ BREAKING CHANGES
hypothesis (`BF10`) and its `log` value to avoid cluttered dataframe since
all the other columns were essentially mathematical transformations of it
and not really relevant.

- The `output` argument's default value has been changed from too generic
`"results"` to `"dataframe"`.

MAJOR CHANGES

Expand Down
4 changes: 2 additions & 2 deletions R/bf_contingency_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ bf_contingency_tab <- function(data,
fixed.margin = "rows",
prior.concentration = 1,
caption = NULL,
output = "results",
output = "dataframe",
k = 2L,
...) {

Expand Down Expand Up @@ -230,7 +230,7 @@ bf_contingency_tab <- function(data,
# return the text results or the dataframe with results
return(switch(
EXPR = output,
"results" = dplyr::select(df, -dplyr::matches("error|time|code")),
"dataframe" = dplyr::select(df, -dplyr::matches("error|time|code")),
bf_message
))
}
4 changes: 2 additions & 2 deletions R/bf_corr_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ bf_corr_test <- function(data,
y,
bf.prior = 0.707,
caption = NULL,
output = "results",
output = "dataframe",
k = 2L,
...) {

Expand All @@ -62,7 +62,7 @@ bf_corr_test <- function(data,
# return the text results or the dataframe with results
switch(
EXPR = output,
"results" = bf_extractor(bf_object),
"dataframe" = bf_extractor(bf_object),
bf_expr(bf_object, k = k, output = output, caption = caption, ...)
)
}
24 changes: 9 additions & 15 deletions R/bf_meta.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#' sizes or outcomes) and `std.error` (corresponding standard errors). These
#' two columns will be used for `yi` and `sei` arguments in `metafor::rma`
#' (for parametric analysis) or `metaplus::metaplus` (for robust analysis).
#' @param messages Deprecated. Retained only for backward compatibility.
#' @inheritParams bf_expr
#' @inheritParams metaBMA::meta_random
#' @inheritDotParams metaBMA::meta_random -y -SE
Expand Down Expand Up @@ -48,7 +47,6 @@
#' data = df,
#' k = 3,
#' iter = 1500,
#' messages = TRUE,
#' # customizing analysis with additional arguments
#' control = list(max_treedepth = 15)
#' )
Expand All @@ -61,9 +59,8 @@ bf_meta <- function(data,
d = prior("norm", c(mean = 0, sd = 0.3)),
tau = prior("invgamma", c(shape = 1, scale = 0.15)),
k = 2L,
output = "results",
output = "dataframe",
caption = NULL,
messages = TRUE,
...) {

# check the data contains needed column
Expand All @@ -72,7 +69,7 @@ bf_meta <- function(data,
#----------------------- meta-analysis -------------------------------

# extracting results from random-effects meta-analysis
meta_res <-
mod <-
metaBMA::meta_random(
y = data$estimate,
SE = data$std.error,
Expand All @@ -84,12 +81,9 @@ bf_meta <- function(data,
#----------------------- preparing caption -------------------------------

# creating a dataframe with posterior estimates
df_estimates <-
as_tibble(meta_res$estimates, rownames = "term") %>%
dplyr::filter(.data = ., term == "d")

# dataframe with bayes factors
df <- tibble(bf10 = meta_res$BF["random_H1", "random_H0"])
df <-
as_tibble(mod$estimates, rownames = "term") %>%
dplyr::mutate(.data = ., bf10 = mod$BF["random_H1", "random_H0"])

# changing aspects of the caption based on what output is needed
if (output %in% c("null", "caption", "H0", "h0")) {
Expand Down Expand Up @@ -127,16 +121,16 @@ bf_meta <- function(data,
top.text = caption,
bf.sub = bf.sub,
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)
d.pmean = specify_decimal_p(x = df$mean[[1]], k = k),
d.pmean.LB = specify_decimal_p(x = df$hpd95_lower[[1]], k = k),
d.pmean.UB = specify_decimal_p(x = df$hpd95_upper[[1]], k = k)
)
)

# return the text results or the dataframe with results
return(switch(
EXPR = output,
"results" = df,
"dataframe" = df,
bf_message
))
}
4 changes: 2 additions & 2 deletions R/bf_oneway_anova.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ bf_oneway_anova <- function(data,
y,
bf.prior = 0.707,
caption = NULL,
output = "results",
output = "dataframe",
paired = FALSE,
k = 2L,
...) {
Expand Down Expand Up @@ -112,7 +112,7 @@ bf_oneway_anova <- function(data,
# return the text results or the dataframe with results
switch(
EXPR = output,
"results" = bf_extractor(bf_object),
"dataframe" = bf_extractor(bf_object),
bf_expr(bf_object, k = k, output = output, caption = caption, anova.design = TRUE, ...)
)
}
4 changes: 2 additions & 2 deletions R/bf_ttest.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bf_ttest <- function(data,
paired = FALSE,
bf.prior = 0.707,
caption = NULL,
output = "results",
output = "dataframe",
k = 2L,
...) {

Expand Down Expand Up @@ -118,7 +118,7 @@ bf_ttest <- function(data,
# return the text results or the dataframe with results
switch(
EXPR = output,
"results" = bf_extractor(bf_object),
"dataframe" = bf_extractor(bf_object),
bf_expr(bf_object, k = k, output = output, caption = caption, ...)
)
}
2 changes: 1 addition & 1 deletion R/helpers_bf_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ bf_extractor <- function(bf.object, ...) {
#' which will return expression with evidence in favor of the null hypothesis,
#' or `"alternative"` (or `"title"` or `"H1"` or `"h1"`), which will return
#' expression with evidence in favor of the alternative hypothesis, or
#' `"results"`, which will return a dataframe with results all the details).
#' `"dataframe"`, which will return a dataframe with results all the details).
#' @param anova.design Whether the object is from `BayesFactor::anovaBF`
#' (default: `FALSE`). The expression is different for anova designs because
#' not all details are available.
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -229,5 +229,5 @@
"name": "Comprehensive R Archive Network (CRAN)",
"url": "https://cran.r-project.org"
},
"fileSize": "1655.411KB"
"fileSize": "1659.995KB"
}
1 change: 1 addition & 0 deletions docs/news/index.html

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

2 changes: 1 addition & 1 deletion docs/pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pandoc: '2.11'
pkgdown: 1.6.1
pkgdown_sha: ~
articles: {}
last_built: 2020-10-14T08:30Z
last_built: 2020-10-14T21:22Z
urls:
reference: https://indrajeetpatil.github.io/tidyBF//reference
article: https://indrajeetpatil.github.io/tidyBF//articles
Expand Down
2 changes: 1 addition & 1 deletion docs/reference/bf_contingency_tab.html

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

4 changes: 2 additions & 2 deletions docs/reference/bf_corr_test.html

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

2 changes: 1 addition & 1 deletion docs/reference/bf_expr.html

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

19 changes: 9 additions & 10 deletions docs/reference/bf_meta.html

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

4 changes: 2 additions & 2 deletions docs/reference/bf_oneway_anova.html

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

Loading

3 comments on commit 2ba6b75

@lintr-bot
Copy link

Choose a reason for hiding this comment

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

tests/testthat/test-bf_ttest.R:121:7: style: Commented code should be removed.

# set.seed(123)
      ^~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:131:11: style: Commented code should be removed.

#     conf.level = 0.90
          ^~~~~~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:165:7: style: Commented code should be removed.

# set.seed(123)
      ^~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:174:11: style: Commented code should be removed.

#     conf.method = "eti"
          ^~~~~~~~~~~~~~~~~~~

@lintr-bot
Copy link

Choose a reason for hiding this comment

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

tests/testthat/test-bf_ttest.R:121:7: style: Commented code should be removed.

# set.seed(123)
      ^~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:131:11: style: Commented code should be removed.

#     conf.level = 0.90
          ^~~~~~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:165:7: style: Commented code should be removed.

# set.seed(123)
      ^~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:174:11: style: Commented code should be removed.

#     conf.method = "eti"
          ^~~~~~~~~~~~~~~~~~~

@lintr-bot
Copy link

Choose a reason for hiding this comment

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

tests/testthat/test-bf_ttest.R:121:7: style: Commented code should be removed.

# set.seed(123)
      ^~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:131:11: style: Commented code should be removed.

#     conf.level = 0.90
          ^~~~~~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:165:7: style: Commented code should be removed.

# set.seed(123)
      ^~~~~~~~~~~~~

tests/testthat/test-bf_ttest.R:174:11: style: Commented code should be removed.

#     conf.method = "eti"
          ^~~~~~~~~~~~~~~~~~~

Please sign in to comment.