Inferential test selection and execution including t-test, ANOVA, chi-square, and non-parametric alternatives
Inferential Statistics
Complete protocol for selecting and executing hypothesis tests, including parametric and non-parametric tests, assumption checking, effect size calculation, and multiple comparison correction.
When to Use
When testing hypotheses about group differences or associations
When comparing treatment outcomes between groups
When determining if observed differences are statistically significant
After completing descriptive statistics (see descriptive-statistics skill)
Protocol
1. Test Selection Decision Tree
Continuous Outcome
Groups
Related?
Parametric
Non-Parametric
2
Independent
Independent t-test
Mann-Whitney U
2
Paired/matched
Paired t-test
Wilcoxon signed-rank
>2
Independent
One-way ANOVA
Kruskal-Wallis
>2
Repeated measures
Repeated measures ANOVA
Friedman test
Categorical Outcome
Expected counts
Groups
Test
All >= 5
2+
Chi-square test of independence
Any < 5, 2x2 table
2
Fisher's exact test
Any < 5, larger table
2+
Fisher-Freeman-Halton exact test
Paired/matched
2
McNemar's test
Correlation
Data type
Test
Both continuous, normal
Pearson correlation (r)
Ordinal or non-normal
Spearman rank correlation (rho)
Both ordinal, small n
Kendall's tau
2. Assumption Checking
2.1 Assumptions for Parametric Tests
Independent t-test and one-way ANOVA:
Independence -- observations are independent (study design)
Normality -- outcome variable is approximately normally distributed in each group
Homogeneity of variance -- equal variances across groups (Levene's test)
from scipy import stats
import pandas as pd
import numpy as np
# Example: comparing outcome between two groups
group1 = df[df['group'] == 'treatment']['outcome']
group2 = df[df['group'] == 'control']['outcome']
# Normality (per group)for name, data in [('Treatment', group1), ('Control', group2)]:
stat, p = stats.shapiro(data.dropna())
print(f"{name}: Shapiro-Wilk W={stat:.4f}, p={p:.4f}")
# Homogeneity of variance
stat, p = stats.levene(group1.dropna(), group2.dropna())
print(f"Levene's test: F={stat:.4f}, p={p:.4f}")
Decision rules:
If normality violated: use non-parametric alternative
If normality OK but variance unequal: use Welch's t-test (does not assume equal variances)
For ANOVA with unequal variances: use Welch's ANOVA or Games-Howell post-hoc
# Paired data (e.g., pre-post measurements)
t_stat, p_value = stats.ttest_rel(pre_scores, post_scores)
print(f"t = {t_stat:.3f}, p = {p_value:.4f}")
# Effect size: Cohen's d for paired data
diff = post_scores - pre_scores
d_paired = diff.mean() / diff.std()
print(f"Cohen's d (paired) = {d_paired:.3f}")
3.4 Wilcoxon Signed-Rank Test
# Non-parametric alternative to paired t-test
stat, p_value = stats.wilcoxon(pre_scores, post_scores)
print(f"W = {stat:.1f}, p = {p_value:.4f}")
# Effect size: r = Z / sqrt(N)
n = len(pre_scores)
z = stats.norm.ppf(p_value / 2)
r = abs(z) / np.sqrt(n)
print(f"Effect size r = {r:.3f}")
# For 2x2 tables with small expected counts
contingency_2x2 = pd.crosstab(df['exposure'], df['outcome'])
odds_ratio, p_value = stats.fisher_exact(contingency_2x2)
print(f"Odds Ratio = {odds_ratio:.3f}, p = {p_value:.4f}")
Independence of observations verified by study design
Sample size adequate for chosen test
Non-parametric alternative used when assumptions violated
Execution
Correct test applied with proper parameters
Two-tailed test used (unless one-tailed justified a priori)
Effect size calculated for each comparison
Confidence intervals computed
Multiple Comparisons
Family-wise error rate addressed if multiple tests performed
Correction method stated and justified
Corrected p-values reported alongside uncorrected
Reporting
Test statistic, df, and exact p-value reported
Effect size reported with interpretation
Group means/medians and SDs/IQRs reported
Sample sizes per group stated
Results narrative matches statistical output
References
Cohen J. Statistical Power Analysis for the Behavioral Sciences. 2nd ed. Lawrence Erlbaum Associates; 1988.
Field A. Discovering Statistics Using IBM SPSS Statistics. 5th ed. SAGE Publications; 2018.
Wasserstein RL, Lazar NA. The ASA Statement on p-Values: Context, Process, and Purpose. The American Statistician. 2016;70(2):129-133. doi:10.1080/00031305.2016.1154108
Benjamini Y, Hochberg Y. Controlling the False Discovery Rate: A Practical and Powerful Approach to Multiple Testing. JRSS-B. 1995;57(1):289-300.
Fritz CO, Morris PE, Richler JJ. Effect Size Estimates: Current Use, Calculations, and Interpretation. Journal of Experimental Psychology: General. 2012;141(1):2-18. doi:10.1037/a0024338