Skip to content
DeepForgeby svx
All problems
MediumProbabilitypr-130

Bias of the MLE Sample Variance

Problem

The maximum likelihood sample variance (dividing by n instead of n - 1) is biased. For a true variance sigma_squared the bias is:

bias = -sigma_squared / n.

Return the bias, and 0.0 for n <= 0.

Hint

The MLE underestimates by a factor of (n - 1) / n.

Test cases

case 1
in: [10,1]
expected: -0.1
case 2
in: [5,2]
expected: -0.4
case 3
in: [1,0.5]
expected: -0.5
case 4
in: [0,1]
expected: 0
Starter codePython
def sample_variance_bias(n, sigma_squared):
    # Your code here
    pass

4 test cases · run your code against them in the editor