Boxplot and Significance Test for Two Groups

Provides functions to create side-by-side boxplots for a continuous variable grouped by a two-level categorical variable, check normality assumptions using the Shapiro-Wilk test (Shapiro and Wilk (1965) ), and perform appropriate statistical tests such as the independent two-sample t-test (Student (1908) ) or the Mann–Whitney U test ( Mann–Whitney (1947) ). Returns a publication-ready plot and test statistics including test statistic, degrees of freedom, and p-value.


boxTest

The boxTest package provides a simple way to compare two groups using boxplots and statistical tests. It automatically checks normality (via Shapiro–Wilk test) and then applies the appropriate test:

  • Independent 2-sample t-test (if both groups are normally distributed)
  • Mann–Whitney U test (if at least one group is non-normal)

It also generates a publication-ready boxplot with jittered points.


Installation

From GitHub (development version)

# install.packages("remotes")  # if not already installed
remotes::install_github("arka1985/boxTest")

From CRAN (once accepted)

install.packages("boxTest")

From tar.gz release

Download the .tar.gz file from Releases and install locally:

install.packages("path/to/boxTest_0.1.0.tar.gz", repos = NULL, type = "source")

Example

library(boxTest)

# Create a sample dataset: Male and Female BMI
df <- data.frame(
  gender = rep(c("Male", "Female"), each = 10),
  BMI = c(22, 24, 25, 23, 26, 28, 24, 23, 27, 25,
          21, 22, 23, 20, 24, 22, 21, 23, 22, 21)
)

# Compare BMI between Male and Female
res <- compare_two_groups(df, "BMI", "gender")

# Show the boxplot
print(res$plot)

# Normality test results
print(res$normality)

# Test summary (t-test or Mann–Whitney U)
print(res$test_summary)

Output

  • res$plot → A ggplot object showing the boxplot with jittered points
  • res$normality → Shapiro–Wilk test results for each group
  • res$test_summary → Test used, statistic, df (if applicable), and p-value

Authors

  • Arkaprabha Sau (Author & Maintainer)
  • Santanu Phadikar (Author)
  • Ishita Bhakta (Author)

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("boxTest")

0.1.0 by Arkaprabha Sau, a year ago


Browse source code at https://github.com/cran/boxTest


Authors: Arkaprabha Sau [aut, cre] , Santanu Phadikar [aut] , Ishita Bhakta [aut]


Documentation:   PDF Manual  


MIT + file LICENSE license


Imports ggplot2, dplyr, stats, rlang

Suggests testthat, knitr, rmarkdown


See at CRAN