🎩 You're Invited:Meet the Socket team at Black Hat in Las Vegas, August 3-6.RSVP
Sign In

crosstabs

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

crosstabs

MCP server for statistical crosstabulation analysis with 40+ tools

pipPyPI
Version
1.0.3
Weekly downloads
113
Maintainers
1
Created

Crosstabs MCP Server

Python 3.10+ License: MIT MCP

A Python MCP (Model Context Protocol) server providing 40+ statistical tools for contingency table analysis. Designed for AI assistants like Claude to perform rigorous statistical analysis.

Features

Core Statistical Tests

TestDescription
Chi-squarePearson's chi-square test of independence
G-testLikelihood ratio test (more accurate for small samples)
Fisher's exactExact test for 2×2 tables
McNemar'sTest for paired categorical data

Effect Sizes & Measures

MeasureUse Case
Cramér's VEffect size for any table size (with bias correction)
Phi coefficientEffect size for 2×2 tables
Odds ratioAssociation strength with confidence intervals
Relative riskRisk comparison between groups
Risk differenceAbsolute risk reduction
Attributable riskPopulation-level impact

Ordinal Measures

MeasureDescription
Spearman's rhoRank correlation
Kendall's tauConcordance measure
Goodman-Kruskal gammaOrdinal association
Somers' DAsymmetric ordinal measure
Stuart's tau-cRectangular table measure

Agreement & Reliability

MeasureDescription
Cohen's kappaInter-rater agreement
Weighted kappaAgreement with ordinal weights

Advanced Analysis

ToolDescription
CMH testStratified analysis controlling confounders
Breslow-DayTest homogeneity of odds ratios
Correspondence analysisDimensionality reduction for tables
Monte Carlo chi-squareExact p-values via simulation
Power analysisSample size and power calculations
Multiple comparisonsBonferroni and FDR corrections

Installation

pip install crosstabs

From source

git clone https://github.com/barangaroo/crosstabs-lite.git
cd crosstabs-lite/mcp-server-python
pip install -e .

Quick Start

Run the MCP Server

crosstabs

Or directly:

python -m crosstabs_mcp.server

Configure Claude Code

Add to your ~/.claude/claude_desktop_config.json:

{
  "mcpServers": {
    "crosstabs": {
      "command": "crosstabs"
    }
  }
}

Or with Python path:

{
  "mcpServers": {
    "crosstabs": {
      "command": "python",
      "args": ["-m", "crosstabs_mcp.server"]
    }
  }
}

Usage Examples

Once configured, Claude can perform statistical analysis:

Chi-square Test

User: Test if there's an association between treatment and outcome:
      Treatment A: 50 success, 30 failure
      Treatment B: 20 success, 40 failure

Claude: [Uses chi_square_test with matrix [[50,30],[20,40]]]
        χ² = 11.67, p = 0.0006
        Cramér's V = 0.29 (small-medium effect)
        There is a significant association between treatment and outcome.

Odds Ratio

User: Calculate the odds ratio for this case-control study:
      Cases: 30 exposed, 70 unexposed
      Controls: 15 exposed, 85 unexposed

Claude: [Uses odds_ratio with matrix [[30,70],[15,85]]]
        OR = 2.43 (95% CI: 1.21-4.87)
        Exposure is associated with 143% higher odds of the outcome.

Fisher's Exact Test

User: I have a small sample: [[3,1],[1,5]]. Is it significant?

Claude: [Uses fishers_exact with the matrix]
        p = 0.103 (two-tailed)
        Not statistically significant at α=0.05.

Available Tools

Tool NameDescription
chi_square_testChi-square test of independence
g_testG-test (likelihood ratio)
fishers_exactFisher's exact test (2×2)
mcnemar_testMcNemar's test for paired data
odds_ratioOdds ratio with CI
relative_riskRelative risk with CI
risk_differenceRisk difference with CI
cramers_vCramér's V effect size
cramers_v_correctedBias-corrected Cramér's V
phi_coefficientPhi for 2×2 tables
cohens_kappaCohen's kappa
weighted_kappaWeighted kappa
spearmans_rhoSpearman's rank correlation
kendalls_tauKendall's tau-b
goodman_kruskal_gammaGamma coefficient
somers_dSomers' D
tau_cStuart's tau-c
cmh_testCochran-Mantel-Haenszel
breslow_dayBreslow-Day test
linear_trend_testLinear-by-linear association
correspondence_analysisCorrespondence analysis
monte_carlo_chi_squareMonte Carlo exact test
power_analysisPower/sample size
bonferroni_correctionBonferroni p-value adjustment
fdr_correctionBenjamini-Hochberg FDR
standardized_residualsCell residuals
post_hoc_analysisPost-hoc chi-square decomposition
proportion_ciConfidence interval for proportion
check_assumptionsValidate chi-square assumptions
mosaic_plot_dataData for mosaic visualization
stacked_bar_dataData for stacked bar chart
attributable_riskAttributable risk measures
chi_square_yatesYates' continuity correction
detect_outliersOutlier detection
crosstab_from_dataBuild table from raw data
crosstab_from_csvBuild table from CSV

Development

Run Tests

pip install -e ".[dev]"
pytest tests/ -v

Project Structure

mcp-server-python/
├── crosstabs_mcp/
│   ├── __init__.py
│   ├── server.py          # Main MCP server
│   └── advanced_stats.py  # Additional functions
├── tests/
│   └── test_statistics.py # Test suite (52 tests)
├── pyproject.toml
├── requirements.txt
└── README.md

Requirements

  • Python 3.10+
  • mcp >= 1.0.0
  • fastmcp >= 0.1.0
  • numpy >= 1.24.0
  • scipy >= 1.10.0
  • pandas >= 2.0.0
  • statsmodels >= 0.14.0

License

MIT License - see LICENSE for details.

Contributing

Contributions welcome! Please read CONTRIBUTING.md first.

Keywords

chi-square

FAQs

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts