data scienceadvanced980 tokens
Statistical Hypothesis Testing
Design and interpret rigorous statistical hypothesis tests
hypothesis-testingstatisticsscipypythoninferencep-value
Prompt Template
You are a statistician designing and interpreting hypothesis tests. Help me test the following hypothesis rigorously.
**Research Question:**
{research_question}
**Data:**
```
{data_description}
```
**Context:**
{context}
Design and execute a proper hypothesis test:
**1. Formulate Hypotheses:**
- **Null Hypothesis (H₀):** [Statement of no effect/difference]
- **Alternative Hypothesis (H₁):** [What you're trying to prove]
- **Type:** One-tailed or two-tailed? Why?
- **Significance Level (α):** [Usually 0.05, justify if different]
**2. Choose Appropriate Test:**
Decision tree:
- **Comparing Means:**
- 2 groups, normal → t-test (independent or paired)
- 3+ groups, normal → ANOVA
- Non-normal → Mann-Whitney U or Kruskal-Wallis
- **Comparing Proportions:**
- 2 proportions → Two-proportion z-test
- Multiple → Chi-square test
- **Correlation:**
- Normal → Pearson correlation
- Non-normal → Spearman correlation
- **Time Series:**
- Stationarity → Augmented Dickey-Fuller
- Seasonality → Seasonal decomposition
Selected Test: [Name]
Rationale: [Why this test is appropriate]
**3. Check Assumptions:**
For the chosen test, verify:
- **Normality:** Shapiro-Wilk test, Q-Q plot
- **Independence:** Sample design, autocorrelation check
- **Homogeneity of Variance:** Levene's test, Bartlett's test
- **Sample Size:** Power analysis, rule of thumb
- **Other:** [Test-specific assumptions]
If assumptions violated:
- Transform data (log, sqrt, Box-Cox)
- Use non-parametric alternative
- Use robust methods
- Bootstrap confidence intervals
**4. Calculate Test Statistic:**
```python
import pandas as pd
import numpy as np
from scipy import stats
import matplotlib.pyplot as plt
# Load data
{data_loading_code}
# Check assumptions
# 1. Normality test
stat, p_value = stats.shapiro(data)
print(f"Shapiro-Wilk: statistic={stat:.4f}, p-value={p_value:.4f}")
# 2. Visualize assumptions
# [Q-Q plot, histogram, etc.]
# Perform hypothesis test
test_stat, p_value = stats.{test_function}(group1, group2)
print(f"Test Statistic: {test_stat:.4f}")
print(f"P-value: {p_value:.4f}")
# Calculate effect size
effect_size = {effect_size_formula}
print(f"Effect Size: {effect_size:.4f}")
# Confidence interval
ci = stats.{confidence_interval_function}(data, confidence=0.95)
print(f"95% CI: {ci}")
```
**5. Interpret Results:**
**Statistical Conclusion:**
- **Test Statistic:** [value]
- **P-value:** [value]
- **Decision:** Reject H₀ or Fail to reject H₀
- **At significance level α = {alpha}:**
- If p < α: Reject H₀, statistically significant
- If p ≥ α: Fail to reject H₀, not statistically significant
**Effect Size:**
- **Measure:** [Cohen's d, r, η², odds ratio]
- **Value:** [number]
- **Interpretation:** [small/medium/large effect]
- **Practical Significance:** [Does the effect size matter in practice?]
**Confidence Interval:**
- **95% CI:** [lower, upper]
- **Interpretation:** We are 95% confident the true [parameter] lies in this range
**6. Statistical Power:**
- **Power Achieved:** [1 - β]
- **Minimum Detectable Effect:** [What effect size could we detect?]
- **Sample Size Recommendation:** [If underpowered, how many more samples needed?]
**7. Practical Interpretation:**
Translate to plain language:
- **What we found:** [Non-technical explanation]
- **Confidence level:** [How sure are we?]
- **Real-world meaning:** [Business/scientific impact]
- **Limitations:** [What this test doesn't tell us]
**8. Potential Issues:**
- **Type I Error:** False positive risk = α = {alpha}
- **Type II Error:** False negative risk = β = [calculate]
- **Multiple Comparisons:** [Bonferroni correction if applicable]
- **Confounding Variables:** [What else might explain the result?]
- **External Validity:** [Can we generalize these findings?]
**9. Visualizations:**
Create:
- Distribution plots for each group
- Box plots comparing groups
- Effect size visualization
- Confidence interval plot
**10. Reporting Template:**
"We conducted a {test_name} to examine {research_question}. The test revealed {statistically significant / no statistically significant} difference (test_statistic = {value}, p = {p_value}). The effect size was {small/medium/large} ({effect_measure} = {value}). We can conclude with {confidence}% confidence that {practical_interpretation}."
**11. Next Steps:**
- If significant: Replication study, mechanism investigation
- If not significant: Power analysis, larger sample, different approach
- Further analyses: Subgroup analysis, regression, causal inference
Provide complete, reproducible code with detailed interpretation.Variables to Replace
{research_question}{data_description}{context}{alpha}{data_loading_code}{test_function}{effect_size_formula}{confidence_interval_function}{test_name}{value}{p_value}{effect_measure}{confidence}{practical_interpretation}Pro Tips
Always check assumptions before running tests. Report effect sizes, not just p-values. Statistical significance ≠ practical significance.
Related Prompts
Need More Prompts?
Explore our full library of 60+ professional AI prompt templates
Browse All Prompts →