| name | statistical-analyzer |
| description | Perform statistical hypothesis testing, regression analysis, ANOVA, and t-tests with plain-English interpretations and visualizations. |
Statistical Analyzer
Guided statistical analysis with hypothesis testing, regression, ANOVA, and plain-English results.
Features
- Hypothesis Testing: t-tests, chi-square, proportion tests
- Regression Analysis: Linear, polynomial, multiple regression
- ANOVA: One-way, two-way ANOVA with post-hoc tests
- Distribution Analysis: Normality tests, Q-Q plots
- Correlation Analysis: Pearson, Spearman with significance
- Plain-English Results: Interpret statistical outputs
- Visualizations: Regression plots, residual analysis, box plots
- Report Generation: PDF/HTML reports with interpretations
Quick Start
from statistical_analyzer import StatisticalAnalyzer
analyzer = StatisticalAnalyzer()
analyzer.load_data(df, group_col='treatment', value_col='score')
results = analyzer.t_test(group1='control', group2='experimental')
print(results['interpretation'])
analyzer.load_data(df)
results = analyzer.linear_regression(x='age', y='income')
print(f"R²: {results['r_squared']}")
analyzer.plot_regression('regression.png')
CLI Usage
python statistical_analyzer.py --data data.csv --test t-test --group treatment --value score --output results.html
python statistical_analyzer.py --data data.csv --test anova --group category --value score --output results.pdf
python statistical_analyzer.py --data data.csv --test regression --x age --y income --output report.pdf
python statistical_analyzer.py --data data.csv --test correlation --output correlation.png
API Reference
StatisticalAnalyzer Class
class StatisticalAnalyzer:
def __init__(self)
def load_data(self, data, **kwargs) -> 'StatisticalAnalyzer'
def load_csv(self, filepath, **kwargs) -> 'StatisticalAnalyzer'
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
def linear_regression(self, x, y) -> Dict
def polynomial_regression(self, x, y, degree=2) -> Dict
def () ->
() -> pd.DataFrame
() ->
() ->
() ->
() ->
() ->
() ->
() ->
() ->
() ->
Tests
T-Test
Compare means between two groups:
analyzer.load_csv('data.csv')
results = analyzer.t_test(
group1='control',
group2='treatment',
paired=False
)
print(results)
results = analyzer.t_test(
group1='before',
group2='after',
paired=True
)
ANOVA
Compare means across multiple groups:
results = analyzer.anova(
groups=['control', 'treatment_a', 'treatment_b'],
value_col='score'
)
print(results['interpretation'])
Regression Analysis
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}")
results = analyzer.polynomial_regression(x='age', y='salary', degree=2)
results = analyzer.multiple_regression(
predictors=['age', 'experience', 'education'],
target='salary'
)
Correlation Analysis
corr_matrix = analyzer.correlation(method='pearson')
print(corr_matrix)
results = analyzer.correlation_test('height', 'weight', method='pearson')
print(results['interpretation'])
Distribution Tests
results = analyzer.normality_test('scores', method='shapiro')
analyzer.qq_plot('scores', output='qq_plot.png')
Interpretation Guide
The analyzer provides plain-English interpretations:
Significance Levels
- p < 0.001: "Highly significant"
- p < 0.01: "Very significant"
- p < 0.05: "Statistically significant"
- p ≥ 0.05: "Not statistically significant"
Effect Sizes
- Cohen's d: Small (0.2), Medium (0.5), Large (0.8)
- R²: Weak (<0.3), Moderate (0.3-0.7), Strong (>0.7)
- Correlation: Weak (<0.3), Moderate (0.3-0.7), Strong (>0.7)
Visualizations
Regression Plot
analyzer.linear_regression(x='age', y='income')
analyzer.plot_regression('regression.png')
Residual Plot
analyzer.plot_residuals('residuals.png')
Box Plot
analyzer.plot_boxplot(
groups=['control', 'treatment_a', 'treatment_b'],
value_col='score',
output='boxplot.png'
)
Distribution Plot
analyzer.plot_distribution('scores', 'distribution.png')
Reports
Generate comprehensive reports:
analyzer.load_csv('data.csv')
analyzer.t_test(group1='control', group2='treatment')
analyzer.linear_regression(x='hours', y='score')
analyzer.generate_report('analysis_report.pdf', format='pdf')
analyzer.generate_report('analysis_report.html', format='html')
Reports include:
- Summary statistics
- Test results with interpretations
- Visualizations
- Assumptions checks
- Recommendations
Assumptions Checking
Automatic assumptions validation:
Dependencies
- 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