mcpField
S
statistical-analyzer

statistical-analyzer

github.com/dkyazzentwatwa数据与数据库12458 次安装29 周前更新
代码仓库

关于 statistical-analyzer

statistical-analyzer 是用于数据集统计分析的 Python 和命令行工具,涵盖常见检验与回归。它会检查假设,并生成通俗易懂的解释、可视化及 PDF 或 HTML 报告。

主要功能

  1. 01假设检验、回归和 ANOVA
  2. 02相关性与分布分析
  3. 03通俗易懂的结果解释
  4. 04假设检查及警告
  5. 05统计图表与可视化
  6. 06生成 PDF 和 HTML 报告

适用场景

  1. 01使用 t 检验或 ANOVA 比较处理组
  2. 02通过回归或相关分析研究关系
  3. 03检查分布并验证检验假设
  4. 04生成包含结果和图表的报告

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/dkyazzentwatwa/chatgpt-skills --skill statistical-analyzer

安装后在 Claude Code 中输入/statistical-analyzer确认已加载。

附带文件scripts/requirements.txtscripts/statistical_analyzer.py

详细介绍

统计分析器

通过假设检验、回归、ANOVA 和通俗易懂的结果解读,指导统计分析。

功能

  • 假设检验:t 检验、卡方检验、比例检验
  • 回归分析:线性回归、多项式回归、多元回归
  • ANOVA:单因素、双因素 ANOVA,支持事后检验
  • 分布分析:正态性检验、Q-Q 图
  • 相关性分析:Pearson、Spearman 相关分析,并提供显著性检验
  • 通俗易懂的结果:解读统计输出
  • 可视化:回归图、残差分析、箱线图
  • 报告生成:生成包含解读的 PDF/HTML 报告

快速开始

from statistical_analyzer import StatisticalAnalyzer

analyzer = StatisticalAnalyzer()

# T-test
analyzer.load_data(df, group_col='treatment', value_col='score')
results = analyzer.t_test(group1='control', group2='experimental')
print(results['interpretation'])

# Regression
analyzer.load_data(df)
results = analyzer.linear_regression(x='age', y='income')
print(f"R²: {results['r_squared']}")
analyzer.plot_regression('regression.png')

CLI 用法

# T-test
python statistical_analyzer.py --data data.csv --test t-test --group treatment --value score --output results.html

# ANOVA
python statistical_analyzer.py --data data.csv --test anova --group category --value score --output results.pdf

# Regression
python statistical_analyzer.py --data data.csv --test regression --x age --y income --output report.pdf

# Correlation matrix
python statistical_analyzer.py --data data.csv --test correlation --output correlation.png

API 参考

StatisticalAnalyzer 类
class StatisticalAnalyzer:
    def __init__(self)

    # Data Loading
    def load_data(self, data, **kwargs) -> 'StatisticalAnalyzer'
    def load_csv(self, filepath, **kwargs) -> 'StatisticalAnalyzer'

    # Hypothesis Tests
    def t_test(self, group1, group2, paired=False, alternative='two-sided') -> Dict
    def one_sample_t_test(self, column, expected_mean, alternative='two-sided') -> Dict
    def anova(self, groups, value_col) -> Dict
    def chi_square(self, observed, expected=None) -> Dict
    def proportion_test(self, successes, total, expected_prop=0.5) -> Dict

    # Regression
    def linear_regression(self, x, y) -> Dict
    def polynomial_regression(self, x, y, degree=2) -> Dict
    def multiple_regression(self, predictors: List[str], target: str) -> Dict

    # Correlation
    def correlation(self, method='pearson') -> pd.DataFrame  # Correlation matrix
    def correlation_test(self, var1, var2, method='pearson') -> Dict

    # Distribution Tests
    def normality_test(self, column, method='shapiro') -> Dict
    def qq_plot(self, column, output=None) -> str

    # Visualization
    def plot_regression(self, output, x=None, y=None) -> str
    def plot_residuals(self, output) -> str
    def plot_distribution(self, column, output) -> str
    def plot_boxplot(self, groups, value_col, output) -> str

    # Reporting
    def generate_report(self, output, format='pdf') -> str
    def summary(self) -> str

检验

T 检验

比较两组的均值:

analyzer.load_csv('data.csv')

# Independent samples
results = analyzer.t_test(
    group1='control',
    group2='treatment',
    paired=False
)

# Results
print(results)
# {
#     'statistic': -2.45,
#     'p_value': 0.018,
#     'mean_diff': -5.2,
#     'ci': (-9.5, -0.9),
#     'interpretation': 'The difference is statistically significant (p=0.018)...'
# }

# Paired samples (before/after)
results = analyzer.t_test(
    group1='before',
    group2='after',
    paired=True
)
ANOVA

比较多个组的均值:

results = analyzer.anova(
    groups=['control', 'treatment_a', 'treatment_b'],
    value_col='score'
)

# Results include post-hoc tests
print(results['interpretation'])
# "There is a statistically significant difference between groups (p<0.001).
#  Post-hoc tests show treatment_a differs from control (p=0.003)..."
回归分析
# Simple linear regression
results = analyzer.linear_regression(x='hours_studied', y='exam_score')

print(f"R² = {results['r_squared']:.3f}")
print(f"Equation: y = {results['slope']:.2f}x + {results['intercept']:.2f}")
print(f"p-value: {results['p_value']:.4f}")

# Polynomial regression
results = analyzer.polynomial_regression(x='age', y='salary', degree=2)

# Multiple regression
results = analyzer.multiple_regression(
    predictors=['age', 'experience', 'education'],
    target='salary'
)
相关性分析
# Full correlation matrix
corr_matrix = analyzer.correlation(method='pearson')
print(corr_matrix)

# Test specific correlation
results = analyzer.correlation_test('height', 'weight', method='pearson')
print(results['interpretation'])
# "There is a strong positive correlation (r=0.82, p<0.001)"
分布检验
# Test normality
results = analyzer.normality_test('scores', method='shapiro')
# Returns: {'statistic': 0.98, 'p_value': 0.35,
#           'interpretation': 'Data appears normally distributed (p=0.35)'}

# Q-Q plot
analyzer.qq_plot('scores', output='qq_plot.png')

解读指南

分析器会提供通俗易懂的解读:

显著性水平
  • p < 0.001:「极显著」
  • p < 0.01:「非常显著」
  • p < 0.05:「具有统计显著性」
  • p ≥ 0.05:「不具有统计显著性」
效应量
  • Cohen's d:小(0.2)、中(0.5)、大(0.8)
  • R²:弱(<0.3)、中等(0.3-0.7)、强(>0.7)
  • 相关性:弱(<0.3)、中等(0.3-0.7)、强(>0.7)

可视化

回归图
analyzer.linear_regression(x='age', y='income')
analyzer.plot_regression('regression.png')
# Creates scatter plot with regression line and confidence interval
残差图
analyzer.plot_residuals('residuals.png')
# Checks regression assumptions (homoscedasticity)
箱线图
analyzer.plot_boxplot(
    groups=['control', 'treatment_a', 'treatment_b'],
    value_col='score',
    output='boxplot.png'
)
分布图
analyzer.plot_distribution('scores', 'distribution.png')
# Histogram with normal curve overlay

报告

生成全面的报告:

analyzer.load_csv('data.csv')
analyzer.t_test(group1='control', group2='treatment')
analyzer.linear_regression(x='hours', y='score')

# PDF report with all analyses
analyzer.generate_report('analysis_report.pdf', format='pdf')

# HTML report
analyzer.generate_report('analysis_report.html', format='html')

报告包括:

  • 汇总统计
  • 附带解读的检验结果
  • 可视化
  • 假设检查
  • 建议

假设检查

自动验证假设:

# T-test checks:
# - Normality (Shapiro-Wilk)
# - Equal variances (Levene's test)
# Warnings if assumptions violated

# ANOVA checks:
# - Normality per group
# - Homogeneity of variances
# Suggests non-parametric alternatives

# Regression checks:
# - Linearity
# - Homoscedasticity
# - Normality of residuals
# - Independence (Durbin-Watson)

依赖项

  • scipy>=1.10.0
  • statsmodels>=0.14.0
  • pandas>=2.0.0
  • numpy>=1.24.0
  • matplotlib>=3.7.0
  • seaborn>=0.12.0
  • reportlab>=4.0.0

评论

支持 Markdown