feat: statistical analysis
- Dominant language
- No language data
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
**BEFORE**:
```python
@hypothesis_test(alpha=0.05)
def compare_groups(control: Series, treatment: Series):
return control ~ treatment # Syntax for statistical comparison
```
**AFTER**:
```python
# After (transpiled.py):
from scipy import stats
from dataclasses import dataclass
from typing import Optional, Tuple, Literal
import numpy as np
import pandas as pd
@dataclass
class TestResults:
statistic: float
pvalue: float
significant: bool
test_type: str
effect_size: float
confidence_interval: Tuple[float, float]
def __str__(self):
sig = "significant" if self.significant else "not significant"
return (f"{self.test_type}: {sig} (p={self.pvalue:.3f})\n"
f"Effect size: {self.effect_size:.3f}\n"
f"95% CI: [{self.confidence_interval[0]:.3f}, {self.confidence_interval[1]:.3f}]")
def compare_groups(control: pd.Series, treatment: pd.Series) -> TestResults:
# Automatically choose appropriate test based on data
if _is_normal(control) and _is_normal(treatment):
stat, p = stats.ttest_ind(control, treatment)
test_type = "Student's t-test"
# Cohen's d for effect size
effect_size = (treatment.mean() - control.mean()) / np.sqrt(
((control.std() ** 2 + treatment.std() ** 2) / 2)
)
else:
stat, p = stats.mannwhitneyu(control, treatment)
test_type = "Mann-Whitney U test"
# Rank-biserial correlation for effect size
effect_size = 2 * (stats.rankdata(treatment).mean() -
stats.rankdata(control).mean()) / len(control)
# Calculate confidence interval
ci = _bootstrap_ci(treatment - control)
return TestResults(
statistic=stat,
pvalue=p,
significant=p < 0.05,
test_type=test_type,
effect_size=effect_size,
confidence_interval=ci
)
def _is_normal(data: pd.Series, alpha: float = 0.05) -> bool:
# Shapiro-Wilk test for normality
_, p = stats.shapiro(data)
return p > alpha
def _bootstrap_ci(diff: pd.Series,
n_bootstrap: int = 10000,
ci: float = 0.95) -> Tuple[float, float]:
resamples = np.random.choice(
diff,
size=(n_bootstrap, len(diff)),
replace=True
)
means = resamples.mean(axis=1)
return np.percentile(means, [(1-ci)*100/2, (1+ci)*100/2])
```
The ~ operator gets transformed into a sophisticated statistical comparison that:
- Checks assumptions
- Chooses appropriate tests
- Calculates effect sizes
- Provides confidence intervals
- Returns a rich results object
Contributor guide
No contributing guide indexed for this repository
Research direction
No source file or test is named. Start by locating the transpilation entry point for the `~` operator and compare it with the proposed `compare_groups` behavior. Done means the operator produces the stated statistical results, including test selection, effect size, confidence interval, and result formatting.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- numpy, pandas, python
- Domain
- data
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100