Standard Error and a Confidence Interval

~12 mincode completion

Implement mean_confidence_interval(x, z) returning [low, high], a two-element list.

Use the unbiased sample standard deviation (ddof=1).

Examples

Four evenly spaced points, at roughly 95% confidence

Input
mean_confidence_interval([2, 4, 6, 8], 1.96)
Output
[2.46965, 7.53035]

A sample with no spread gives an interval of zero width

Input
mean_confidence_interval([3, 3, 3], 1.96)
Output
[3, 3]

A wider multiplier gives a wider interval around the same mean

Input
mean_confidence_interval([1, 2, 3, 4, 5], 2.58)
Output
[1.17566, 4.82434]

Hints

Hint 1

Take the square root at the end, not inside the sum.

Hint 2

A common slip here: uses the standard deviation instead of the standard error.

Requirements

  • x: array of observations, shape (n,)

  • z: multiplier, e.g. 1.96 for roughly 95%

  • Return list of two floats: [lower bound, upper bound]

Constraints

  • Allowed library: NumPy only

  • Time limit: 200 ms, Memory: 64 MB

Where this shows up

~12 min

8 employers weight this skill

4 quant funds, 2 health and bio companies, 2 big tech firms. Top match scores 93.

Python
import numpy as np


def mean_confidence_interval(x, z):
    """
    A z-based confidence interval for the sample mean.

    Args:
        x: array of observations, shape (n,)
        z: multiplier, e.g. 1.96 for roughly 95%

    Returns:
        list of two floats: [lower bound, upper bound]
    """
    # YOUR CODE HERE
    pass
Loading docs…

The AI Mentor needs an account

It reads your code and the failing tests and nudges you toward the fix without handing you the answer. Free accounts get it on every problem you're working on today.