hypothesis_test
Perform one-sample, independent, and paired t-tests with Shapiro normality pre-checks, confidence intervals, and Cohen's d to determine whether observed differences are statistically significant.
Instructions
hypothesis_test —— 统计推断组 · 假设检验(工具 6,核心实现)。
docstring = agent 使用说明书,与 statlab_mcp/docs/design/03_inference_batch1.md 同步维护。
参数: file_path (str): 本地数据文件(csv/tsv/xlsx/json) column (str): 分析列(须为数值列) test (str, "one_sample"): one_sample / independent / paired group_col (str|None): test=independent 时必填,须恰好 2 组且每组 n>=2 sample2_col (str|None): test=paired 时必填(与 column 成对对齐) mu0 (float, 0.0): one_sample 的 H0 假设均值 alternative (str, "two_sided"): two_sided / less / greater alpha (float, 0.05): 显著性水平 ∈ (0,1)
方法(设计文档口径): one_sample -> scipy.stats.ttest_1samp;independent -> ttest_ind(equal_var=False) (Welch's t,规格硬性规定,df 用 Welch-Satterthwaite 公式手算,跨版本稳定); paired -> ttest_rel(差值 = column - sample2_col,成正态预检对象)。 检验前 Shapiro 预检(3<=n<=5000):违反只警示不阻断,可转用 nonparametric_test (Wilcoxon/Mann-Whitney)。 CI 一律双侧(1-alpha,t 分布);效应量 Cohen's d(单样本|mean-mu0|/sd、 独立 pooled sd、配对差值 sd)。结论文案固定模板 p<alpha 拒绝 H0 / p>=alpha 不能拒绝。
示例: hypothesis_test("samples/clean.csv", column="score", test="one_sample", mu0=70.0) hypothesis_test("samples/clean.csv", column="score", test="independent", group_col="category") 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 |
|---|---|---|---|
| mu0 | No | ||
| test | No | one_sample | |
| alpha | No | ||
| column | No | ||
| file_path | No | ||
| group_col | No | ||
| alternative | No | two_sided | |
| inline_data | No | ||
| sample2_col | No |