Skip to content
This repository has been archived by the owner on Mar 24, 2022. It is now read-only.

Commit

Permalink
Merge 4f4327c into c990501
Browse files Browse the repository at this point in the history
  • Loading branch information
IndrajeetPatil committed Sep 4, 2020
2 parents c990501 + 4f4327c commit 415ee12
Show file tree
Hide file tree
Showing 49 changed files with 1,548 additions and 5,300 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -37,7 +37,6 @@ r_packages:
- LaplacesDemon
- logspline
- testthat
- devtools
- remotes
- knitr
- rmarkdown
Expand Down
6 changes: 3 additions & 3 deletions API
Expand Up @@ -9,10 +9,10 @@ pairwise_p(data, x, y, type = "parametric", paired = FALSE, var.equal = FALSE, t

## Reexported objects

::%$%
magrittr::%$%
zeallot::%<-%
::%<>%
::%>%
magrittr::%<>%
magrittr::%>%
rlang::%|%
rlang::%||%
rlang:::=
Expand Down
4 changes: 2 additions & 2 deletions CRAN-RELEASE
@@ -1,2 +1,2 @@
This package was submitted to CRAN on 2020-06-23.
Once it is accepted, delete this file and tag the release (commit b0b6801fdc).
This package was submitted to CRAN on 2020-09-04.
Once it is accepted, delete this file and tag the release (commit 8ab15c7).
2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,7 +1,7 @@
Type: Package
Package: pairwiseComparisons
Title: Multiple Pairwise Comparison Tests
Version: 1.1.2.9000
Version: 2.0.0
Authors@R:
person(given = "Indrajeet",
family = "Patil",
Expand Down
10 changes: 9 additions & 1 deletion NEWS.md
@@ -1,4 +1,12 @@
# pairwiseComparisons 1.1.2.9000
# pairwiseComparisons 2.0.0

- Fixes a bug which affected results for within-subjects design when the
dataframe wasn't sorted by `x` (#19).

- This fix also now makes the results more consistent, such that irrespective
of which type of statistics is chosen the `group1` and `group2` columns are
in identical order.


# pairwiseComparisons 1.1.2

Expand Down
18 changes: 5 additions & 13 deletions R/data.R
Expand Up @@ -2,13 +2,9 @@
#' @name movies_wide
#' @details Modified dataset from `ggplot2movies` package.
#'
#' The internet movie database, \url{http://imdb.com/}, is a website devoted
#' to collecting movie data supplied by studios and fans. It claims to be the
#' biggest movie database on the web and is run by amazon. More information
#' about imdb.com can be found online,
#' \url{http://imdb.com/help/show_leaf?about}, including information about
#' the data collection process,
#' \url{http://imdb.com/help/show_leaf?infosource}.
#' The internet movie database, \url{https://imdb.com/}, is a website devoted
#' to collecting movie data supplied by studios and fans. It claims to be the
#' biggest movie database on the web and is run by amazon.
#'
#' Movies were selected for inclusion if they had a known length and had been
#' rated by at least one imdb user. Small categories such as documentaries
Expand Down Expand Up @@ -41,13 +37,9 @@
#' @name movies_long
#' @details Modified dataset from `ggplot2movies` package.
#'
#' The internet movie database, \url{http://imdb.com/}, is a website devoted
#' The internet movie database, \url{https://imdb.com/}, is a website devoted
#' to collecting movie data supplied by studios and fans. It claims to be the
#' biggest movie database on the web and is run by amazon. More about
#' information imdb.com can be found online,
#' \url{http://imdb.com/help/show_leaf?about}, including information about
#' the data collection process,
#' \url{http://imdb.com/help/show_leaf?infosource}.
#' biggest movie database on the web and is run by amazon.
#'
#' Movies were are identical to those selected for inclusion in movies_wide but this
#' dataset has been constructed such that every movie appears in one and only one
Expand Down
36 changes: 14 additions & 22 deletions R/games_howell.R
Expand Up @@ -78,39 +78,32 @@ games_howell <- function(data, x, y) {
)

# sigma standard error
se <-
sqrt(x = 0.5 * (std[combs[1, x]] / n[combs[1, x]] + std[combs[2, x]] / n[combs[2, x]]))
se <- sqrt(x = 0.5 * (std[combs[1, x]] / n[combs[1, x]] + std[combs[2, x]] / n[combs[2, x]]))

# upper confidence limit for mean difference
conf.high <- lapply(X = 1:NCOL(combs), FUN = function(x) {
mean.diff + stats::qtukey(
p = 0.95,
nmeans = groups,
df = df
) * se
})[[1]]
conf.high <-
lapply(
X = 1:NCOL(combs),
FUN = function(x) mean.diff + stats::qtukey(p = 0.95, nmeans = groups, df = df) * se
)

# lower confidence limit for mean difference
conf.low <- lapply(X = 1:NCOL(combs), FUN = function(x) {
mean.diff - stats::qtukey(
p = 0.95,
nmeans = groups,
df = df
) * se
})[[1]]
conf.low <-
lapply(
X = 1:NCOL(combs),
FUN = function(x) mean.diff - stats::qtukey(p = 0.95, nmeans = groups, df = df) * se
)

# Group Combinations
group1 <- as.character(combs[1, x])
group2 <- as.character(combs[2, x])

# Collect all statistics into list
stats <- list(group1, group2, mean.diff, se, t, df, p, conf.high, conf.low)
stats <- list(group1, group2, mean.diff, se, t, df, p, conf.high[[1]], conf.low[[1]])
})

# unlist statistics collected earlier
stats.unlisted <- lapply(statistics, function(x) {
unlist(x)
})
stats.unlisted <- lapply(statistics, function(x) unlist(x))

# create dataframe from flattened list
results <-
Expand All @@ -121,8 +114,7 @@ games_howell <- function(data, x, y) {
))

# select columns that should be numeric and change with as.numeric
results[, 3:ncol(results)] <-
round(as.numeric(as.matrix(results[, 3:ncol(results)])), digits = 3)
results[, 3:ncol(results)] <- round(as.numeric(as.matrix(results[, 3:ncol(results)])), digits = 3)

# Rename data frame columns
colnames(results) <-
Expand Down
64 changes: 29 additions & 35 deletions R/pairwise_comparisons.R
Expand Up @@ -3,8 +3,8 @@
#' @description Calculate parametric, non-parametric, and robust pairwise
#' comparisons between group levels with corrections for multiple testing.
#'
#' @param data A dataframe (or a tibble) from which variables specified are to
#' be taken. A matrix or tables will **not** be accepted.
#' @param data A dataframe from which variables specified are to be taken. A
#' matrix or tables will **not** be accepted.
#' @param x The grouping variable from the dataframe `data`.
#' @param y The response (a.k.a. outcome or dependent) variable from the
#' dataframe `data`.
Expand Down Expand Up @@ -187,16 +187,20 @@ pairwise_comparisons <- function(data,

# ---------------------------- data cleanup -------------------------------

# creating a dataframe
# creating a dataframe (it's important for the data to be sorted by `x`)
df_internal <-
long_to_wide_converter(
data = data,
data = dplyr::arrange(data, {{ x }}),
x = {{ x }},
y = {{ y }},
paired = paired,
spread = FALSE
)

# for some tests, it's better to have these as vectors
x_vec <- df_internal %>% dplyr::pull({{ x }})
y_vec <- df_internal %>% dplyr::pull({{ y }})

# ---------------------------- parametric ---------------------------------

if (type %in% c("parametric", "bayes")) {
Expand Down Expand Up @@ -253,16 +257,15 @@ pairwise_comparisons <- function(data,

# tidy dataframe with results from pairwise tests
df_tidy <-
broomExtra::tidy(
stats::pairwise.t.test(
x = df_internal %>% dplyr::pull({{ y }}),
g = df_internal %>% dplyr::pull({{ x }}),
p.adjust.method = "none",
paired = paired,
alternative = "two.sided",
na.action = na.omit
)
stats::pairwise.t.test(
x = y_vec,
g = x_vec,
p.adjust.method = "none",
paired = paired,
alternative = "two.sided",
na.action = na.omit
) %>%
broomExtra::tidy(.) %>%
p_adjust_column_adder(df = ., p.adjust.method = p.adjust.method)

# combining mean difference and results from pairwise t-test
Expand Down Expand Up @@ -310,23 +313,20 @@ pairwise_comparisons <- function(data,
)
) %>%
dplyr::rowwise() %>%
dplyr::mutate(label = paste(
"list(~log[e](BF[10])",
"==",
specify_decimal_p(x = log_e_bf10, k = k),
")",
sep = ""
dplyr::mutate(label = paste0(
"list(~log[e](BF[10])", "==", specify_decimal_p(x = log_e_bf10, k = k), ")"
)) %>%
dplyr::ungroup() %>%
dplyr::mutate(.data = ., test.details = "Student's t-test")

# early return (no further cleanup required)
return(dplyr::bind_cols(dplyr::select(df, group1, group2), df_tidy) %>%
return(
dplyr::mutate_if(
.tbl = .,
.tbl = dplyr::bind_cols(dplyr::select(df, group1, group2), df_tidy),
.predicate = is.factor,
.funs = ~ as.character(.)
))
)
)
}

# ---------------------------- nonparametric ----------------------------
Expand All @@ -337,8 +337,8 @@ pairwise_comparisons <- function(data,
invisible(utils::capture.output(df <-
as.data.frame(
dunn.test::dunn.test(
x = df_internal %>% dplyr::pull({{ y }}),
g = df_internal %>% dplyr::pull({{ x }}),
x = y_vec,
g = x_vec,
table = FALSE,
kw = FALSE,
label = FALSE,
Expand Down Expand Up @@ -375,29 +375,23 @@ pairwise_comparisons <- function(data,

# converting the entered long format data to wide format
if (isTRUE(paired)) {
x_vec <- df_internal %>% dplyr::pull({{ x }})
y_vec <- df_internal %>% dplyr::pull({{ y }})

# creating model object
mod <-
PMCMRplus::durbinAllPairsTest(
y = na.omit(matrix(
data = y_vec,
ncol = length(unique(x_vec)),
dimnames = list(
seq(1, length(y_vec) / length(unique(x_vec))),
unique(x_vec)
)
dimnames = list(seq(1, length(y_vec) / length(unique(x_vec))), unique(x_vec))
)),
p.adjust.method = "none"
)

# combining into one dataframe
df <-
dplyr::bind_cols(
matrix_to_tidy(m = mod$statistic, col_names = c("group1", "group2", "W")),
matrix_to_tidy(m = mod$statistic, col_names = c("group2", "group1", "W")),
dplyr::select(
matrix_to_tidy(m = mod$p.value, col_names = c("group1", "group2", "p.value")),
matrix_to_tidy(m = mod$p.value, col_names = c("group2", "group1", "p.value")),
-dplyr::contains("group")
)
)
Expand Down Expand Up @@ -485,8 +479,8 @@ pairwise_comparisons <- function(data,
dplyr::mutate(label = specify_decimal_p(x = p.value, k = k, p.value = TRUE)) %>%
dplyr::mutate(
label = dplyr::case_when(
label == "< 0.001" ~ paste("list(~italic(p)[", adjust_text, "]<=", "0.001", ")", sep = " "),
TRUE ~ paste("list(~italic(p)[", adjust_text, "]==", label, ")", sep = " ")
label == "< 0.001" ~ paste0("list(~italic(p)[", adjust_text, "]<=", "0.001", ")"),
TRUE ~ paste0("list(~italic(p)[", adjust_text, "]==", label, ")")
)
) %>%
dplyr::mutate(
Expand Down
14 changes: 7 additions & 7 deletions README.Rmd
Expand Up @@ -6,7 +6,7 @@ output: github_document

```{r, echo = FALSE}
# show me all columns
options(tibble.width = Inf)
options(tibble.width = Inf, pillar.bold = TRUE)
knitr::opts_chunk$set(
collapse = TRUE,
Expand All @@ -23,12 +23,12 @@ knitr::opts_chunk$set(

Package | Status | Usage | GitHub | References
----------------- | ----------------- | ----------------- | ----------------- | -----------------
[![CRAN_Release_Badge](http://www.r-pkg.org/badges/version-ago/pairwiseComparisons)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![Travis Build Status](https://travis-ci.org/IndrajeetPatil/pairwiseComparisons.svg?branch=master)](https://travis-ci.org/IndrajeetPatil/pairwiseComparisons) | [![Daily downloads badge](https://cranlogs.r-pkg.org/badges/last-day/pairwiseComparisons?color=blue)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![GitHub version](https://img.shields.io/badge/GitHub-1.1.1-orange.svg?style=flat-square)](https://github.com/IndrajeetPatil/pairwiseComparisons/) | [![Website](https://img.shields.io/badge/website-pairwiseComparisons-orange.svg?colorB=E91E63)](https://indrajeetpatil.github.io/pairwiseComparisons/)
[![CRAN_Release_Badge](http://www.r-pkg.org/badges/version-ago/pairwiseComparisons)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![Travis Build Status](https://travis-ci.org/IndrajeetPatil/pairwiseComparisons.svg?branch=master)](https://travis-ci.org/IndrajeetPatil/pairwiseComparisons) | [![Daily downloads badge](https://cranlogs.r-pkg.org/badges/last-day/pairwiseComparisons?color=blue)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![GitHub version](https://img.shields.io/badge/GitHub-2.0.0-orange.svg?style=flat-square)](https://github.com/IndrajeetPatil/pairwiseComparisons/) | [![Website](https://img.shields.io/badge/website-pairwiseComparisons-orange.svg?colorB=E91E63)](https://indrajeetpatil.github.io/pairwiseComparisons/)
[![CRAN Checks](https://cranchecks.info/badges/summary/pairwiseComparisons)](https://cran.r-project.org/web/checks/check_results_pairwiseComparisons.html) | [![AppVeyor Build Status](https://ci.appveyor.com/api/projects/status/github/IndrajeetPatil/pairwiseComparisons?branch=master&svg=true)](https://ci.appveyor.com/project/IndrajeetPatil/pairwiseComparisons) | [![Weekly downloads badge](https://cranlogs.r-pkg.org/badges/last-week/pairwiseComparisons?color=blue)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![Forks](https://img.shields.io/badge/forks-`r itdepends:::get_github_info("pairwiseComparisons")$forks[[1]]`-blue.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons/) | [![Rdoc](https://www.rdocumentation.org/badges/version/pairwiseComparisons)](https://www.rdocumentation.org/packages/pairwiseComparisons)
[![minimal R version](https://img.shields.io/badge/R%3E%3D-3.6.0-6666ff.svg)](https://cran.r-project.org/) | [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/) | [![Monthly downloads badge](https://cranlogs.r-pkg.org/badges/last-month/pairwiseComparisons?color=blue)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![Github Issues](https://img.shields.io/badge/issues-`r itdepends:::get_github_info("pairwiseComparisons")$open_issues[[1]]`-red.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons/issues) | [![vignettes](https://img.shields.io/badge/vignettes-1.0.0-orange.svg?colorB=FF5722)](https://github.com/IndrajeetPatil/pairwiseComparisons/blob/master/README.md)
[![minimal R version](https://img.shields.io/badge/R%3E%3D-3.6.0-6666ff.svg)](https://cran.r-project.org/) | [![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/) | [![Monthly downloads badge](https://cranlogs.r-pkg.org/badges/last-month/pairwiseComparisons?color=blue)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![Github Issues](https://img.shields.io/badge/issues-`r itdepends:::get_github_info("pairwiseComparisons")$open_issues[[1]]`-red.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons/issues) | [![vignettes](https://img.shields.io/badge/vignettes-2.0.0-orange.svg?colorB=FF5722)](https://github.com/IndrajeetPatil/pairwiseComparisons/blob/master/README.md)
[![GitHub code size in bytes](https://img.shields.io/github/languages/code-size/IndrajeetPatil/pairwiseComparisons.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons) | [![Coverage Status](https://coveralls.io/repos/github/IndrajeetPatil/pairwiseComparisons/badge.svg?branch=master)](https://coveralls.io/github/IndrajeetPatil/pairwiseComparisons?branch=master) | [![Total downloads badge](https://cranlogs.r-pkg.org/badges/grand-total/pairwiseComparisons?color=blue)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![Github Stars](https://img.shields.io/github/stars/IndrajeetPatil/pairwiseComparisons.svg?style=social&label=Github)](https://github.com/IndrajeetPatil/pairwiseComparisons) | [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.2074621.svg)](https://doi.org/10.5281/zenodo.2074621)
[![Licence](https://img.shields.io/badge/licence-GPL--3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0.en.html) | [![Codecov test coverage](https://codecov.io/gh/IndrajeetPatil/pairwiseComparisons/branch/master/graph/badge.svg)](https://codecov.io/gh/IndrajeetPatil/pairwiseComparisons?branch=master) | [![Covrpage Summary](https://img.shields.io/badge/covrpage-Last_Build_2020_05_29-brightgreen.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons/blob/master/tests/README.md) | [![Last-changedate](https://img.shields.io/badge/last%20change-`r gsub('-', '--', Sys.Date())`-yellowgreen.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons/commits/master) | [![GitHub last commit](https://img.shields.io/github/last-commit/IndrajeetPatil/pairwiseComparisons.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons/commits/master)
[![status](https://tinyverse.netlify.com/badge/pairwiseComparisons)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![R build status](https://github.com/IndrajeetPatil/pairwiseComparisons/workflows/R-CMD-check/badge.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons) | [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/pairwiseComparisons/community) | [![Project Status](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/IndrajeetPatil/pairwiseComparisons/issues)
[![status](https://tinyverse.netlify.com/badge/pairwiseComparisons)](https://CRAN.R-project.org/package=pairwiseComparisons) | [![R build status](https://github.com/IndrajeetPatil/pairwiseComparisons/workflows/R-CMD-check/badge.svg)](https://github.com/IndrajeetPatil/pairwiseComparisons) | [![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/pairwiseComparisons/community) | [![Project Status](http://www.repostatus.org/badges/latest/active.svg)](https://www.repostatus.org/#active) | [![contributions welcome](https://img.shields.io/badge/contributions-welcome-brightgreen.svg?style=flat)](https://github.com/IndrajeetPatil/pairwiseComparisons/issues)

# Introduction <img src="man/figures/logo.png" align="right" width="240" />

Expand Down Expand Up @@ -233,7 +233,8 @@ library(ggsignif)
mtcars$cyl <- as.factor(mtcars$cyl)
# creating a basic plot
p <- ggplot(mtcars, aes(cyl, wt)) + geom_boxplot()
p <- ggplot(mtcars, aes(cyl, wt)) +
geom_boxplot()
# using `pairwiseComparisons` package to create a dataframe with results
(df <-
Expand Down Expand Up @@ -308,8 +309,7 @@ of commitment):

- Review code

- Add new functionality (in the form of new plotting functions or helpers for
preparing subtitles)
- Add new functionality

Please note that this project is released with a
[Contributor Code of Conduct](https://github.com/IndrajeetPatil/pairwiseComparisons/blob/master/.github/CODE_OF_CONDUCT.md). By participating in this project you agree to abide by its terms.

0 comments on commit 415ee12

Please sign in to comment.