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

Commit

Permalink
cran submission
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Mar 18, 2020
1 parent bcf8ec2 commit cfaaef2
Show file tree
Hide file tree
Showing 24 changed files with 312 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# CODEOWNERS for ggstatsplot
# CODEOWNERS for tidyBF
.github/CODEOWNERS @IndrajeetPatil
2 changes: 2 additions & 0 deletions CRAN-RELEASE
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This package was submitted to CRAN on 2020-03-18.
Once it is accepted, delete this file and tag the release (commit bcf8ec20b6).
4 changes: 4 additions & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ Authors@R:
Maintainer: Indrajeet Patil <patilindrajeet.science@gmail.com>
Description: Provides helper functions that make it easy to run
'BayesFactor' package tests on a data which is in a tidy format.
Additionally, it provides a more consistent syntax and by default
returns a dataframe with rich details. These functions can also return
expressions containing results from Bayes Factor tests that can then
be displayed on custom plots.
License: GPL-3 | file LICENSE
URL: https://indrajeetpatil.github.io/tidyBF/,
https://github.com/IndrajeetPatil/tidyBF
Expand Down
16 changes: 2 additions & 14 deletions R/bf_contingency_tab.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,14 +38,12 @@
#' \url{https://gist.github.com/richarddmorey/a4cd3a2051f373db917550d67131dba4}.
#'
#' @examples
#'
#' \donttest{
#' # ------------------ association tests --------------------------------
#'
#' # for reproducibility
#' set.seed(123)
#' library(tidyBF)
#'
#' # ------------------ association tests --------------------------------
#'
#' # to get caption (in favor of null)
#' bf_contingency_tab(
#' data = mtcars,
Expand All @@ -54,15 +52,6 @@
#' fixed.margin = "cols"
#' )
#'
#' # to get caption (in favor of alternative)
#' bf_contingency_tab(
#' data = mtcars,
#' x = am,
#' y = cyl,
#' fixed.margin = "rows",
#' output = "alternative"
#' )
#'
#' # to see results
#' bf_contingency_tab(
#' data = mtcars,
Expand All @@ -80,7 +69,6 @@
#' x = am,
#' prior.concentration = 10
#' )
#' }
#' @export

# function body
Expand Down
2 changes: 0 additions & 2 deletions R/bf_corr_test.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#' \code{\link{bf_ttest}}
#'
#' @examples
#' \donttest{
#' # for reproducibility
#' set.seed(123)
#'
Expand All @@ -38,7 +37,6 @@
#' y = y4,
#' bf.prior = 0.8
#' )
#' }
#' @export

# function body
Expand Down
12 changes: 9 additions & 3 deletions R/helpers_bf_tests.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@
#' @importFrom dplyr rename select mutate
#'
#' @examples
#' # getting only Bayes Factors
#' bf_extractor(
#' set.seed(123)
#'
#' # creating a `BayesFactor` object
#' bf_obj <-
#' BayesFactor::anovaBF(
#' formula = Sepal.Length ~ Species,
#' data = iris,
#' progress = FALSE
#' )
#' )
#'
#' # extracting Bayes Factors in a dataframe
#' # *important*: don't enter `1/bf_obj` to extract results for null hypothesis;
#' # doing so will return wrong results
#' bf_extractor(bf_obj)
#' @export

# function body
Expand Down
64 changes: 57 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ knitr::opts_chunk$set(
)
```

# tidyBF: Grouped statistical analysis in a tidy way
# `tidyBF`: Grouped statistical analysis in a tidy way

[![CRAN_Release_Badge](http://www.r-pkg.org/badges/version-ago/tidyBF)](https://CRAN.R-project.org/package=tidyBF)
[![packageversion](https://img.shields.io/badge/Package%20version-0.1.0.9000-orange.svg?style=flat-square)](https://github.com/IndrajeetPatil/tidyBF/commits/master)
[![Daily downloads badge](https://cranlogs.r-pkg.org/badges/last-day/tidyBF?color=blue)](https://CRAN.R-project.org/package=tidyBF)
[![Weekly downloads badge](https://cranlogs.r-pkg.org/badges/last-week/tidyBF?color=blue)](https://CRAN.R-project.org/package=tidyBF)
Expand All @@ -32,11 +31,15 @@ knitr::opts_chunk$set(
[![minimal R version](https://img.shields.io/badge/R%3E%3D-3.5.0-6666ff.svg)](https://cran.r-project.org/)
[![Coverage Status](https://img.shields.io/codecov/c/github/IndrajeetPatil/tidyBF/master.svg)](https://codecov.io/github/IndrajeetPatil/tidyBF?branch=master)
[![Coverage Status](https://coveralls.io/repos/github/IndrajeetPatil/tidyBF/badge.svg?branch=master)](https://coveralls.io/github/IndrajeetPatil/tidyBF?branch=master)
[![status](https://tinyverse.netlify.com/badge/tidyBF)](https://CRAN.R-project.org/package=tidyBF)

# Overview

`tidyBF` package is a tidy wrapper around `BayesFactor` package.
`tidyBF` package is a tidy wrapper around `BayesFactor` package that always
expects the data to be in the tidy format and return a tibble containing Bayes
Factor values. Additionally, it provides a more consistent syntax and by
default returns a dataframe with rich details. These functions can also return
expressions containing results from Bayes Factor tests that can then be
displayed on custom plots.

# Installation

Expand Down Expand Up @@ -78,10 +81,12 @@ remotes::install_github(
Below are few concrete examples of where `tidyBF` wrapper might provide a more
friendly way to access output from or write functions around `BayesFactor`.

1. `BayesFactor` is inconsistent with its formula interface. `tidyBF` avoids
this as it doesn't provide the formula interface for any of the functions.
## Syntax consistency

```{r r_formula}
`BayesFactor` is inconsistent with its formula interface. `tidyBF` avoids this
as it doesn't provide the formula interface for any of the functions.

```{r formula}
# setup
set.seed(123)
Expand All @@ -105,6 +110,51 @@ bf_ttest(data = mtcars, x = am, y = wt)
bf_ttest(data = sleep, x = group, y = extra, paired = TRUE)
```

## Expressions for plots

Although all functions default to returning a dataframe, you can also use it
to extract expressions that can be displayed in plots.

```{r expr_plot}
# setup
set.seed(123)
library(ggplot2)
# two-sample t-test results in an expression
stats_exp <- bf_ttest(mtcars, am, wt, output = "alternative")
# using the expression to display details in a plot
ggplot(mtcars, aes(as.factor(am), wt)) +
geom_boxplot() +
labs(subtitle = stats_exp)
```

## Dataframe with all the details

`BayesFactor` can return the Bayes Factor value corresponding to either
evidence in favor of the null hypothesis over the alternative hypothesis
(`BF01`) or in favor of the alternative over the null (`BF10`), depending on how this
object is called. `tidyBF` on the other hand return both of these values and
their logarithms.

```{r all_together}
# `BayesFactor` object
bf <- BayesFactor::correlationBF(y = iris$Sepal.Length, x = iris$Petal.Length)
# alternative
bf
# null
1 / bf
# `tidyBF` output
bf_corr_test(iris, Sepal.Length, Petal.Length, bf.prior = 0.333)
```

Note that the log-transformed values are helpful because in case of strong
effects, the raw Bayes Factor values can be pretty large, but the
log-transformed values continue to remain easy to work with.

# Code of Conduct

Please note that the `tidyBF` project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
Expand Down
87 changes: 79 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@

<!-- README.md is generated from README.Rmd. Please edit that file -->

# tidyBF: Grouped statistical analysis in a tidy way
# `tidyBF`: Grouped statistical analysis in a tidy way

[![CRAN\_Release\_Badge](http://www.r-pkg.org/badges/version-ago/tidyBF)](https://CRAN.R-project.org/package=tidyBF)
[![packageversion](https://img.shields.io/badge/Package%20version-0.1.0.9000-orange.svg?style=flat-square)](https://github.com/IndrajeetPatil/tidyBF/commits/master)
[![Daily downloads
badge](https://cranlogs.r-pkg.org/badges/last-day/tidyBF?color=blue)](https://CRAN.R-project.org/package=tidyBF)
Expand All @@ -22,18 +21,22 @@ Status](https://ci.appveyor.com/api/projects/status/github/IndrajeetPatil/tidyBF
[![Project Status: Active - The project has reached a stable, usable
state and is being actively
developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active)
[![Last-changedate](https://img.shields.io/badge/last%20change-2020--03--17-yellowgreen.svg)](https://github.com/IndrajeetPatil/tidyBF/commits/master)
[![Last-changedate](https://img.shields.io/badge/last%20change-2020--03--18-yellowgreen.svg)](https://github.com/IndrajeetPatil/tidyBF/commits/master)
[![minimal R
version](https://img.shields.io/badge/R%3E%3D-3.5.0-6666ff.svg)](https://cran.r-project.org/)
[![Coverage
Status](https://img.shields.io/codecov/c/github/IndrajeetPatil/tidyBF/master.svg)](https://codecov.io/github/IndrajeetPatil/tidyBF?branch=master)
[![Coverage
Status](https://coveralls.io/repos/github/IndrajeetPatil/tidyBF/badge.svg?branch=master)](https://coveralls.io/github/IndrajeetPatil/tidyBF?branch=master)
[![status](https://tinyverse.netlify.com/badge/tidyBF)](https://CRAN.R-project.org/package=tidyBF)

# Overview

`tidyBF` package is a tidy wrapper around `BayesFactor` package.
`tidyBF` package is a tidy wrapper around `BayesFactor` package that
always expects the data to be in the tidy format and return a tibble
containing Bayes Factor values. Additionally, it provides a more
consistent syntax and by default returns a dataframe with rich details.
These functions can also return expressions containing results from
Bayes Factor tests that can then be displayed on custom plots.

# Installation

Expand Down Expand Up @@ -76,10 +79,11 @@ Below are few concrete examples of where `tidyBF` wrapper might provide
a more friendly way to access output from or write functions around
`BayesFactor`.

1. `BayesFactor` is inconsistent with its formula interface. `tidyBF`
avoids this.
## Syntax consistency

<!-- end list -->
`BayesFactor` is inconsistent with its formula interface. `tidyBF`
avoids this as it doesn’t provide the formula interface for any of the
functions.

``` r
# setup
Expand Down Expand Up @@ -125,6 +129,73 @@ bf_ttest(data = sleep, x = group, y = extra, paired = TRUE)
#> 1 17.3 1.68e-7 0.0579 2.85 -2.85 1.24 -1.24 0.707
```

## Expressions for plots

Although all functions default to returning a dataframe, you can also
use it to extract expressions that can be displayed in plots.

``` r
# setup
set.seed(123)
library(ggplot2)

# two-sample t-test results in an expression
stats_exp <- bf_ttest(mtcars, am, wt, output = "alternative")

# using the expression to display details in a plot
ggplot(mtcars, aes(as.factor(am), wt)) +
geom_boxplot() +
labs(subtitle = stats_exp)
```

<img src="man/figures/README-expr_plot-1.png" width="100%" />

## Dataframe with all the details

`BayesFactor` can return the Bayes Factor value corresponding to either
evidence in favor of the null hypothesis over the alternative hypothesis
(`BF01`) or in favor of the alternative over the null (`BF10`),
depending on how this object is called. `tidyBF` on the other hand
return both of these values and their logarithms.

``` r
# `BayesFactor` object
bf <- BayesFactor::correlationBF(y = iris$Sepal.Length, x = iris$Petal.Length)

# alternative
bf
#> Bayes factor analysis
#> --------------
#> [1] Alt., r=0.333 : 2.136483e+43 ±0%
#>
#> Against denominator:
#> Null, rho = 0
#> ---
#> Bayes factor type: BFcorrelation, Jeffreys-beta*

# null
1 / bf
#> Bayes factor analysis
#> --------------
#> [1] Null, rho = 0 : 4.680589e-44 ±0%
#>
#> Against denominator:
#> Alternative, r = 0.333333333333333, rho =/= 0
#> ---
#> Bayes factor type: BFcorrelation, Jeffreys-beta*

# `tidyBF` output
bf_corr_test(iris, Sepal.Length, Petal.Length, bf.prior = 0.333)
#> # A tibble: 1 x 8
#> bf10 error bf01 log_e_bf10 log_e_bf01 log_10_bf10 log_10_bf01 bf.prior
#> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
#> 1 2.13e43 0 4.70e-44 99.8 -99.8 43.3 -43.3 0.333
```

Note that the log-transformed values are helpful because in case of
strong effects, the raw Bayes Factor values can be pretty large, but the
log-transformed values continue to remain easy to work with.

# Code of Conduct

Please note that the `tidyBF` project is released with a [Contributor
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
],
"@type": "SoftwareSourceCode",
"identifier": "tidyBF",
"description": "Provides helper functions that make it easy to run\n 'BayesFactor' package tests on a data which is in a tidy format.",
"description": "Provides helper functions that make it easy to run\n 'BayesFactor' package tests on a data which is in a tidy format.\n Additionally, it provides a more consistent syntax and by default\n returns a dataframe with rich details. These functions can also return\n expressions containing results from Bayes Factor tests that can then\n be displayed on custom plots.",
"name": "tidyBF: Tidy Wrapper for 'BayesFactor' Package",
"codeRepository": "https://github.com/IndrajeetPatil/tidyBF",
"relatedLink": "https://indrajeetpatil.github.io/tidyBF/",
Expand Down
3 changes: 2 additions & 1 deletion cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@
0 errors | 0 warnings | 1 note

- This is a new release.
- I prefer to keep `LICENSE` file at the top level because this makes it easy

- I prefer to keep the `LICENSE` file at the top level because this makes it easy
to read it on GitHub as well.
Loading

0 comments on commit cfaaef2

Please sign in to comment.