Explore the mathematical foundations of scientific inference: descriptive statistics, measures of central tendency and dispersion, frequency distributions, skewness and kurtosis, classical probability axioms, Normal and Binomial distributions, empirical sampling techniques, the Central Limit Theorem, confidence interval estimation, the hypothesis testing framework (p-values, alpha levels, Type I and II errors), parametric and non-parametric tests (T-Test, Chi-Square, ANOVA), correlation versus causation, and simple linear regression with Ordinary Least Squares.
Statistical analysis begins by distinguishing between a Population (the entire collection of all possible subjects or events under study) and a Sample (a representative subset drawn from that population). Characteristics describing a population are called parameters (conventionally denoted by Greek letters), whereas values computed from sample data are called statistics (denoted by Latin letters).
Measures of central tendency pinpoint the single representative value around which a numerical distribution clusters:
Centrality alone is incomplete; two distributions can have identical means of 100 while possessing vastly different risks or variabilities. Measures of dispersion quantify the extent to which data points scatter around the center:
| Metric | Mathematical Definition | Properties & Outlier Sensitivity |
|---|---|---|
| Range | Maximum value minus Minimum value. | Extremely fragile; entirely determined by the two most extreme values in the dataset. |
| Variance | The average of the squared deviations from the arithmetic mean. | Measured in squared units (e.g., dollars squared), making intuitive interpretation difficult. Uses N for populations and n - 1 (Bessel's correction) for samples to prevent underestimation of population variance. |
| Standard Deviation | The positive square root of the variance. | Expressed in the exact same physical units as the original data. Provides direct measurement of average deviation from the mean. |
| Interquartile Range (IQR) | 75th Percentile (Q3) minus 25th Percentile (Q1). | Measures the spread of the middle 50% of the distribution. Completely unaffected by extreme outliers. |
When computing variance from a sample, the sample data points are naturally closer to the sample mean than to the true, unknown population mean. Dividing by sample size n produces a mathematically biased estimate that systematically underestimates population spread. Dividing by degrees of freedom: n - 1 corrects for this bias, ensuring the sample variance is an unbiased estimator.
To understand the complete profile of numerical data, analysts construct Frequency Distributions by partitioning continuous data into non-overlapping intervals (bins) and plotting them as a Histogram. The shape of this histogram reveals two fundamental higher-order statistical moments: Skewness and Kurtosis.
POSITIVE (RIGHT) SKEW SYMMETRIC (NORMAL) NEGATIVE (LEFT) SKEW
(Long tail on the right) (Bell-shaped curve) (Long tail on the left)
^ ^ ^
/ \ / \ / \
/ \ / \ / \
/ \ / \ / \
/ \____ / \ ____/ \
----+-------------\---------> ---+---------\--------> --/-------------\-------->
Mode Med Mean Mean=Med=Mode Mean Med Mode
Condition: Mean > Median > Mode Condition: Mean = Median = Mode Condition: Mode > Median > Mean
Examples: Wealth, Startup Valuations Examples: Human Height, Errors Examples: Age at Death (Developed)
Skewness measures the degree of asymmetry of a probability distribution around its mean:
Mean > Median > Mode.Mode > Median > Mean.Kurtosis measures the "tailedness" of the probability distribution relative to a standard normal distribution. It quantifies how much of the distribution's variance is driven by rare, extreme outliers versus modest frequent deviations:
Probability provides the mathematical framework for quantifying uncertainty. Formally established by Andrey Kolmogorov, the probability of an event E satisfies three fundamental axioms:
0 ≤ P(E) ≤ 1.S equals certainty: P(S) = 1.
Models the number of successful outcomes k across a fixed number n of independent Bernoulli trials, where each trial has only two mutually exclusive outcomes (Success or Failure) with a constant probability of success p.
n × pn × p × (1 − p)The ubiquitous symmetric, bell-shaped distribution governed entirely by two parameters: the population mean and the population standard deviation.
Mean
|
+------+------+
/ | \
/ 68.27% of Data \ (Within +/- 1 Standard Deviation)
+-----+---------+---------+-----+
/ | | | \
/ 95.45% of Total Observations \ (Within +/- 2 Standard Deviations)
+-----+--------+---------+---------+--------+-----+
/ | | | | | \
/ 99.73% of All Physical Observations Fall Here \ (Within +/- 3 Standard Deviations)
-+--------+--------+---------+---------+--------+--------+--->
-3 SD -2 SD -1 SD Mean +1 SD +2 SD +3 SD
(Z=-3) (Z=-2) (Z=-1) (Z=0) (Z=+1) (Z=+2) (Z=+3)
Any normal variable can be transformed into the Standard Normal Distribution (having a mean of 0 and a standard deviation of 1) by calculating its Z-Score:
Z = (Observation - Population_Mean) / Standard_Deviation
A Z-score indicates precisely how many standard deviations an individual observation lies above or below the mean, allowing direct comparison of variables measured on completely different physical scales (e.g., comparing a student's SAT score against their high school GPA).
Gathering data on an entire population is frequently physically impossible or financially prohibitive. Consequently, data scientists extract representative samples using rigorous probability sampling techniques:
The Central Limit Theorem is the foundational pillar of inferential statistics. It states:
Regardless of the underlying distribution of the original population (whether it is uniform, skewed, bimodal, or exponential), the sampling distribution of the sample mean will approximate a normal bell-shaped distribution as the sample size n becomes sufficiently large (typically n ≥ 30).
The spread of this sampling distribution is quantified by the Standard Error of the Mean (SE):
Standard_Error = Population_Standard_Deviation / Square_Root(Sample_Size)
As sample size increases, standard error shrinks toward zero, meaning larger samples yield tighter, more accurate approximations of the true population parameter.
A point estimate (such as a single sample mean) is never perfectly accurate. A Confidence Interval constructs a plausible range of values likely to contain the true population parameter at a specified confidence level (commonly 95%):
Confidence_Interval = Sample_Mean +/- (Critical_Value * Standard_Error)
/* For a 95% Confidence Level under a normal curve, Critical_Value = 1.96 */
CI_95 = Sample_Mean +/- (1.96 * (Sample_SD / Square_Root(n)))
Correct Interpretation: If we were to draw 100 independent random samples and compute a 95% confidence interval for each, approximately 95 of those 100 calculated intervals would successfully bracket the true population mean.
Hypothesis testing is a formal mathematical procedure for determining whether an empirical observation in sample data reflects a genuine, statistically significant population effect or is merely a product of random sampling noise.
TRUE STATE OF THE POPULATION
H0 is ACTUALLY TRUE H0 is ACTUALLY FALSE
+------------------------------+------------------------------+
STATISTICAL Fail to | CORRECT DECISION | TYPE II ERROR |
DECISION Reject H0 | (Confidence: 1 - alpha) | (Beta: False Negative)|
+------------------------------+------------------------------+
Reject H0 | TYPE I ERROR | CORRECT DECISION |
| (Alpha: False Positive) | (Power: 1 - Beta) |
+------------------------------+------------------------------+
Analogy:
- Type I Error (Alpha): Convicting an innocent defendant in court (False Alarm).
- Type II Error (Beta): Acquitting a guilty criminal due to insufficient evidence (Missed Defect).
0.05 or 5%). It represents the threshold probability below which we consider an event too improbable under H0 to be explained by chance alone.p-value ≤ α: Reject H0 (The result is statistically significant).p-value > α: Fail to Reject H0 (Insufficient evidence to claim an effect).Selecting the appropriate statistical hypothesis test depends strictly on the number of groups compared and the measurement scales of the independent and dependent variables:
WHAT TYPE OF DATA ARE YOU COMPARING?
|
+-------------------------+-------------------------+
| |
v v
CATEGORICAL VARIABLES CONTINUOUS NUMERICAL VARIABLE
| |
[CHI-SQUARE TEST] HOW MANY GROUPS TO COMPARE?
- Goodness of Fit (1 Var) |
- Test of Independence (2 Vars) +-----------------+-----------------+
| |
v v
TWO GROUPS THREE OR MORE GROUPS
| |
[STUDENT'S T-TEST] [ONE-WAY ANOVA]
- Independent (2 diff groups) Evaluates F-statistic:
- Paired (Before/After same group) Between vs Within Var
Evaluates whether the difference between two sample means is statistically significant:
Evaluates discrete counts and categorical frequencies by comparing observed counts (O) against expected counts (E) derived under the null hypothesis of independence:
When comparing means across three or more groups (e.g., testing average sales performance across North, South, East, and West regional branches), performing repeated pairwise t-tests is unacceptable because it compounds the probability of a false positive (family-wise Type I error inflation).
ANOVA evaluates all groups simultaneously by computing the F-Statistic:
F = (Variance Between Groups) / (Variance Within Groups)
If the variance between the group averages is significantly larger than the random noise within the groups, the F-statistic yields a small p-value, prompting rejection of the null hypothesis that all group means are identical.
In bivariate and multivariate analysis, data scientists examine how two continuous variables behave in tandem:
-1.0 and +1.0:
r = +1.0: Perfect positive linear correlation.r = 0.0: Zero linear correlation.r = -1.0: Perfect negative linear correlation.Just because two variables demonstrate high mathematical correlation does not mean one causes the other. Spurious correlations frequently arise from:
While correlation merely evaluates the strength of an association, Linear Regression models the functional mathematical relationship to predict a dependent response variable y from an independent predictor variable x:
y = Intercept + (Slope * x) + Residual_Error
import numpy as np
from scipy import stats
# 1. Independent Two-Sample T-Test
group_control = [82, 85, 88, 79, 84, 86, 81]
group_treatment = [89, 92, 94, 88, 95, 91, 90]
t_stat, p_val_ttest = stats.ttest_ind(group_control, group_treatment)
print(f"T-Test: t-statistic = {t_stat:.3f}, p-value = {p_val_ttest:.5f}")
# 2. One-Way ANOVA across 3 Groups
g1 = [12, 14, 15, 13, 16]
g2 = [18, 20, 19, 21, 17]
g3 = [25, 24, 28, 26, 27]
f_stat, p_val_anova = stats.f_oneway(g1, g2, g3)
print(f"One-Way ANOVA: F = {f_stat:.3f}, p-value = {p_val_anova:.6f}")
# 3. Simple Linear Regression (OLS)
study_hours = [1, 2, 3, 4, 5, 6, 7, 8]
exam_scores = [52, 58, 65, 70, 78, 82, 88, 95]
reg = stats.linregress(study_hours, exam_scores)
print(f"Regression: y = {reg.intercept:.2f} + {reg.slope:.2f}*x | R-squared = {reg.rvalue**2:.3f}")