{"id":29649400,"url":"https://github.com/jabulente/kruskall-wallis-test","last_synced_at":"2025-07-22T04:06:53.289Z","repository":{"id":304963268,"uuid":"1020720752","full_name":"Jabulente/Kruskall-Wallis-Test","owner":"Jabulente","description":"This repository contain project  that provides a reusable Python function to perform the Kruskal-Wallis H-test across multiple continuous variables, grouped by a categorical feature","archived":false,"fork":false,"pushed_at":"2025-07-16T13:08:14.000Z","size":37,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-17T13:32:08.757Z","etag":null,"topics":["data-analysis","data-science","eda","hypothesis-tests","kruskal-wallis","kruskals-algorithm","scipy-stats","statistics"],"latest_commit_sha":null,"homepage":"","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Jabulente.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-16T09:42:44.000Z","updated_at":"2025-07-16T13:08:17.000Z","dependencies_parsed_at":"2025-07-17T17:05:44.074Z","dependency_job_id":"4b1c1491-dad7-4f14-9265-831775166391","html_url":"https://github.com/Jabulente/Kruskall-Wallis-Test","commit_stats":null,"previous_names":["jabulente/kruskall-wallis-test"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/Jabulente/Kruskall-Wallis-Test","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jabulente%2FKruskall-Wallis-Test","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jabulente%2FKruskall-Wallis-Test/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jabulente%2FKruskall-Wallis-Test/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jabulente%2FKruskall-Wallis-Test/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Jabulente","download_url":"https://codeload.github.com/Jabulente/Kruskall-Wallis-Test/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Jabulente%2FKruskall-Wallis-Test/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266424196,"owners_count":23926129,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data-analysis","data-science","eda","hypothesis-tests","kruskal-wallis","kruskals-algorithm","scipy-stats","statistics"],"created_at":"2025-07-22T04:06:50.147Z","updated_at":"2025-07-22T04:06:53.269Z","avatar_url":"https://github.com/Jabulente.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ch1 align='center'\u003e Kruskal-Wallis Test for Multiple Variables and Group Comparisons\u003c/h1\u003e\n\nThis project provides a reusable Python function to perform the **Kruskal-Wallis H-test** across **multiple continuous variables**, grouped by a categorical feature. It returns a **clean summary DataFrame** with test statistics, p-values, and significance indicators, making it easy to evaluate whether medians differ significantly between groups for each variable.\n\n## 1. Purpose\n\nThe Kruskal-Wallis test is a **non-parametric alternative to one-way ANOVA**. It is used when:\n- You have **3 or more independent groups**\n- Your data **violates ANOVA assumptions** (e.g., normality, homogeneity of variance)\n- Your data is **ordinal or continuous but not normally distributed**\n\nThis script simplifies applying this test across **many variables at once**, saving time and boosting productivity in exploratory and inferential analysis.\n\n## 2. Features\n\n- Accepts a pandas DataFrame and a grouping column\n- Automatically applies the Kruskal-Wallis test to all other numeric variables\n- Outputs a summary table including:\n  - Variable name\n  - Kruskal-Wallis test statistic\n  - p-value\n  - Significance status (`p \u003c 0.05`)\n- Ready for integration in statistical reports or dashboards\n\n##  3. How to Use\n\n```python\nfrom scipy.stats import kruskal\nimport pandas as pd\nimport numpy as np\n\ndef kruskall_wallis(df, group_columns: str, numerical_columns: list = None):\n    if numerical_columns is None:\n        numerical_columns = df.select_dtypes(include=[np.number]).columns.tolist()\n        for g in group_columns:\n            if g in numerical_columns:\n                numerical_columns.remove(g)\n    results = []\n    for group_column in group_columns:\n        for column in numerical_columns:\n            # Create a list of samples grouped by group_column\n            groups = [group[column].dropna().values for name, group in df.groupby(group_column)]\n            stats, p_value = kruskal(*groups)\n            interpretation = '✔' if p_value \u003c 0.05 else '✖'\n            results.append({\n                'Group': group_column,\n                'Variables': column,\n                'Kruskal-Wallis Statistic': stats,\n                'P-value': p_value,\n                'Significant (α\u003c0.05)': interpretation\n            })\n    return pd.DataFrame(results)\n\n```\n\n## 4. 📂 Example Dataset\n```\ndf = pd.DataFrame({\n    'Group 1': ['Ashura', 'Ashura', 'Ashura', 'Barack', 'Barack', 'Barack', 'Colins', 'Colins', 'Colins'],\n    'Group 2': ['Orenge', 'Orenge', 'Orenge', 'Banana', 'Banana', 'Banana', 'Carott', 'Carott', 'Carott'],\n    'Group 3': ['Alpha', 'Alpha', 'Alpha', 'Bravo', 'Bravo', 'Bravo', 'Eagle', 'Eagle', 'Eagle'],\n    'Variable 1': [12, 14, 13, 15, 16, 14, 10, 9, 11],\n    'Variable 2': [7, 6, 7, 8, 9, 10, 5, 6, 5],\n    'Variable 3': [20, 21, 19, 23, 22, 21, 18, 17, 19],\n    'Variable 4': [124, 145, 137, 150, 163, 148, 180, 90, 111],\n    'Variable 5': [70, 66, 75, 80, 92, 100, 56, 64, 56],\n    'Variable 6': [2, 2, 1, 2, 2, 2, 1, 1, 1]\n})\n\n\ngroups_column = ['Group 1', 'Group 2', 'Group 3']\nresults = kruskal_test_all_variables(df, 'Group')\nprint(results)\n```\n\n\n##  5. Sample Output\n\nVariable\tKruskal-Wallis Statistic\tp-value\tSignificant (p\u003c0.05)\n\n|    | Group   | Variables   |   Kruskal-Wallis Statistic |   P-value | Significant (α\u003c0.05)   |\n|---:|:--------|:------------|---------------------------:|----------:|:-----------------------|\n|  0 | Group 1 | Variable 1  |                      6.88  |     0.032 | ✔                      |\n|  1 | Group 1 | Variable 2  |                      6.997 |     0.03  | ✔                      |\n|  2 | Group 1 | Variable 3  |                      6.531 |     0.038 | ✔                      |\n|  3 | Group 1 | Variable 4  |                      2.4   |     0.301 | ✖                      |\n|  4 | Group 1 | Variable 5  |                      7.261 |     0.027 | ✔                      |\n|  5 | Group 1 | Variable 6  |                      5.6   |     0.061 | ✖                      |\n|  6 | Group 2 | Variable 1  |                      6.88  |     0.032 | ✔                      |\n|  7 | Group 2 | Variable 2  |                      6.997 |     0.03  | ✔                      |\n|  8 | Group 2 | Variable 3  |                      6.531 |     0.038 | ✔                      |\n|  9 | Group 2 | Variable 4  |                      2.4   |     0.301 | ✖                      |\n| 10 | Group 2 | Variable 5  |                      7.261 |     0.027 | ✔                      |\n| 11 | Group 2 | Variable 6  |                      5.6   |     0.061 | ✖                      |\n| 12 | Group 3 | Variable 1  |                      6.88  |     0.032 | ✔                      |\n| 13 | Group 3 | Variable 2  |                      6.997 |     0.03  | ✔                      |\n| 14 | Group 3 | Variable 3  |                      6.531 |     0.038 | ✔                      |\n| 15 | Group 3 | Variable 4  |                      2.4   |     0.301 | ✖                      |\n| 16 | Group 3 | Variable 5  |                      7.261 |     0.027 | ✔                      |\n| 17 | Group 3 | Variable 6  |                      5.6   |     0.061 | ✖                      |\n\n# 6. 📈 Applications\n\n- Agricultural and biological experiments\n- Social science and behavioral research\n- Market and product group analysis\n- Education and clinical trial comparisons\n\n## 7. 📥 Requirements\n\n- Python 3.x\n- pandas\n- scipy\n\n```\npip install pandas scipy\n```\n\n\n## 8. 🤝 Contributing\n\nFeel free to fork this repo, contribute improvements, or suggest additional features such as post-hoc Dunn tests, visualization tools, or effect size calculation.\n\n\n⭐️ If You Found This Useful\n\n- Leave a star 🌟\n- Share feedback\n- Fork and adapt for your project\n- Mention the project in your work!\n\n## 9. License\n\nMIT License\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabulente%2Fkruskall-wallis-test","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjabulente%2Fkruskall-wallis-test","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjabulente%2Fkruskall-wallis-test/lists"}