@wentorai/research-plugins 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +204 -0
- package/curated/analysis/README.md +64 -0
- package/curated/domains/README.md +104 -0
- package/curated/literature/README.md +53 -0
- package/curated/research/README.md +62 -0
- package/curated/tools/README.md +87 -0
- package/curated/writing/README.md +61 -0
- package/index.ts +39 -0
- package/mcp-configs/academic-db/ChatSpatial.json +17 -0
- package/mcp-configs/academic-db/academia-mcp.json +17 -0
- package/mcp-configs/academic-db/academic-paper-explorer.json +17 -0
- package/mcp-configs/academic-db/academic-search-mcp-server.json +17 -0
- package/mcp-configs/academic-db/agentinterviews-mcp.json +17 -0
- package/mcp-configs/academic-db/all-in-mcp.json +17 -0
- package/mcp-configs/academic-db/apple-health-mcp.json +17 -0
- package/mcp-configs/academic-db/arxiv-latex-mcp.json +17 -0
- package/mcp-configs/academic-db/arxiv-mcp-server.json +17 -0
- package/mcp-configs/academic-db/bgpt-mcp.json +17 -0
- package/mcp-configs/academic-db/biomcp.json +17 -0
- package/mcp-configs/academic-db/biothings-mcp.json +17 -0
- package/mcp-configs/academic-db/catalysishub-mcp-server.json +17 -0
- package/mcp-configs/academic-db/clinicaltrialsgov-mcp-server.json +17 -0
- package/mcp-configs/academic-db/deep-research-mcp.json +17 -0
- package/mcp-configs/academic-db/dicom-mcp.json +17 -0
- package/mcp-configs/academic-db/enrichr-mcp-server.json +17 -0
- package/mcp-configs/academic-db/fec-mcp-server.json +17 -0
- package/mcp-configs/academic-db/fhir-mcp-server-themomentum.json +17 -0
- package/mcp-configs/academic-db/fhir-mcp.json +19 -0
- package/mcp-configs/academic-db/gget-mcp.json +17 -0
- package/mcp-configs/academic-db/google-researcher-mcp.json +17 -0
- package/mcp-configs/academic-db/idea-reality-mcp.json +17 -0
- package/mcp-configs/academic-db/legiscan-mcp.json +19 -0
- package/mcp-configs/academic-db/lex.json +17 -0
- package/mcp-configs/ai-platform/Adaptive-Graph-of-Thoughts-MCP-server.json +17 -0
- package/mcp-configs/ai-platform/ai-counsel.json +17 -0
- package/mcp-configs/ai-platform/atlas-mcp-server.json +17 -0
- package/mcp-configs/ai-platform/counsel-mcp.json +17 -0
- package/mcp-configs/ai-platform/cross-llm-mcp.json +17 -0
- package/mcp-configs/ai-platform/gptr-mcp.json +17 -0
- package/mcp-configs/browser/decipher-research-agent.json +17 -0
- package/mcp-configs/browser/deep-research.json +17 -0
- package/mcp-configs/browser/everything-claude-code.json +17 -0
- package/mcp-configs/browser/gpt-researcher.json +17 -0
- package/mcp-configs/browser/heurist-agent-framework.json +17 -0
- package/mcp-configs/data-platform/4everland-hosting-mcp.json +17 -0
- package/mcp-configs/data-platform/context-keeper.json +17 -0
- package/mcp-configs/data-platform/context7.json +19 -0
- package/mcp-configs/data-platform/contextstream-mcp.json +17 -0
- package/mcp-configs/data-platform/email-mcp.json +17 -0
- package/mcp-configs/note-knowledge/ApeRAG.json +17 -0
- package/mcp-configs/note-knowledge/In-Memoria.json +17 -0
- package/mcp-configs/note-knowledge/agent-memory.json +17 -0
- package/mcp-configs/note-knowledge/aimemo.json +17 -0
- package/mcp-configs/note-knowledge/biel-mcp.json +19 -0
- package/mcp-configs/note-knowledge/cognee.json +17 -0
- package/mcp-configs/note-knowledge/context-awesome.json +17 -0
- package/mcp-configs/note-knowledge/context-mcp.json +17 -0
- package/mcp-configs/note-knowledge/conversation-handoff-mcp.json +17 -0
- package/mcp-configs/note-knowledge/cortex.json +17 -0
- package/mcp-configs/note-knowledge/devrag.json +17 -0
- package/mcp-configs/note-knowledge/easy-obsidian-mcp.json +17 -0
- package/mcp-configs/note-knowledge/engram.json +17 -0
- package/mcp-configs/note-knowledge/gnosis-mcp.json +17 -0
- package/mcp-configs/note-knowledge/graphlit-mcp-server.json +19 -0
- package/mcp-configs/reference-mgr/arxiv-cli.json +17 -0
- package/mcp-configs/reference-mgr/arxiv-search-mcp.json +17 -0
- package/mcp-configs/reference-mgr/chiken.json +17 -0
- package/mcp-configs/reference-mgr/claude-scholar.json +17 -0
- package/mcp-configs/reference-mgr/devonthink-mcp.json +17 -0
- package/mcp-configs/registry.json +447 -0
- package/openclaw.plugin.json +21 -0
- package/package.json +61 -0
- package/skills/analysis/dataviz/color-accessibility-guide/SKILL.md +230 -0
- package/skills/analysis/dataviz/geospatial-viz-guide/SKILL.md +218 -0
- package/skills/analysis/dataviz/interactive-viz-guide/SKILL.md +287 -0
- package/skills/analysis/dataviz/network-visualization-guide/SKILL.md +195 -0
- package/skills/analysis/dataviz/publication-figures-guide/SKILL.md +238 -0
- package/skills/analysis/dataviz/python-dataviz-guide/SKILL.md +195 -0
- package/skills/analysis/econometrics/causal-inference-guide/SKILL.md +197 -0
- package/skills/analysis/econometrics/iv-regression-guide/SKILL.md +198 -0
- package/skills/analysis/econometrics/panel-data-guide/SKILL.md +274 -0
- package/skills/analysis/econometrics/robustness-checks/SKILL.md +250 -0
- package/skills/analysis/econometrics/stata-regression/SKILL.md +117 -0
- package/skills/analysis/econometrics/time-series-guide/SKILL.md +235 -0
- package/skills/analysis/statistics/bayesian-statistics-guide/SKILL.md +221 -0
- package/skills/analysis/statistics/hypothesis-testing-guide/SKILL.md +210 -0
- package/skills/analysis/statistics/meta-analysis-guide/SKILL.md +206 -0
- package/skills/analysis/statistics/nonparametric-tests-guide/SKILL.md +221 -0
- package/skills/analysis/statistics/power-analysis-guide/SKILL.md +240 -0
- package/skills/analysis/statistics/sem-guide/SKILL.md +231 -0
- package/skills/analysis/statistics/survival-analysis-guide/SKILL.md +195 -0
- package/skills/analysis/wrangling/missing-data-handling/SKILL.md +224 -0
- package/skills/analysis/wrangling/pandas-data-wrangling/SKILL.md +242 -0
- package/skills/analysis/wrangling/questionnaire-design-guide/SKILL.md +234 -0
- package/skills/analysis/wrangling/text-mining-guide/SKILL.md +225 -0
- package/skills/domains/ai-ml/computer-vision-guide/SKILL.md +213 -0
- package/skills/domains/ai-ml/deep-learning-papers-guide/SKILL.md +200 -0
- package/skills/domains/ai-ml/llm-evaluation-guide/SKILL.md +194 -0
- package/skills/domains/ai-ml/prompt-engineering-research/SKILL.md +233 -0
- package/skills/domains/ai-ml/reinforcement-learning-guide/SKILL.md +254 -0
- package/skills/domains/ai-ml/transformer-architecture-guide/SKILL.md +233 -0
- package/skills/domains/biomedical/clinical-research-guide/SKILL.md +232 -0
- package/skills/domains/biomedical/clinicaltrials-api/SKILL.md +177 -0
- package/skills/domains/biomedical/epidemiology-guide/SKILL.md +200 -0
- package/skills/domains/biomedical/genomics-analysis-guide/SKILL.md +270 -0
- package/skills/domains/business/market-analysis-guide/SKILL.md +112 -0
- package/skills/domains/business/strategic-management-guide/SKILL.md +154 -0
- package/skills/domains/chemistry/computational-chemistry-guide/SKILL.md +266 -0
- package/skills/domains/chemistry/retrosynthesis-guide/SKILL.md +215 -0
- package/skills/domains/cs/algorithms-complexity-guide/SKILL.md +194 -0
- package/skills/domains/cs/dblp-api/SKILL.md +129 -0
- package/skills/domains/cs/software-engineering-research/SKILL.md +218 -0
- package/skills/domains/ecology/biodiversity-data-guide/SKILL.md +296 -0
- package/skills/domains/ecology/conservation-biology-guide/SKILL.md +198 -0
- package/skills/domains/ecology/gbif-api/SKILL.md +158 -0
- package/skills/domains/ecology/inaturalist-api/SKILL.md +173 -0
- package/skills/domains/economics/behavioral-economics-guide/SKILL.md +239 -0
- package/skills/domains/economics/development-economics-guide/SKILL.md +181 -0
- package/skills/domains/economics/fred-api/SKILL.md +189 -0
- package/skills/domains/education/curriculum-design-guide/SKILL.md +144 -0
- package/skills/domains/education/learning-science-guide/SKILL.md +150 -0
- package/skills/domains/finance/financial-data-analysis/SKILL.md +152 -0
- package/skills/domains/finance/quantitative-finance-guide/SKILL.md +151 -0
- package/skills/domains/geoscience/climate-science-guide/SKILL.md +158 -0
- package/skills/domains/geoscience/gis-remote-sensing-guide/SKILL.md +129 -0
- package/skills/domains/humanities/digital-humanities-guide/SKILL.md +181 -0
- package/skills/domains/humanities/philosophy-research-guide/SKILL.md +148 -0
- package/skills/domains/law/courtlistener-api/SKILL.md +213 -0
- package/skills/domains/law/legal-research-guide/SKILL.md +250 -0
- package/skills/domains/math/linear-algebra-applications/SKILL.md +227 -0
- package/skills/domains/math/numerical-methods-guide/SKILL.md +236 -0
- package/skills/domains/math/oeis-api/SKILL.md +158 -0
- package/skills/domains/pharma/clinical-pharmacology-guide/SKILL.md +165 -0
- package/skills/domains/pharma/drug-development-guide/SKILL.md +177 -0
- package/skills/domains/physics/computational-physics-guide/SKILL.md +300 -0
- package/skills/domains/physics/nasa-ads-api/SKILL.md +150 -0
- package/skills/domains/physics/quantum-computing-guide/SKILL.md +234 -0
- package/skills/domains/social-science/social-research-methods/SKILL.md +194 -0
- package/skills/domains/social-science/survey-research-guide/SKILL.md +182 -0
- package/skills/literature/discovery/citation-alert-guide/SKILL.md +154 -0
- package/skills/literature/discovery/conference-proceedings-guide/SKILL.md +142 -0
- package/skills/literature/discovery/literature-mapping-guide/SKILL.md +175 -0
- package/skills/literature/discovery/paper-tracking-guide/SKILL.md +211 -0
- package/skills/literature/discovery/rss-paper-feeds/SKILL.md +214 -0
- package/skills/literature/discovery/semantic-scholar-recs-guide/SKILL.md +164 -0
- package/skills/literature/fulltext/doaj-api/SKILL.md +120 -0
- package/skills/literature/fulltext/interlibrary-loan-guide/SKILL.md +163 -0
- package/skills/literature/fulltext/open-access-guide/SKILL.md +183 -0
- package/skills/literature/fulltext/pmc-oai-api/SKILL.md +184 -0
- package/skills/literature/fulltext/preprint-servers-guide/SKILL.md +128 -0
- package/skills/literature/fulltext/repository-harvesting-guide/SKILL.md +207 -0
- package/skills/literature/fulltext/unpaywall-api/SKILL.md +113 -0
- package/skills/literature/metadata/altmetrics-guide/SKILL.md +132 -0
- package/skills/literature/metadata/citation-network-guide/SKILL.md +236 -0
- package/skills/literature/metadata/crossref-api/SKILL.md +133 -0
- package/skills/literature/metadata/datacite-api/SKILL.md +126 -0
- package/skills/literature/metadata/doi-resolution-guide/SKILL.md +168 -0
- package/skills/literature/metadata/h-index-guide/SKILL.md +183 -0
- package/skills/literature/metadata/journal-metrics-guide/SKILL.md +188 -0
- package/skills/literature/metadata/opencitations-api/SKILL.md +128 -0
- package/skills/literature/metadata/orcid-api/SKILL.md +136 -0
- package/skills/literature/metadata/orcid-integration-guide/SKILL.md +178 -0
- package/skills/literature/search/arxiv-api/SKILL.md +95 -0
- package/skills/literature/search/biorxiv-api/SKILL.md +123 -0
- package/skills/literature/search/boolean-search-guide/SKILL.md +199 -0
- package/skills/literature/search/citation-chaining-guide/SKILL.md +148 -0
- package/skills/literature/search/database-comparison-guide/SKILL.md +100 -0
- package/skills/literature/search/europe-pmc-api/SKILL.md +120 -0
- package/skills/literature/search/google-scholar-guide/SKILL.md +182 -0
- package/skills/literature/search/mesh-terms-guide/SKILL.md +164 -0
- package/skills/literature/search/openalex-api/SKILL.md +134 -0
- package/skills/literature/search/pubmed-api/SKILL.md +130 -0
- package/skills/literature/search/scientify-literature-survey/SKILL.md +203 -0
- package/skills/literature/search/semantic-scholar-api/SKILL.md +134 -0
- package/skills/literature/search/systematic-search-strategy/SKILL.md +214 -0
- package/skills/research/automation/ai-scientist-guide/SKILL.md +228 -0
- package/skills/research/automation/data-collection-automation/SKILL.md +248 -0
- package/skills/research/automation/research-workflow-automation/SKILL.md +266 -0
- package/skills/research/deep-research/meta-synthesis-guide/SKILL.md +174 -0
- package/skills/research/deep-research/research-cog/SKILL.md +153 -0
- package/skills/research/deep-research/scoping-review-guide/SKILL.md +217 -0
- package/skills/research/deep-research/systematic-review-guide/SKILL.md +250 -0
- package/skills/research/funding/figshare-api/SKILL.md +163 -0
- package/skills/research/funding/grant-writing-guide/SKILL.md +233 -0
- package/skills/research/funding/nsf-grant-guide/SKILL.md +206 -0
- package/skills/research/funding/open-science-guide/SKILL.md +255 -0
- package/skills/research/funding/zenodo-api/SKILL.md +174 -0
- package/skills/research/methodology/action-research-guide/SKILL.md +201 -0
- package/skills/research/methodology/experimental-design-guide/SKILL.md +236 -0
- package/skills/research/methodology/grad-school-guide/SKILL.md +182 -0
- package/skills/research/methodology/grounded-theory-guide/SKILL.md +171 -0
- package/skills/research/methodology/mixed-methods-guide/SKILL.md +208 -0
- package/skills/research/methodology/qualitative-research-guide/SKILL.md +234 -0
- package/skills/research/methodology/scientify-idea-generation/SKILL.md +222 -0
- package/skills/research/paper-review/paper-reading-assistant/SKILL.md +266 -0
- package/skills/research/paper-review/peer-review-guide/SKILL.md +227 -0
- package/skills/research/paper-review/rebuttal-writing-guide/SKILL.md +185 -0
- package/skills/research/paper-review/scientify-write-review-paper/SKILL.md +209 -0
- package/skills/tools/code-exec/jupyter-notebook-guide/SKILL.md +178 -0
- package/skills/tools/code-exec/python-reproducibility-guide/SKILL.md +341 -0
- package/skills/tools/code-exec/r-reproducibility-guide/SKILL.md +236 -0
- package/skills/tools/code-exec/sandbox-execution-guide/SKILL.md +221 -0
- package/skills/tools/diagram/mermaid-diagram-guide/SKILL.md +269 -0
- package/skills/tools/diagram/plantuml-guide/SKILL.md +397 -0
- package/skills/tools/diagram/scientific-illustration-guide/SKILL.md +225 -0
- package/skills/tools/document/anystyle-api/SKILL.md +199 -0
- package/skills/tools/document/grobid-pdf-parsing/SKILL.md +294 -0
- package/skills/tools/document/markdown-academic-guide/SKILL.md +217 -0
- package/skills/tools/document/pdf-extraction-guide/SKILL.md +321 -0
- package/skills/tools/knowledge-graph/knowledge-graph-construction/SKILL.md +306 -0
- package/skills/tools/knowledge-graph/ontology-design-guide/SKILL.md +214 -0
- package/skills/tools/knowledge-graph/rag-methodology-guide/SKILL.md +325 -0
- package/skills/tools/ocr-translate/formula-recognition-guide/SKILL.md +367 -0
- package/skills/tools/ocr-translate/handwriting-recognition-guide/SKILL.md +211 -0
- package/skills/tools/ocr-translate/latex-ocr-guide/SKILL.md +204 -0
- package/skills/tools/ocr-translate/multilingual-research-guide/SKILL.md +234 -0
- package/skills/tools/scraping/academic-web-scraping/SKILL.md +326 -0
- package/skills/tools/scraping/api-data-collection-guide/SKILL.md +301 -0
- package/skills/tools/scraping/web-scraping-ethics-guide/SKILL.md +250 -0
- package/skills/writing/citation/bibtex-management-guide/SKILL.md +246 -0
- package/skills/writing/citation/citation-style-guide/SKILL.md +248 -0
- package/skills/writing/citation/reference-manager-comparison/SKILL.md +208 -0
- package/skills/writing/citation/zotero-api/SKILL.md +188 -0
- package/skills/writing/composition/abstract-writing-guide/SKILL.md +188 -0
- package/skills/writing/composition/discussion-writing-guide/SKILL.md +194 -0
- package/skills/writing/composition/introduction-writing-guide/SKILL.md +194 -0
- package/skills/writing/composition/literature-review-writing/SKILL.md +196 -0
- package/skills/writing/composition/methods-section-guide/SKILL.md +185 -0
- package/skills/writing/composition/response-to-reviewers/SKILL.md +215 -0
- package/skills/writing/composition/scientific-writing-guide/SKILL.md +152 -0
- package/skills/writing/latex/bibliography-management-guide/SKILL.md +206 -0
- package/skills/writing/latex/latex-drawing-guide/SKILL.md +234 -0
- package/skills/writing/latex/latex-ecosystem-guide/SKILL.md +240 -0
- package/skills/writing/latex/math-typesetting-guide/SKILL.md +231 -0
- package/skills/writing/latex/overleaf-collaboration-guide/SKILL.md +211 -0
- package/skills/writing/latex/tikz-diagrams-guide/SKILL.md +211 -0
- package/skills/writing/polish/academic-translation-guide/SKILL.md +175 -0
- package/skills/writing/polish/academic-writing-refiner/SKILL.md +143 -0
- package/skills/writing/polish/ai-writing-humanizer/SKILL.md +178 -0
- package/skills/writing/polish/grammar-checker-guide/SKILL.md +184 -0
- package/skills/writing/polish/plagiarism-detection-guide/SKILL.md +167 -0
- package/skills/writing/templates/beamer-presentation-guide/SKILL.md +263 -0
- package/skills/writing/templates/conference-paper-template/SKILL.md +219 -0
- package/skills/writing/templates/thesis-template-guide/SKILL.md +200 -0
- package/skills/writing/templates/thesis-writing-guide/SKILL.md +220 -0
- package/src/tools/arxiv.ts +131 -0
- package/src/tools/crossref.ts +112 -0
- package/src/tools/openalex.ts +174 -0
- package/src/tools/pubmed.ts +166 -0
- package/src/tools/semantic-scholar.ts +108 -0
- package/src/tools/unpaywall.ts +58 -0
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: hypothesis-testing-guide
|
|
3
|
+
description: "Statistical hypothesis testing, power analysis, and significance reporting"
|
|
4
|
+
metadata:
|
|
5
|
+
openclaw:
|
|
6
|
+
emoji: "📈"
|
|
7
|
+
category: "analysis"
|
|
8
|
+
subcategory: "statistics"
|
|
9
|
+
keywords: ["hypothesis testing", "significance testing", "t-test", "ANOVA", "sample size calculation", "power analysis"]
|
|
10
|
+
source: "N/A"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Hypothesis Testing Guide
|
|
14
|
+
|
|
15
|
+
## Overview
|
|
16
|
+
|
|
17
|
+
Hypothesis testing is the backbone of empirical research. It provides a principled framework for deciding whether observed differences in data reflect genuine effects or merely random variation. Misuse of hypothesis tests -- p-hacking, ignoring assumptions, confusing statistical and practical significance -- is a leading cause of irreproducible findings.
|
|
18
|
+
|
|
19
|
+
This guide covers the core hypothesis testing framework, the most commonly used tests across disciplines, assumption checking, effect size reporting, power analysis for sample size planning, and multiple comparison corrections. Each test is accompanied by Python code using scipy, statsmodels, and pingouin, ready to integrate into research workflows.
|
|
20
|
+
|
|
21
|
+
The goal is not just to help you run tests, but to help you run the right test correctly and report results following modern standards (APA 7th edition, journal best practices).
|
|
22
|
+
|
|
23
|
+
## The Hypothesis Testing Framework
|
|
24
|
+
|
|
25
|
+
### Step-by-Step Procedure
|
|
26
|
+
|
|
27
|
+
1. **State hypotheses.** Define H0 (null: no effect) and H1 (alternative: effect exists).
|
|
28
|
+
2. **Choose significance level.** Typically alpha = 0.05, but justify your choice.
|
|
29
|
+
3. **Select the appropriate test.** Based on data type, distribution, and design.
|
|
30
|
+
4. **Check assumptions.** Normality, homogeneity of variance, independence.
|
|
31
|
+
5. **Compute test statistic and p-value.**
|
|
32
|
+
6. **Report effect size and confidence interval.** p-values alone are insufficient.
|
|
33
|
+
7. **Make a decision.** Reject or fail to reject H0, with practical interpretation.
|
|
34
|
+
|
|
35
|
+
### Common Errors
|
|
36
|
+
|
|
37
|
+
| Error Type | Definition | Probability |
|
|
38
|
+
|-----------|-----------|-------------|
|
|
39
|
+
| Type I (False Positive) | Reject H0 when it is true | alpha (usually 0.05) |
|
|
40
|
+
| Type II (False Negative) | Fail to reject H0 when it is false | beta (usually 0.20) |
|
|
41
|
+
| Power | Probability of correctly detecting an effect | 1 - beta (target: 0.80) |
|
|
42
|
+
|
|
43
|
+
## Test Selection Guide
|
|
44
|
+
|
|
45
|
+
| Research Question | Data Type | Groups | Test |
|
|
46
|
+
|-------------------|-----------|--------|------|
|
|
47
|
+
| Two group means differ? | Continuous, normal | 2 independent | Independent t-test |
|
|
48
|
+
| Before/after difference? | Continuous, normal | 2 paired | Paired t-test |
|
|
49
|
+
| Multiple group means differ? | Continuous, normal | 3+ independent | One-way ANOVA |
|
|
50
|
+
| Two group medians differ? | Ordinal / non-normal | 2 independent | Mann-Whitney U |
|
|
51
|
+
| Before/after (non-normal)? | Ordinal / non-normal | 2 paired | Wilcoxon signed-rank |
|
|
52
|
+
| Multiple groups (non-normal)? | Ordinal / non-normal | 3+ independent | Kruskal-Wallis |
|
|
53
|
+
| Association between categories? | Categorical | 2 variables | Chi-square test |
|
|
54
|
+
| Correlation? | Continuous | 2 variables | Pearson or Spearman |
|
|
55
|
+
|
|
56
|
+
## Running Tests in Python
|
|
57
|
+
|
|
58
|
+
### Independent Samples t-Test
|
|
59
|
+
|
|
60
|
+
```python
|
|
61
|
+
from scipy import stats
|
|
62
|
+
import numpy as np
|
|
63
|
+
import pingouin as pg
|
|
64
|
+
|
|
65
|
+
# Generate example data
|
|
66
|
+
control = np.random.normal(50, 10, n=30)
|
|
67
|
+
treatment = np.random.normal(55, 10, n=30)
|
|
68
|
+
|
|
69
|
+
# Check normality assumption
|
|
70
|
+
stat_c, p_c = stats.shapiro(control)
|
|
71
|
+
stat_t, p_t = stats.shapiro(treatment)
|
|
72
|
+
print(f"Normality p-values: control={p_c:.3f}, treatment={p_t:.3f}")
|
|
73
|
+
|
|
74
|
+
# Check homogeneity of variance
|
|
75
|
+
stat_l, p_l = stats.levene(control, treatment)
|
|
76
|
+
print(f"Levene's test p={p_l:.3f}")
|
|
77
|
+
|
|
78
|
+
# Run t-test
|
|
79
|
+
t_stat, p_val = stats.ttest_ind(control, treatment, equal_var=(p_l > 0.05))
|
|
80
|
+
|
|
81
|
+
# Effect size (Cohen's d)
|
|
82
|
+
cohens_d = (treatment.mean() - control.mean()) / np.sqrt(
|
|
83
|
+
((len(control)-1)*control.var() + (len(treatment)-1)*treatment.var())
|
|
84
|
+
/ (len(control) + len(treatment) - 2)
|
|
85
|
+
)
|
|
86
|
+
|
|
87
|
+
print(f"t={t_stat:.3f}, p={p_val:.4f}, Cohen's d={cohens_d:.3f}")
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### One-Way ANOVA with Post-Hoc Tests
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
import pandas as pd
|
|
94
|
+
|
|
95
|
+
df = pd.DataFrame({
|
|
96
|
+
'score': np.concatenate([
|
|
97
|
+
np.random.normal(50, 10, 30),
|
|
98
|
+
np.random.normal(55, 10, 30),
|
|
99
|
+
np.random.normal(60, 10, 30)
|
|
100
|
+
]),
|
|
101
|
+
'group': np.repeat(['A', 'B', 'C'], 30)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
# ANOVA
|
|
105
|
+
aov = pg.anova(data=df, dv='score', between='group', detailed=True)
|
|
106
|
+
print(aov)
|
|
107
|
+
|
|
108
|
+
# Post-hoc pairwise comparisons (Tukey HSD)
|
|
109
|
+
posthoc = pg.pairwise_tukey(data=df, dv='score', between='group')
|
|
110
|
+
print(posthoc[['A', 'B', 'diff', 'p-tukey', 'hedges']])
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### Chi-Square Test of Independence
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# Contingency table
|
|
117
|
+
observed = pd.DataFrame(
|
|
118
|
+
[[45, 30], [25, 50]],
|
|
119
|
+
index=['Method A', 'Method B'],
|
|
120
|
+
columns=['Success', 'Failure']
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
chi2, p, dof, expected = stats.chi2_contingency(observed)
|
|
124
|
+
cramers_v = np.sqrt(chi2 / (observed.values.sum() * (min(observed.shape) - 1)))
|
|
125
|
+
|
|
126
|
+
print(f"chi2={chi2:.3f}, p={p:.4f}, Cramer's V={cramers_v:.3f}")
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Power Analysis and Sample Size
|
|
130
|
+
|
|
131
|
+
Power analysis answers: "How many participants do I need?"
|
|
132
|
+
|
|
133
|
+
```python
|
|
134
|
+
from statsmodels.stats.power import TTestIndPower, FTestAnovaPower
|
|
135
|
+
|
|
136
|
+
# For a two-sample t-test
|
|
137
|
+
analysis = TTestIndPower()
|
|
138
|
+
|
|
139
|
+
# Calculate required sample size
|
|
140
|
+
n = analysis.solve_power(
|
|
141
|
+
effect_size=0.5, # Cohen's d (medium effect)
|
|
142
|
+
alpha=0.05,
|
|
143
|
+
power=0.80,
|
|
144
|
+
ratio=1.0, # Equal group sizes
|
|
145
|
+
alternative='two-sided'
|
|
146
|
+
)
|
|
147
|
+
print(f"Required n per group: {int(np.ceil(n))}")
|
|
148
|
+
|
|
149
|
+
# Power curve
|
|
150
|
+
import matplotlib.pyplot as plt
|
|
151
|
+
|
|
152
|
+
sample_sizes = np.arange(10, 200, 5)
|
|
153
|
+
powers = [analysis.power(effect_size=0.5, nobs1=n, ratio=1.0, alpha=0.05)
|
|
154
|
+
for n in sample_sizes]
|
|
155
|
+
|
|
156
|
+
fig, ax = plt.subplots()
|
|
157
|
+
ax.plot(sample_sizes, powers)
|
|
158
|
+
ax.axhline(0.8, color='red', linestyle='--', label='Power = 0.80')
|
|
159
|
+
ax.set_xlabel('Sample Size per Group')
|
|
160
|
+
ax.set_ylabel('Statistical Power')
|
|
161
|
+
ax.legend()
|
|
162
|
+
fig.savefig('power_curve.pdf')
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
### Effect Size Reference Table
|
|
166
|
+
|
|
167
|
+
| Effect Size | Small | Medium | Large |
|
|
168
|
+
|-------------|-------|--------|-------|
|
|
169
|
+
| Cohen's d (t-test) | 0.2 | 0.5 | 0.8 |
|
|
170
|
+
| eta-squared (ANOVA) | 0.01 | 0.06 | 0.14 |
|
|
171
|
+
| Cramer's V (chi-square) | 0.1 | 0.3 | 0.5 |
|
|
172
|
+
| Pearson r (correlation) | 0.1 | 0.3 | 0.5 |
|
|
173
|
+
|
|
174
|
+
## Multiple Comparison Corrections
|
|
175
|
+
|
|
176
|
+
When running multiple tests, the family-wise error rate inflates. Use corrections:
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
from statsmodels.stats.multitest import multipletests
|
|
180
|
+
|
|
181
|
+
p_values = [0.01, 0.04, 0.03, 0.08, 0.002]
|
|
182
|
+
|
|
183
|
+
# Bonferroni (conservative)
|
|
184
|
+
reject_bonf, pvals_bonf, _, _ = multipletests(p_values, method='bonferroni')
|
|
185
|
+
|
|
186
|
+
# Benjamini-Hochberg FDR (less conservative)
|
|
187
|
+
reject_bh, pvals_bh, _, _ = multipletests(p_values, method='fdr_bh')
|
|
188
|
+
|
|
189
|
+
for i, p in enumerate(p_values):
|
|
190
|
+
print(f"p={p:.3f} | Bonferroni: {pvals_bonf[i]:.3f} ({reject_bonf[i]}) "
|
|
191
|
+
f"| BH-FDR: {pvals_bh[i]:.3f} ({reject_bh[i]})")
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
## Best Practices
|
|
195
|
+
|
|
196
|
+
- **Always report effect sizes alongside p-values.** A significant p-value with a tiny effect size is rarely meaningful.
|
|
197
|
+
- **Pre-register your analysis plan.** This prevents p-hacking and HARKing (Hypothesizing After Results are Known).
|
|
198
|
+
- **Check assumptions before running parametric tests.** Use non-parametric alternatives when assumptions are violated.
|
|
199
|
+
- **Use confidence intervals.** They convey both effect magnitude and precision.
|
|
200
|
+
- **Report exact p-values (p = 0.032), not thresholds (p < 0.05).** Except when p < 0.001.
|
|
201
|
+
- **Consider Bayesian alternatives.** Bayes factors provide evidence for H0, not just against it.
|
|
202
|
+
- **Plan sample sizes a priori.** Power analysis should be done before data collection, not after.
|
|
203
|
+
|
|
204
|
+
## References
|
|
205
|
+
|
|
206
|
+
- [scipy.stats Documentation](https://docs.scipy.org/doc/scipy/reference/stats.html)
|
|
207
|
+
- [pingouin Documentation](https://pingouin-stats.org/) -- Friendly statistics in Python
|
|
208
|
+
- [statsmodels Documentation](https://www.statsmodels.org/)
|
|
209
|
+
- [APA 7th Edition Statistics Reporting Guide](https://apastyle.apa.org/instructional-aids/numbers-statistics-guide.pdf)
|
|
210
|
+
- [Statistical Tests Cheat Sheet](https://machinelearningmastery.com/statistical-hypothesis-tests-in-python-cheat-sheet/)
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: meta-analysis-guide
|
|
3
|
+
description: "Conduct systematic meta-analyses with effect size pooling and heterogeneity a..."
|
|
4
|
+
metadata:
|
|
5
|
+
openclaw:
|
|
6
|
+
emoji: "balance_scale"
|
|
7
|
+
category: "analysis"
|
|
8
|
+
subcategory: "statistics"
|
|
9
|
+
keywords: ["meta-analysis", "statistical synthesis", "heterogeneity", "effect size", "forest plot"]
|
|
10
|
+
source: "wentor"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Meta-Analysis Guide
|
|
14
|
+
|
|
15
|
+
A skill for conducting rigorous meta-analyses: computing and pooling effect sizes, assessing heterogeneity, evaluating publication bias, and generating forest plots. Follows Cochrane Handbook and PRISMA guidelines.
|
|
16
|
+
|
|
17
|
+
## Effect Size Computation
|
|
18
|
+
|
|
19
|
+
### Common Effect Size Measures
|
|
20
|
+
|
|
21
|
+
| Measure | Use Case | Formula | Interpretation |
|
|
22
|
+
|---------|----------|---------|----------------|
|
|
23
|
+
| Cohen's d | Mean difference (2 groups) | (M1 - M2) / S_pooled | 0.2 small, 0.5 medium, 0.8 large |
|
|
24
|
+
| Hedges' g | d with small-sample correction | d * J(df) | Preferred over d for small N |
|
|
25
|
+
| Pearson r | Correlation | r | 0.1 small, 0.3 medium, 0.5 large |
|
|
26
|
+
| Odds Ratio | Binary outcomes | (a*d)/(b*c) | 1 = no effect |
|
|
27
|
+
| Risk Ratio | Binary outcomes | (a/(a+b))/(c/(c+d)) | 1 = no effect |
|
|
28
|
+
| SMD | Standardized mean difference | Same as Hedges' g | When scales differ |
|
|
29
|
+
|
|
30
|
+
### Computing Effect Sizes in Python
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import numpy as np
|
|
34
|
+
from dataclasses import dataclass
|
|
35
|
+
|
|
36
|
+
@dataclass
|
|
37
|
+
class EffectSize:
|
|
38
|
+
estimate: float
|
|
39
|
+
variance: float
|
|
40
|
+
se: float
|
|
41
|
+
ci_lower: float
|
|
42
|
+
ci_upper: float
|
|
43
|
+
measure: str
|
|
44
|
+
|
|
45
|
+
def cohens_d(m1: float, m2: float, sd1: float, sd2: float,
|
|
46
|
+
n1: int, n2: int) -> EffectSize:
|
|
47
|
+
"""
|
|
48
|
+
Compute Hedges' g (bias-corrected Cohen's d).
|
|
49
|
+
"""
|
|
50
|
+
# Pooled standard deviation
|
|
51
|
+
sd_pooled = np.sqrt(((n1-1)*sd1**2 + (n2-1)*sd2**2) / (n1+n2-2))
|
|
52
|
+
|
|
53
|
+
# Cohen's d
|
|
54
|
+
d = (m1 - m2) / sd_pooled
|
|
55
|
+
|
|
56
|
+
# Small-sample correction (Hedges' g)
|
|
57
|
+
df = n1 + n2 - 2
|
|
58
|
+
j = 1 - (3 / (4*df - 1))
|
|
59
|
+
g = d * j
|
|
60
|
+
|
|
61
|
+
# Variance of g
|
|
62
|
+
var_g = (n1+n2)/(n1*n2) + g**2 / (2*(n1+n2))
|
|
63
|
+
se_g = np.sqrt(var_g)
|
|
64
|
+
|
|
65
|
+
return EffectSize(
|
|
66
|
+
estimate=g,
|
|
67
|
+
variance=var_g,
|
|
68
|
+
se=se_g,
|
|
69
|
+
ci_lower=g - 1.96*se_g,
|
|
70
|
+
ci_upper=g + 1.96*se_g,
|
|
71
|
+
measure='Hedges_g'
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def odds_ratio(a: int, b: int, c: int, d: int) -> EffectSize:
|
|
75
|
+
"""
|
|
76
|
+
Compute log odds ratio from a 2x2 table.
|
|
77
|
+
a=treatment success, b=treatment failure, c=control success, d=control failure
|
|
78
|
+
"""
|
|
79
|
+
# Add 0.5 continuity correction if any cell is 0
|
|
80
|
+
if any(x == 0 for x in [a, b, c, d]):
|
|
81
|
+
a, b, c, d = a+0.5, b+0.5, c+0.5, d+0.5
|
|
82
|
+
|
|
83
|
+
log_or = np.log((a*d) / (b*c))
|
|
84
|
+
var = 1/a + 1/b + 1/c + 1/d
|
|
85
|
+
se = np.sqrt(var)
|
|
86
|
+
|
|
87
|
+
return EffectSize(
|
|
88
|
+
estimate=log_or,
|
|
89
|
+
variance=var,
|
|
90
|
+
se=se,
|
|
91
|
+
ci_lower=log_or - 1.96*se,
|
|
92
|
+
ci_upper=log_or + 1.96*se,
|
|
93
|
+
measure='log_OR'
|
|
94
|
+
)
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Fixed-Effect and Random-Effects Models
|
|
98
|
+
|
|
99
|
+
### Inverse-Variance Pooling
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
def random_effects_meta(effects: list[EffectSize]) -> dict:
|
|
103
|
+
"""
|
|
104
|
+
Random-effects meta-analysis using DerSimonian-Laird estimator.
|
|
105
|
+
"""
|
|
106
|
+
yi = np.array([e.estimate for e in effects])
|
|
107
|
+
vi = np.array([e.variance for e in effects])
|
|
108
|
+
wi = 1 / vi
|
|
109
|
+
k = len(effects)
|
|
110
|
+
|
|
111
|
+
# Fixed-effect estimate
|
|
112
|
+
fe_estimate = np.sum(wi * yi) / np.sum(wi)
|
|
113
|
+
|
|
114
|
+
# Q statistic for heterogeneity
|
|
115
|
+
Q = np.sum(wi * (yi - fe_estimate)**2)
|
|
116
|
+
df = k - 1
|
|
117
|
+
|
|
118
|
+
# DerSimonian-Laird tau-squared
|
|
119
|
+
C = np.sum(wi) - np.sum(wi**2) / np.sum(wi)
|
|
120
|
+
tau2 = max(0, (Q - df) / C)
|
|
121
|
+
|
|
122
|
+
# Random-effects weights
|
|
123
|
+
wi_re = 1 / (vi + tau2)
|
|
124
|
+
re_estimate = np.sum(wi_re * yi) / np.sum(wi_re)
|
|
125
|
+
re_se = np.sqrt(1 / np.sum(wi_re))
|
|
126
|
+
re_ci = (re_estimate - 1.96*re_se, re_estimate + 1.96*re_se)
|
|
127
|
+
|
|
128
|
+
# Heterogeneity statistics
|
|
129
|
+
I2 = max(0, (Q - df) / Q * 100) if Q > 0 else 0
|
|
130
|
+
H2 = Q / df if df > 0 else 1
|
|
131
|
+
|
|
132
|
+
return {
|
|
133
|
+
'pooled_effect': re_estimate,
|
|
134
|
+
'se': re_se,
|
|
135
|
+
'ci_95': re_ci,
|
|
136
|
+
'tau_squared': tau2,
|
|
137
|
+
'Q_statistic': Q,
|
|
138
|
+
'Q_df': df,
|
|
139
|
+
'Q_pvalue': 1 - stats.chi2.cdf(Q, df),
|
|
140
|
+
'I_squared': I2,
|
|
141
|
+
'H_squared': H2,
|
|
142
|
+
'interpretation': (
|
|
143
|
+
f"I-squared = {I2:.1f}%: "
|
|
144
|
+
+ ('low' if I2 < 25 else 'moderate' if I2 < 75 else 'high')
|
|
145
|
+
+ ' heterogeneity'
|
|
146
|
+
)
|
|
147
|
+
}
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
## Forest Plot
|
|
151
|
+
|
|
152
|
+
```python
|
|
153
|
+
import matplotlib.pyplot as plt
|
|
154
|
+
|
|
155
|
+
def forest_plot(studies: list[dict], pooled: dict,
|
|
156
|
+
title: str = 'Forest Plot') -> plt.Figure:
|
|
157
|
+
"""
|
|
158
|
+
Create a publication-quality forest plot.
|
|
159
|
+
|
|
160
|
+
Args:
|
|
161
|
+
studies: List of dicts with 'name', 'effect', 'ci_lower', 'ci_upper', 'weight'
|
|
162
|
+
pooled: Dict with 'pooled_effect', 'ci_95'
|
|
163
|
+
"""
|
|
164
|
+
fig, ax = plt.subplots(figsize=(10, max(6, len(studies)*0.5)))
|
|
165
|
+
k = len(studies)
|
|
166
|
+
|
|
167
|
+
for i, study in enumerate(studies):
|
|
168
|
+
y = k - i
|
|
169
|
+
ax.plot([study['ci_lower'], study['ci_upper']], [y, y], 'b-', linewidth=1)
|
|
170
|
+
size = study.get('weight', 5) * 2
|
|
171
|
+
ax.plot(study['effect'], y, 'bs', markersize=max(3, min(size, 15)))
|
|
172
|
+
ax.text(-0.05, y, study['name'], ha='right', va='center', fontsize=9,
|
|
173
|
+
transform=ax.get_yaxis_transform())
|
|
174
|
+
|
|
175
|
+
# Pooled estimate (diamond)
|
|
176
|
+
pe = pooled['pooled_effect']
|
|
177
|
+
ci = pooled['ci_95']
|
|
178
|
+
ax.fill([ci[0], pe, ci[1], pe], [0.3, 0.6, 0.3, 0], 'r', alpha=0.7)
|
|
179
|
+
|
|
180
|
+
ax.axvline(x=0, color='gray', linestyle='--', linewidth=0.5)
|
|
181
|
+
ax.set_xlabel('Effect Size (Hedges g)')
|
|
182
|
+
ax.set_title(title)
|
|
183
|
+
ax.set_yticks([])
|
|
184
|
+
plt.tight_layout()
|
|
185
|
+
return fig
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
## Publication Bias Assessment
|
|
189
|
+
|
|
190
|
+
Methods to assess and address publication bias:
|
|
191
|
+
|
|
192
|
+
1. **Funnel plot**: Visual inspection for asymmetry
|
|
193
|
+
2. **Egger's test**: Regression test for funnel plot asymmetry (p < 0.10 suggests bias)
|
|
194
|
+
3. **Trim-and-fill**: Imputes missing studies to correct for bias
|
|
195
|
+
4. **p-curve analysis**: Tests whether significant results contain evidential value
|
|
196
|
+
5. **Selection models**: Formally model the publication process (e.g., Vevea-Hedges)
|
|
197
|
+
|
|
198
|
+
## Reporting Standards
|
|
199
|
+
|
|
200
|
+
Follow PRISMA 2020 guidelines for reporting:
|
|
201
|
+
- Report all effect sizes with 95% CIs
|
|
202
|
+
- Report Q, I-squared, and tau-squared for heterogeneity
|
|
203
|
+
- Include forest plots for all primary outcomes
|
|
204
|
+
- Report funnel plots and publication bias tests
|
|
205
|
+
- Provide subgroup analyses and sensitivity analyses (leave-one-out)
|
|
206
|
+
- Register the protocol on PROSPERO before conducting the review
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: nonparametric-tests-guide
|
|
3
|
+
description: "Apply Mann-Whitney, Kruskal-Wallis, and other nonparametric methods"
|
|
4
|
+
metadata:
|
|
5
|
+
openclaw:
|
|
6
|
+
emoji: "chart_with_upwards_trend"
|
|
7
|
+
category: "analysis"
|
|
8
|
+
subcategory: "statistics"
|
|
9
|
+
keywords: ["nonparametric tests", "Mann-Whitney", "Kruskal-Wallis", "Wilcoxon", "rank-based tests", "distribution-free"]
|
|
10
|
+
source: "wentor-research-plugins"
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
# Nonparametric Tests Guide
|
|
14
|
+
|
|
15
|
+
A skill for selecting and applying nonparametric statistical tests when data violate parametric assumptions. Covers rank-based tests for group comparisons, correlation, and paired data, with implementation examples and guidance on reporting.
|
|
16
|
+
|
|
17
|
+
## When to Use Nonparametric Tests
|
|
18
|
+
|
|
19
|
+
### Decision Criteria
|
|
20
|
+
|
|
21
|
+
```
|
|
22
|
+
Use nonparametric tests when:
|
|
23
|
+
- Data are ordinal (Likert scales, rankings)
|
|
24
|
+
- Distribution is clearly non-normal (heavy skew, outliers)
|
|
25
|
+
- Sample size is very small (n < 15-20 per group)
|
|
26
|
+
- Homogeneity of variance is violated
|
|
27
|
+
- You are analyzing ranks or medians rather than means
|
|
28
|
+
|
|
29
|
+
Use parametric tests when:
|
|
30
|
+
- Data are approximately normal (or n > 30 by CLT)
|
|
31
|
+
- Variance is homogeneous across groups
|
|
32
|
+
- You need greater statistical power
|
|
33
|
+
- The parametric assumptions are reasonably met
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Test Selection Guide
|
|
37
|
+
|
|
38
|
+
| Parametric Test | Nonparametric Alternative | Use Case |
|
|
39
|
+
|----------------|--------------------------|----------|
|
|
40
|
+
| Independent t-test | Mann-Whitney U | Compare 2 independent groups |
|
|
41
|
+
| Paired t-test | Wilcoxon signed-rank | Compare 2 related samples |
|
|
42
|
+
| One-way ANOVA | Kruskal-Wallis H | Compare 3+ independent groups |
|
|
43
|
+
| Repeated measures ANOVA | Friedman test | Compare 3+ related samples |
|
|
44
|
+
| Pearson correlation | Spearman rank correlation | Measure association |
|
|
45
|
+
| Chi-square test | Fisher's exact test | Compare proportions (small n) |
|
|
46
|
+
|
|
47
|
+
## Mann-Whitney U Test
|
|
48
|
+
|
|
49
|
+
### Two Independent Groups
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
from scipy import stats
|
|
53
|
+
import numpy as np
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def mann_whitney_test(group_a: list, group_b: list) -> dict:
|
|
57
|
+
"""
|
|
58
|
+
Perform Mann-Whitney U test for two independent groups.
|
|
59
|
+
|
|
60
|
+
Args:
|
|
61
|
+
group_a: Observations from group A
|
|
62
|
+
group_b: Observations from group B
|
|
63
|
+
"""
|
|
64
|
+
statistic, p_value = stats.mannwhitneyu(
|
|
65
|
+
group_a, group_b, alternative="two-sided"
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
n_a, n_b = len(group_a), len(group_b)
|
|
69
|
+
|
|
70
|
+
# Rank-biserial correlation as effect size
|
|
71
|
+
r = 1 - (2 * statistic) / (n_a * n_b)
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
"U_statistic": statistic,
|
|
75
|
+
"p_value": p_value,
|
|
76
|
+
"n_a": n_a,
|
|
77
|
+
"n_b": n_b,
|
|
78
|
+
"median_a": np.median(group_a),
|
|
79
|
+
"median_b": np.median(group_b),
|
|
80
|
+
"effect_size_r": abs(r),
|
|
81
|
+
"effect_interpretation": (
|
|
82
|
+
"small" if abs(r) < 0.3
|
|
83
|
+
else "medium" if abs(r) < 0.5
|
|
84
|
+
else "large"
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
# Example usage
|
|
90
|
+
control = [12, 15, 14, 10, 13, 11, 16, 9, 14, 12]
|
|
91
|
+
treatment = [18, 22, 19, 17, 20, 21, 16, 23, 19, 20]
|
|
92
|
+
result = mann_whitney_test(control, treatment)
|
|
93
|
+
print(f"U = {result['U_statistic']}, p = {result['p_value']:.4f}")
|
|
94
|
+
print(f"Effect size r = {result['effect_size_r']:.3f} ({result['effect_interpretation']})")
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Kruskal-Wallis H Test
|
|
98
|
+
|
|
99
|
+
### Three or More Independent Groups
|
|
100
|
+
|
|
101
|
+
```python
|
|
102
|
+
def kruskal_wallis_with_posthoc(*groups) -> dict:
|
|
103
|
+
"""
|
|
104
|
+
Perform Kruskal-Wallis test with Dunn's post-hoc comparisons.
|
|
105
|
+
|
|
106
|
+
Args:
|
|
107
|
+
*groups: Variable number of group data arrays
|
|
108
|
+
"""
|
|
109
|
+
# Omnibus test
|
|
110
|
+
h_stat, p_value = stats.kruskal(*groups)
|
|
111
|
+
|
|
112
|
+
result = {
|
|
113
|
+
"H_statistic": h_stat,
|
|
114
|
+
"p_value": p_value,
|
|
115
|
+
"n_groups": len(groups),
|
|
116
|
+
"group_medians": [np.median(g) for g in groups]
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
# If significant, perform pairwise Mann-Whitney with Bonferroni correction
|
|
120
|
+
if p_value < 0.05:
|
|
121
|
+
n_comparisons = len(groups) * (len(groups) - 1) // 2
|
|
122
|
+
pairwise = []
|
|
123
|
+
for i in range(len(groups)):
|
|
124
|
+
for j in range(i + 1, len(groups)):
|
|
125
|
+
u, p = stats.mannwhitneyu(groups[i], groups[j])
|
|
126
|
+
pairwise.append({
|
|
127
|
+
"comparison": f"Group {i+1} vs Group {j+1}",
|
|
128
|
+
"U": u,
|
|
129
|
+
"p_raw": p,
|
|
130
|
+
"p_adjusted": min(p * n_comparisons, 1.0),
|
|
131
|
+
"significant": (p * n_comparisons) < 0.05
|
|
132
|
+
})
|
|
133
|
+
result["posthoc"] = pairwise
|
|
134
|
+
|
|
135
|
+
return result
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Wilcoxon Signed-Rank Test
|
|
139
|
+
|
|
140
|
+
### Paired or Repeated Measures
|
|
141
|
+
|
|
142
|
+
```python
|
|
143
|
+
def wilcoxon_signed_rank(before: list, after: list) -> dict:
|
|
144
|
+
"""
|
|
145
|
+
Perform Wilcoxon signed-rank test for paired data.
|
|
146
|
+
|
|
147
|
+
Args:
|
|
148
|
+
before: Pre-intervention measurements
|
|
149
|
+
after: Post-intervention measurements
|
|
150
|
+
"""
|
|
151
|
+
statistic, p_value = stats.wilcoxon(before, after)
|
|
152
|
+
|
|
153
|
+
n = len(before)
|
|
154
|
+
# Effect size: r = Z / sqrt(N)
|
|
155
|
+
z_score = stats.norm.ppf(1 - p_value / 2)
|
|
156
|
+
r = z_score / np.sqrt(n)
|
|
157
|
+
|
|
158
|
+
differences = [a - b for a, b in zip(after, before)]
|
|
159
|
+
|
|
160
|
+
return {
|
|
161
|
+
"W_statistic": statistic,
|
|
162
|
+
"p_value": p_value,
|
|
163
|
+
"n_pairs": n,
|
|
164
|
+
"median_difference": np.median(differences),
|
|
165
|
+
"effect_size_r": abs(r)
|
|
166
|
+
}
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
## Spearman Rank Correlation
|
|
170
|
+
|
|
171
|
+
### Monotonic Association
|
|
172
|
+
|
|
173
|
+
```python
|
|
174
|
+
def spearman_correlation(x: list, y: list) -> dict:
|
|
175
|
+
"""
|
|
176
|
+
Compute Spearman rank correlation.
|
|
177
|
+
"""
|
|
178
|
+
rho, p_value = stats.spearmanr(x, y)
|
|
179
|
+
|
|
180
|
+
return {
|
|
181
|
+
"rho": rho,
|
|
182
|
+
"p_value": p_value,
|
|
183
|
+
"interpretation": (
|
|
184
|
+
"negligible" if abs(rho) < 0.1
|
|
185
|
+
else "weak" if abs(rho) < 0.3
|
|
186
|
+
else "moderate" if abs(rho) < 0.5
|
|
187
|
+
else "strong" if abs(rho) < 0.7
|
|
188
|
+
else "very strong"
|
|
189
|
+
)
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
## Reporting Nonparametric Results
|
|
194
|
+
|
|
195
|
+
### APA-Style Reporting Examples
|
|
196
|
+
|
|
197
|
+
```
|
|
198
|
+
Mann-Whitney U:
|
|
199
|
+
"A Mann-Whitney U test indicated that treatment scores
|
|
200
|
+
(Mdn = 20.0) were significantly higher than control scores
|
|
201
|
+
(Mdn = 13.0), U = 5.0, p < .001, r = .82."
|
|
202
|
+
|
|
203
|
+
Kruskal-Wallis:
|
|
204
|
+
"A Kruskal-Wallis H test showed a significant difference
|
|
205
|
+
in scores across the three conditions, H(2) = 15.32,
|
|
206
|
+
p < .001. Post-hoc pairwise comparisons with Bonferroni
|
|
207
|
+
correction revealed..."
|
|
208
|
+
|
|
209
|
+
Wilcoxon Signed-Rank:
|
|
210
|
+
"A Wilcoxon signed-rank test showed that the intervention
|
|
211
|
+
significantly improved scores (Mdn_diff = 4.5),
|
|
212
|
+
W = 12.0, p = .003, r = .58."
|
|
213
|
+
|
|
214
|
+
Spearman:
|
|
215
|
+
"There was a strong positive correlation between X and Y,
|
|
216
|
+
r_s = .72, p < .001."
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
### Effect Size Guidelines
|
|
220
|
+
|
|
221
|
+
Always report effect sizes alongside p-values. For rank-biserial correlation r: small (0.1), medium (0.3), large (0.5). For Spearman rho, use standard correlation benchmarks. Effect sizes allow readers to judge practical significance independent of sample size.
|