Contents
,
Deep Breakdown
What it tells me (Situation Awareness): The ellipse is the set of points where the sum of distances to two fixed foci is constant. With semi-major axis (along ) and semi-minor axis (along ), the area is . The circle is the special case . In DA/DS and statistics, the ellipse is the confidence region shape for a bivariate normal distribution: the 1- contour of in 2D is an ellipse whose axes align with the eigenvectors of and whose half-axes lengths are and (the square roots of the eigenvalues). PCA scatter plots routinely overlay these confidence ellipses to visualize data spread and feature correlation.
Flowchart
Real-world use
Where it is used
Used when plotting confidence regions for bivariate normal distributions in 2D (PCA biplots, scatter plot overlays), in orbital mechanics analogies for understanding non-circular feature distributions, in quality control (Hotelling's statistic defines an ellipsoidal acceptance region), and in 2D anomaly detection where the normal region is an ellipse defined by the covariance structure of the training data.
Problem it solves
A circle assumes equal variance in all directions. Real data rarely has this property: feature pairs often have different scales and may be correlated. The ellipse generalizes the circle to capture anisotropic (direction-dependent) spread, making it the correct geometric object for modeling 2D Gaussian data, defining confidence regions, and visualizing correlation structure.
How it solves the problem
The ellipse equation is the standard form aligned with the coordinate axes. For a rotated ellipse (correlated features), the general form is where is the covariance matrix. Eigendecomposing gives the rotation angle (eigenvectors ) and the axis lengths ( scaled by ). The area formula follows from the substitution , which transforms the ellipse to the unit circle with Jacobian .
Example in a business
A data scientist plots the scatter of weekly TV spend vs digital spend for 104 weeks, overlaid with the 95% confidence ellipse from the sample covariance matrix. The ellipse's tilt reveals the correlation direction; the axis lengths reveal the relative variability. If the ellipse is nearly circular, the two channels vary independently; if it is elongated, the channels co-vary (possibly due to budget constraints or seasonality). This informs media mix model assumptions.
The formula, piece by piece
- : the contribution of the -coordinate, normalized by the squared semi-major axis ; controls the horizontal extent
- : the contribution of the -coordinate, normalized by the squared semi-minor axis ; controls the vertical extent
- : semi-major axis length; half the width along the -axis; by convention
- : semi-minor axis length; half the height along the -axis
- : area; reduces to when
- Eccentricity: (0 = circle, approaching 1 = very elongated) Full formulas: ,
The formula in words
"An ellipse is a stretched circle: squash a circle by factor in the -direction and you get an ellipse with semi-axes and . The area is times both half-axis lengths — if either half-axis is , you recover the circle formula ." Tiny numeric example: , . Equation: . Points on ellipse: (right vertex), (top vertex), , . .
Critical Concepts
- Standard vs general form: standard form assumes axes aligned with coordinate axes. For a rotated/correlated ellipse: where (from chi-squared distribution with 2 df) for a confidence region.
- Confidence region for bivariate normal: the -level confidence ellipse has . For 95%, .
- Axis alignment from PCA: eigendecompose ; the eigenvectors give the ellipse orientation, and gives the half-axis lengths.
- Area connection to determinant: . The determinant of the covariance matrix controls the total area of the confidence ellipse.
- Eccentricity: is a circle; is an extremely elongated ellipse. High eccentricity in a confidence ellipse signals strong correlation between the two features.
- Perimeter: there is no simple closed-form for the ellipse perimeter (unlike area).
The Ramanujan approximation: .
Step-by-step calculation (tiny example)
Step 1: Write the equation and identify vertices , . Equation: . Vertices: , , , . Foci: along : .
Step 2: Compute the area .
Step 3: Check a point is on the ellipse Point : .
Code examples
Beginner example (Python)
import numpy as np
import matplotlib.pyplot as plt
# -- Ellipse: equation, points on boundary, area -----------------------
A_SEMI = 5.0 # semi-major axis (x direction)
B_SEMI = 3.0 # semi-minor axis (y direction)
# Parametric form: x = a*cos(t), y = b*sin(t)
t = np.linspace(0, 2 * np.pi, 500)
x_ellipse = A_SEMI * np.cos(t)
y_ellipse = B_SEMI * np.sin(t)
# Check a few specific points
test_points = np.array([[5.0, 0.0], [0.0, 3.0], [3.0, 2.4]])
for pt in test_points:
val = (pt[0] / A_SEMI)**2 + (pt[1] / B_SEMI)**2
status = "on ellipse" if np.isclose(val, 1.0) else ("inside" if val < 1 else "outside")
print(f" Point ({pt[0]:.1f}, {pt[1]:.1f}): x^2/a^2 + y^2/b^2 = {val:.4f} -> {status}")
area = np.pi * A_SEMI * B_SEMI
eccentricity = np.sqrt(1 - (B_SEMI / A_SEMI)**2)
print(f"\nSemi-axes: a={A_SEMI}, b={B_SEMI}")
print(f"Area A = pi*a*b = {area:.4f}")
print(f"Eccentricity e = {eccentricity:.4f} (0=circle, ~1=very elongated)")Beginner example (R)
# -- Ellipse: equation, points on boundary, area -----------------------
A_SEMI <- 5.0
B_SEMI <- 3.0
# Parametric form
t <- seq(0, 2 * pi, length.out = 500)
x_ell <- A_SEMI * cos(t)
y_ell <- B_SEMI * sin(t)
# Check points
test_pts <- rbind(c(5, 0), c(0, 3), c(3, 2.4))
for (i in seq_len(nrow(test_pts))) {
pt <- test_pts[i, ]
val <- (pt[1] / A_SEMI)^2 + (pt[2] / B_SEMI)^2
status <- if (isTRUE(all.equal(val, 1.0))) "on ellipse" else if (val < 1) "inside" else "outside"
cat(sprintf(" Point (%.1f, %.1f): val = %.4f -> %s\n", pt[1], pt[2], val, status))
}
area <- pi * A_SEMI * B_SEMI
eccentricity <- sqrt(1 - (B_SEMI / A_SEMI)^2)
cat(sprintf("\nArea A = pi*a*b = %.4f\n", area))
cat(sprintf("Eccentricity e = %.4f\n", eccentricity))Professional example (Python)
import numpy as np
import pandas as pd
from scipy.stats import chi2
np.random.seed(42) # -- Business scenario: 95% confidence ellipse for weekly media spend
# TV spend and digital spend for 104 weeks.
# Overlay the 95% confidence ellipse (chi-squared with 2 df) on the scatter.
# Report: semi-axes, area, eccentricity, and what the ellipse shape reveals.
N_WEEKS = 104
TV_MEAN, TV_STD = 20_000.0, 4_000.0
DIGITAL_MEAN, DIG_STD = 15_000.0, 3_000.0
CORRELATION = 0.65 # positive: both channels funded together # Simulate correlated spend data
cov_raw = np.array([ [TV_STD**2, CORRELATION * TV_STD * DIG_STD], [CORRELATION * TV_STD * DIG_STD, DIG_STD**2],
])
spend = np.random.multivariate_normal([TV_MEAN, DIGITAL_MEAN], cov_raw, size=N_WEEKS)
x_centered = spend - spend.mean(axis=0) # Sample covariance matrix
cov_sample = np.cov(x_centered.T) # 2x2 # Confidence ellipse: x^T Sigma^-1 x = chi2(2, 0.95) ~ 5.991
K_SQ = float(chi2.ppf(0.95, df=2))
eigvals, eigvecs = np.linalg.eigh(cov_sample)
# Sort eigenvalues descending
order = np.argsort(eigvals)[::-1]
eigvals = eigvals[order]
eigvecs = eigvecs[:, order] # Ellipse semi-axes in original units
semi_a = float(np.sqrt(eigvals[0] * K_SQ)) # semi-major axis (along eigvec_0)
semi_b = float(np.sqrt(eigvals[1] * K_SQ)) # semi-minor axis (along eigvec_1)
area = np.pi * semi_a * semi_b
angle_deg = float(np.degrees(np.arctan2(eigvecs[1, 0], eigvecs[0, 0])))
eccentricity = float(np.sqrt(1 - (semi_b / semi_a)**2))
summary = pd.DataFrame({ "metric": [ "semi-major axis (EUR)", "semi-minor axis (EUR)", "rotation angle (deg)", "confidence ellipse area (EUR^2)", "eccentricity", "correlation implied", ], "value": [ f"{semi_a:,.0f}", f"{semi_b:,.0f}", f"{angle_deg:.2f}", f"{area:,.0f}", f"{eccentricity:.4f}", f"{CORRELATION:.2f}", ],
})
print(f"95% Confidence Ellipse for TV vs Digital Spend (chi2 threshold = {K_SQ:.3f}):")
print(summary.to_string(index=False))
print(f"\nInterpretation: eccentricity={eccentricity:.3f} confirms strong elongation along the TV-digital correlation axis. The ellipse tilt of {angle_deg:.1f} degrees reflects the positive correlation of {CORRELATION}. Area = pi * {semi_a:,.0f} * {semi_b:,.0f} = {area:,.0f} EUR^2 (not a physical unit, but proportional to total data spread).")Source: 1300 p. 160