Posts

Showing posts from March, 2026

Why Do We Divide by n-1 for Sample Variance? (The Intuitive & Mathematical Guide)

Image
Why Do We Divide by (n - 1) in Sample Variance? Key point: Sample variance uses (n - 1) to remove bias caused by estimating the mean. Sample variance is defined as: s 2 = (1 / (n - 1)) ∑ i=1 n (x i - x̄) 2 The use of (n - 1) ensures that the estimator is unbiased. 1. Problem Definition Let a population have mean μ and variance σ 2 . We draw an i.i.d. sample: x 1 , ..., x n Sample mean: x̄ = (1 / n) ∑ x i 2. Naive Estimator and Bias Naive estimator: (1 / n) ∑(x i - x̄) 2 This estimator is biased downward: E[~s 2 ] < σ 2 3. Sample Mean Reduces Spread (Visualization) The sample mean minimizes squared deviations, which reduces observed spread. Figure 1. Sample points with true mean and sample mean. The sample mean shifts toward the data, reducing apparent variance. 4. Mathematical Derivation We now derive why dividing by n - 1 makes the sample variance unbiased. Assume that x 1 , x 2 , ..., x n are i.i.d. ...

Averaging and Moving Average Filters

Image
  1. Why Averaging Matters In engineering systems, especially in robotics, sensor data is often noisy. A simple and effective way to reduce noise is to compute the average of measurements. However, how we compute the average matters, especially when data keeps growing. 2. Batch Expression The average of k data points is defined as: x̄ k = (x 1 + x 2 + ··· + x k ) / k This is called a batch expression , because all data must be collected before computing the result. 3. Limitation of the Batch Method The batch method has two major drawbacks: Every time new data arrives, we must recompute the entire sum. All previous data must be stored in memory. This becomes inefficient when the number of data points is large. 4. Recursive Averaging Filter Instead of recomputing everything, we can reuse the previous average. Starting from the batch expression: x̄ k = (x 1 + x 2 + ··· + x k ) / k Multiply both sides by k : k x̄ k = x 1 + x 2 + ··· + ...