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:
It also generates a publication-ready boxplot with jittered points.
# install.packages("remotes") # if not already installed
::install_github("arka1985/boxTest") remotes
install.packages("boxTest")
Download the .tar.gz
file from Releases and
install locally:
install.packages("path/to/boxTest_0.1.0.tar.gz", repos = NULL, type = "source")
library(boxTest)
# Create a sample dataset: Male and Female BMI
<- data.frame(
df 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
<- compare_two_groups(df, "BMI", "gender")
res
# Show the boxplot
print(res$plot)
# Normality test results
print(res$normality)
# Test summary (t-test or Mann–Whitney U)
print(res$test_summary)
res$plot
→ A ggplot object showing the
boxplot with jittered pointsres$normality
→ Shapiro–Wilk test
results for each groupres$test_summary
→ Test used,
statistic, df (if applicable), and p-value