-
-
Notifications
You must be signed in to change notification settings - Fork 343
Add biomedical statistical tests: Wilcoxon and Mann-Whitney U tests #221
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add biomedical statistical tests: Wilcoxon and Mann-Whitney U tests #221
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds two non-parametric statistical test implementations in R with biomedical-focused examples and documentation.
- New Wilcoxon signed-rank test for paired/one-sample scenarios with custom print method
- New Mann-Whitney U (rank-sum) test for independent samples with custom print method and examples
- README explaining use-cases, interpretation, and example usage
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 10 comments.
| File | Description |
|---|---|
| Biomedical/wilcoxon_signed_rank_test.r | Adds Wilcoxon signed-rank test implementation and extensive runnable examples |
| Biomedical/mann_whitney_u_test.r | Adds Mann-Whitney U test implementation, tie-handling attempt, and runnable examples |
| Biomedical/README.md | Adds documentation and quick start usage for the new tests |
- Implement Wilcoxon Signed-Rank Test for paired samples and one-sample tests - Implement Mann-Whitney U Test for independent group comparisons - Include comprehensive biomedical examples with dummy clinical data - Add detailed documentation explaining importance for biomedical students - Cover common use cases: treatment effects, biomarker analysis, clinical trials - Provide robust error handling and statistical interpretations Features: - Blood pressure, pain score, weight loss, and cholesterol analysis examples - Drug efficacy, gender differences, disease staging, and immune response examples - Clinical interpretation guidelines and statistical theory explanations - Ready-to-use functions with medical data applications
- Add new Biomedical section in alphabetical order - Include Mann Whitney U Test for independent group comparisons - Include Wilcoxon Signed Rank Test for paired samples and one-sample tests - Follow repository guidelines for categorizing new algorithms
93305dc to
6678a57
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
Comments suppressed due to low confidence (1)
Biomedical/mann_whitney_u_test.r:1
- Tie correction is applied incorrectly. With T = sum(t_i^3 - t_i) / (N * (N - 1)), the correct variance is var_U <- n1 * n2 * ((N + 1) - T) / 12. The current code divides by (N - 1) again, underestimating the variance and skewing p-values.
# Mann-Whitney U Test (Wilcoxon Rank-Sum Test) for Biomedical Data Analysis
Directory and Code Quality Fixes: - Rename directory from 'Biomedical' to lowercase 'biomedical' per repository conventions - Update DIRECTORY.md links to reflect lowercase directory name Wilcoxon Signed-Rank Test Fixes: - Fix one-sided p-value logic: use W_plus as test statistic for both 'greater' and 'less' - Use correct tail directions: pnorm(z, lower.tail=FALSE) for 'greater', lower.tail=TRUE for 'less' - Add proper NA handling: remove NAs early before computing differences - For paired samples: use complete.cases() to handle missing value pairs - Add tie correction to variance calculation for more accurate p-values - Remove automatic example execution to prevent side effects Mann-Whitney U Test Fixes: - Remove automatic example execution to prevent console output side effects - Add proper documentation for manual example execution Quality Improvements: - Better error handling for edge cases (no complete cases, all missing values) - More accurate statistical calculations with tie corrections - Cleaner code structure following R best practices - Documentation improvements for manual example running
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 7 comments.
Comments suppressed due to low confidence (2)
biomedical/wilcoxon_signed_rank_test.r:117
- Please add tests covering: (1) the small-sample branch that emits a warning and returns NA p-values; (2) tie handling in absolute differences; (3) one-sided vs two-sided alternatives producing expected directionality. These can be validated against base R's wilcox.test for small synthetic datasets.
} else {
# For small samples, exact p-values would require lookup tables
p_value <- NA
warning("Sample size is small (n < 10). P-value calculation requires exact tables.")
}
biomedical/mann_whitney_u_test.r:121
- Add tests that (1) exercise the small-sample and exact branches (ensuring warnings and NA p-values are produced), (2) verify tie-corrected variance by comparing z-based p-values with wilcox.test(exact = FALSE) on datasets with ties, and (3) confirm correct one-sided behavior ('less' and 'greater').
} else {
# For small samples or when exact is requested
if (exact && n1 <= 20 && n2 <= 20) {
# Note: Exact calculation would require generating all possible rank combinations
# This is computationally intensive and typically done using lookup tables
p_value <- NA
method <- "Mann-Whitney U test (exact method - requires lookup tables)"
warning("Exact p-value calculation requires specialized tables. Using NA.")
} else {
p_value <- NA
method <- "Mann-Whitney U test"
warning("Sample sizes are small. Consider using exact tables for p-value calculation.")
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 6 comments.
@siriak I made the changes told by you. Kindly see to it.
🏥 Biomedical Statistical Tests for Non-parametric Analysis
This PR adds essential statistical tests commonly used in biomedical research and clinical studies.
📊 What's Added
Biomedical/wilcoxon_signed_rank_test.r) - For paired samples and one-sample testsBiomedical/mann_whitney_u_test.r) - For independent group comparisonsBiomedical/README.md) - Explaining importance for biomedical students🔬 Features
📋 Examples Include
Wilcoxon Signed-Rank Test:
Mann-Whitney U Test:
🎯 Why This Matters for Biomedical Research
Medical data often violates normal distribution assumptions due to:
These non-parametric tests are essential for:
✅ Testing & Quality
📚 Educational Value