BRAGA

02 Writing02-02 Notes02-02-378

Independent Events (Intersection)

Published 16 Apr 20264 min read
Contents
  1. 01Deep Breakdown
  2. 02Flowchart
  3. 03Real-world use
  4. 04The formula, piece by piece
  5. 05The formula in words
  6. 06Critical Concepts
  7. 07Step-by-step calculation (tiny example)
  8. 08Code examples
P(A∩B)=P(A)⋅P(B)P(A \cap B) = P(A) \cdot P(B)
(1)

Deep Breakdown

What it tells me (Situation Awareness): Two events AA and BB are statistically independent if knowing that one occurred gives no information about whether the other occurred. The joint probability then equals the product of marginals. This is the independence assumption underlying Naive Bayes, many ML model assumptions, i.i.d. sampling, and bootstrap validity.

Flowchart

A and B areindependentP(A|B) = P(A)P(A∩B) = P(A|B)* P(B)= P(A) * P(B)Joint = productof marginals

Real-world use

Where it is used

Naive Bayes classifier (assumes feature independence given class). Bootstrap sampling (draws assumed i.i.d.). Multi-armed bandit (arm outcomes independent). Cross-validation fold splits.

Problem it solves

Under independence, joint probabilities factorize — enabling tractable computation of high-dimensional joint distributions.

How it solves the problem

If AA and BB are independent, P(A∣B)=P(A)P(A \mid B) = P(A) by definition. Substituting into the chain rule: P(A∩B)=P(A)⋅P(B)P(A \cap B) = P(A) \cdot P(B).

Example in a business

Naive Bayes spam filter: P(spam∣w1,…,wn)∝P(spam)∏iP(wi∣spam)P(\text{spam} \mid w_1, \ldots, w_n) \propto P(\text{spam}) \prod_i P(w_i \mid \text{spam}). This product form works because features are assumed conditionally independent given class.

The formula, piece by piece

P(A∩B)=P(A)⋅P(B)P(A \cap B) = P(A) \cdot P(B)

  • Applies ONLY when AA and BB are independent.
  • If not independent: P(A∩B)=P(A∣B)P(B)≠P(A)P(B)P(A \cap B) = P(A \mid B) P(B) \neq P(A)P(B) in general.

The formula in words

"If A and B are independent, the probability of both occurring equals the product of their individual probabilities."

Critical Concepts

  • Independence is symmetric: A⊥B  ⟺  B⊥AA \perp B \iff B \perp A.
  • Pairwise independence does not imply mutual independence.
  • Testing independence: check if P(A∩B)≈P(A)⋅P(B)P(A \cap B) \approx P(A) \cdot P(B) from data.
  • Conditional independence: A⊥B∣CA \perp B \mid C means P(A∩B∣C)=P(A∣C)P(B∣C)P(A \cap B \mid C) = P(A \mid C)P(B \mid C).

Step-by-step calculation (tiny example)

Step 1: Two independent coins P(H1)=0.5P(H_1) = 0.5, P(H2)=0.5P(H_2) = 0.5. Tosses are independent.

Step 2: Joint P(H1∩H2)=0.5×0.5=0.25P(H_1 \cap H_2) = 0.5 \times 0.5 = 0.25

Step 3: Verify with complement P(at least one head)=1−P(T1∩T2)=1−0.25=0.75P(\text{at least one head}) = 1 - P(T_1 \cap T_2) = 1 - 0.25 = 0.75. Consistent.

Code examples

Beginner example (Python)

python
# Independence check: are two features independent?
import numpy as np
rng = np.random.default_rng(seed=42)
n = 10000
# Simulate independent binary features
feat_a = rng.binomial(1, 0.4, n)
feat_b = rng.binomial(1, 0.6, n)
p_a = feat_a.mean()
p_b = feat_b.mean()
p_ab = (feat_a & feat_b).mean()
p_ab_if_independent = p_a * p_b
print(f"P(A): {p_a:.3f}, P(B): {p_b:.3f}")
print(f"P(A∩B) observed: {p_ab:.4f}")
print(f"P(A)*P(B) expected: {p_ab_if_independent:.4f}")
print(f"Independent: {abs(p_ab - p_ab_if_independent) < 0.01}")

Beginner example (R)

r
set.seed(42)
n <- 10000
feat_a <- rbinom(n, 1, 0.4)
feat_b <- rbinom(n, 1, 0.6)
p_ab_obs <- mean(feat_a & feat_b)
p_ab_exp <- mean(feat_a) * mean(feat_b)
cat("P(A∩B) observed:", round(p_ab_obs, 4), "\n")
cat("P(A)*P(B) expected:", round(p_ab_exp, 4), "\n")

Professional example (Python)

python
import numpy as np
from scipy.stats import chi2_contingency

def test_independence( feature_a: np.ndarray, feature_b: np.ndarray, significance_level: float = 0.05 ) -> dict[str, float | bool]:
    """Test statistical independence of two binary features. Uses chi-square test of independence on contingency table. Args: feature_a: Binary array for feature A. feature_b: Binary array for feature B. significance_level: Alpha for rejection. Returns: Dict with chi2 statistic, p-value, and independence verdict. """
    contingency_table = np.array([ [(~feature_a.astype(bool) & ~feature_b.astype(bool)).sum(), (~feature_a.astype(bool) & feature_b.astype(bool)).sum()], [( feature_a.astype(bool) & ~feature_b.astype(bool)).sum(), ( feature_a.astype(bool) & feature_b.astype(bool)).sum()], ])
    chi2, p_value, dof, expected = chi2_contingency(contingency_table)
    return { "chi2": chi2, "p_value": p_value, "independent": p_value > significance_level, "p_a_times_p_b": feature_a.mean() * feature_b.mean(), "p_a_and_b": (feature_a.astype(bool) & feature_b.astype(bool)).mean(), }   # Test feature independence in a dataset
rng = np.random.default_rng(seed=42)
n_samples = 5_000
independent_result = test_independence( rng.binomial(1, 0.4, n_samples), rng.binomial(1, 0.6, n_samples) )
print("Independent features test:", independent_result)

Source: AIO p. 84

#probability-statistics#probability-theory#conditional-probability-and-independence

Keyboard shortcuts

Single keys, ignored while typing in a field or with Cmd, Ctrl or Alt held.

0
Home
1 2 3 4
Work, Writing, Tools, About
j / k
Next / previous section on this page
n / p
Next / previous project or essay
u
Up one level
l
Deutsch
t
Light or dark theme
?
This list
Esc
Close