Skip to main content
Glama

chi_square_test

Test independence of two categorical variables using chi-square, with automatic numeric binning, Fisher exact correction for small samples, and Cramér's V effect size.

Instructions

chi_square_test —— 统计推断组 · 卡方独立性检验(工具 8,核心实现)。

docstring = agent 使用说明书,与 statlab_mcp/docs/design/04_inference_batch2.md 同步维护。

参数: file_path (str): 本地数据文件(csv/tsv/xlsx/json) col_a / col_b (str): 两列类别变量(均须存在;数值列自动等宽分箱 ≤8 箱并注明)

流程(确定性): 1. 分类化:数值列 pd.cut 等宽分箱(箱数=min(8, max(2, 唯一值数)))并注明; 类别唯一值 =1 -> error;>50 -> error(防列联表爆炸) 2. pd.crosstab 列联表;scipy.stats.chi2_contingency(含期望频数表) 3. >20% 单元格期望频数 <5:2x2 -> scipy.stats.fisher_exact(statistic=OR、df=null); 非 2x2 -> 中文报错引导合并类别 4. 效应量 Cramér's V = sqrt(chi2/(n*(min(rows,cols)-1)))(chi2 来自 chi2_contingency, fisher 路径同样给出并注明基于卡方近似) 5. 结论固定模板;summary 注明"关联≠因果"

示例: chi_square_test("samples/clean.csv", col_a="category", col_b="category") inline 数据: 本工具支持可选 inline_data 参数(v1.2.0 起):与 file_path 二选一, 支持 records 数组或 {"header": [...], "rows": [[...], ...]} 对象两种形态; 规模上限/类型域/data_source 来源标注见 statlab_mcp/docs/SPEC.md 第 12 节。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
col_aNo
col_bNo
file_pathNo
inline_dataNo

Schema Changelog

Changes observed during successful MCP inspections. Dates show when Glama detected each change.

  1. First observedv1.2.0

TDQS

A4.5/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries the full behavioral burden and exceeds it: deterministic pipeline, binning rule, error conditions for unique values, Fisher exact fallback with OR/df=null, Cramér's V formula, expected-frequency caveat, and the 'association ≠ causation' warning. An agent can predict side effects and failure modes.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Purpose, parameters, deterministic flow, example, and inline-data note are laid out in a logical, front-loaded order with negligible redundancy. The only nonoperational sentence is the docstring-synchronization maintenance note, preventing a perfect 5.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no annotations and no output schema, the description covers input constraints, preprocessing, test selection, effect size, edge-case errors, conclusion template, and caveats. It even names the statistics an agent can expect in the result (chi2, expected frequencies, OR, df, Cramér's V).

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0% and has four nullable params with no descriptions. The tool description documents file formats for file_path, the mutual exclusivity and two accepted shapes of inline_data, and the required existence plus auto-binning behavior for col_a/col_b. This is exactly the operational semantics the schema lacks.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description names a specific statistical operation ('卡方独立性检验') and a specific resource (association between two categorical columns), immediately distinguishing it from generic inference siblings. The example call and the '两列类别变量' requirement make the scope unambiguous.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It gives clear input context: two categorical columns are needed, numeric columns get auto-binned, and file_path/inline_data are mutually exclusive. However, it never explicitly says when to prefer this tool over siblings such as nonparametric_test or correlation_matrix, so alternative routing is left to inference.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/good-boy4069/statlab-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server