Unit 5: Statistics and Probability

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.

Section 01

Descriptive Statistics: Centrality & Dispersion

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

Measures of central tendency pinpoint the single representative value around which a numerical distribution clusters:

Measures of Dispersion (Spread)

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.

Why Bessel's Correction (n - 1) Matters

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.

Section 02

Distribution Shape: Histograms, Skew & Kurtosis

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.

Distribution Skewness & Measures of Central Tendency
   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 (The Third Moment: Asymmetry)

Skewness measures the degree of asymmetry of a probability distribution around its mean:

Kurtosis (The Fourth Moment: Tail Weight & Outliers)

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:

Section 03

Probability Foundations & Core Distributions

Probability provides the mathematical framework for quantifying uncertainty. Formally established by Andrey Kolmogorov, the probability of an event E satisfies three fundamental axioms:

  1. The probability of any event is non-negative and bounded: 0 ≤ P(E) ≤ 1.
  2. The probability of the entire sample space S equals certainty: P(S) = 1.
  3. For any mutually exclusive events, the probability of their union is the sum of their individual probabilities.

1. The Binomial Distribution (Discrete)

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.

2. The Normal (Gaussian) Distribution (Continuous)

The ubiquitous symmetric, bell-shaped distribution governed entirely by two parameters: the population mean and the population standard deviation.

The Empirical Rule (68-95-99.7%) for Normal Distributions
                           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)
        

Standard Normal Distribution & Z-Scores

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:

Formula Definition Z-Score Standardization
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).

Section 04

Sampling Methodologies & The Central Limit Theorem

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 (CLT)

The Central Limit Theorem is the foundational pillar of inferential statistics. It states:

The Central Limit Theorem Principle

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):

Formula Definition Standard Error of the Mean
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.

Confidence Intervals (CI)

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%):

Formula Definition 95% Confidence Interval for the Mean
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.

Section 05

The Hypothesis Testing Framework

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.

1. Formulating Null and Alternative Hypotheses

2. The Decision Matrix: Type I vs. Type II Errors

Statistical Decision Matrix & Error Taxonomy
                                        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).
        

3. The p-Value & Significance Level (Alpha)

Section 06

Inferential Statistical Tests: T-Test, Chi-Square & ANOVA

Selecting the appropriate statistical hypothesis test depends strictly on the number of groups compared and the measurement scales of the independent and dependent variables:

Statistical Test Selection Decision Tree
                           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
        

1. Student's T-Test

Evaluates whether the difference between two sample means is statistically significant:

2. Chi-Square Test (Χ2)

Evaluates discrete counts and categorical frequencies by comparing observed counts (O) against expected counts (E) derived under the null hypothesis of independence:

3. One-Way ANOVA (Analysis of Variance)

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:

Formula Definition ANOVA F-Statistic Ratio
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.

Section 07

Correlation, Covariance & Linear Regression

In bivariate and multivariate analysis, data scientists examine how two continuous variables behave in tandem:

Covariance vs. Pearson Correlation Coefficient

Correlation Does NOT Imply Causation

Just because two variables demonstrate high mathematical correlation does not mean one causes the other. Spurious correlations frequently arise from:

  1. Confounding (Lurking) Variables: Ice cream sales and drowning incidents correlate strongly because both are independently caused by hot summer weather.
  2. Reverse Causality: A correlation between exercise and low depression might mean exercise alleviates depression, or that depression diminishes energy to exercise.

Simple Linear Regression Basics

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:

Mathematical Equation Simple Linear Regression Equation
y = Intercept + (Slope * x) + Residual_Error
Python Hypothesis Testing, ANOVA & Regression in Python (scipy.stats & statsmodels)
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}")

Unit Summary & Key Takeaways

  • Central tendency is measured by Mean, Median (robust), and Mode; spread is measured by Variance, Standard Deviation, and IQR.
  • Sample variance requires Bessel's correction (n - 1) for unbiased estimation.
  • Right-skewed distributions have Mean > Median > Mode; left-skewed distributions have Mode > Median > Mean.
  • The Central Limit Theorem guarantees that the distribution of sample means approaches normality as sample size grows (n ≥ 30).
  • Hypothesis testing balances Type I errors (False Positive, alpha) and Type II errors (False Negative, beta).
  • Compare 2 means with a T-Test; compare 3+ means with ANOVA to avoid family-wise error inflation; test categorical relationships with Chi-Square.
  • Pearson correlation measures linear strength (-1 to +1); Simple Linear Regression models predictive causality minimizing OLS residuals.