nonparametric_test
Perform Wilcoxon, Mann-Whitney, or Kruskal-Wallis tests on CSV/Excel/JSON data to compare paired, two-group, or multi-group samples without normality assumptions. Get p-values, effect sizes, and clear conclusions.
Instructions
nonparametric_test —— 统计推断组 · 非参数检验(工具 26,核心实现)。
docstring = agent 使用说明书,与 statlab_mcp/docs/design/09_inference_batch3.md 同步维护。
参数: file_path (str): 本地数据文件(csv/tsv/xlsx/json) test (str, "wilcoxon"): wilcoxon(配对)/ mann_whitney(两组独立)/ kruskal_wallis(多组) column (str): test=wilcoxon 时必填(配对的第一组测量) sample2_col (str): test=wilcoxon 时必填(配对第二组测量) group_col (str): test=mann_whitney / kruskal_wallis 时必填(分组列) value_col (str): test=mann_whitney / kruskal_wallis 时必填(数值列) alpha (float, 0.05): 显著性水平 ∈ (0,1) alternative (str, "two_sided"): two_sided / less / greater(仅 wilcoxon 与 mann_whitney 生效;kruskal_wallis 恒为双侧)
口径(设计文档 09 钉死): wilcoxon: scipy.stats.wilcoxon(zero_method="wilcox", correction=False, method="auto")——0 差剔除(zero_method=wilcox 语义);method="auto": 小样本无 ties 用精确分布,否则正态近似;效应量 matched rank-biserial r = 2×(正秩和)/n(n+1) − 1,等价式 1 − 4W/(n(n+1))(W=scipy 返回的较小秩和), 方向以 mean(column − sample2_col) 符号定(column 高为正侧),n=剔除 0 差后的对数。 mann_whitney: scipy.stats.mannwhitneyu(use_continuity=True, method="auto") ——注明 ties 时用正态近似含连续性校正;效应量 rank-biserial r = 2U/(n1·n2) − 1(U=scipy 对 group1 的统计量),方向 group1 高为正侧。 kruskal_wallis: scipy.stats.kruskal——统计量 H(未做 ties 校正,注明); 效应量 epsilon² = H/(N−1)(= (ΣᵢRᵢ²/nᵢ − 3(N+1))/(N−1),N 为总样本量), 近似解释为"组间秩差异占总秩变异的比例"。 结论固定模板:p<α 拒绝 H0 / p≥α 不能拒绝;局限声明(非参检验功效通常低于 参数检验、ties 处理、样本量)。
边界: 样本不足(wilcoxon 有效对数 n<5;mann_whitney 每组 n<2;kruskal 组数 2~20 且每组 n>=2)、差值无变异/常量组、alpha/alternative 非法、NaN/Inf 防御—— 一律中文报错;无图。
示例: nonparametric_test("samples/clean.csv", test="mann_whitney", group_col="category", value_col="score") inline 数据: 本工具支持可选 inline_data 参数(v1.2.0 起):与 file_path 二选一, 支持 records 数组或 {"header": [...], "rows": [[...], ...]} 对象两种形态; 规模上限/类型域/data_source 来源标注见 statlab_mcp/docs/SPEC.md 第 12 节。
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| test | No | wilcoxon | |
| alpha | No | ||
| column | No | ||
| file_path | No | ||
| group_col | No | ||
| value_col | No | ||
| alternative | No | two_sided | |
| inline_data | No | ||
| sample2_col | No |