compare_two_groups: Compare Two Groups with Boxplot and Significance Test
Description
Generates side-by-side boxplots and runs Shapiro-Wilk tests by group
to check for normality. If both groups are normally distributed,
an independent two-sample t-test is applied. Otherwise,
a Mann–Whitney U test (Wilcoxon rank-sum test) is performed.
Returns a structured list with plots and a clear test summary.
Usage
compare_two_groups(data, continuous, group)
Value
A list containing:
plot
A ggplot object of the boxplot with jittered points.
normality
A data.frame showing Shapiro-Wilk test results by group.
test_summary
A data.frame summarizing the statistical test used, statistic, df (if applicable), and p-value.
Arguments
data
A data.frame containing the variables.
continuous
Name of continuous variable (string).
group
Name of categorical variable with exactly 2 levels (string).