Skip to content

Panic when computing a confidence interval from a single sample. #3

@vext01

Description

@vext01

Hi,

We use your library (thank you for writing it) to compute confidence intervals for benchmarking data.

Our continuous integration pipeline does a "quick run" of our benchmarks and runs our statistics program to check that it doesn't obviously bork. A "quick run" here runs each benchmark only once, which means that we end up computing confidence intervals from a single sample and this crashes stats-ci with a panic.

Minimal example:

use stats_ci::{mean, Confidence};

fn main() {
    // 2 samples: this is OK.
    let ci = mean::Arithmetic::ci(Confidence::new(0.95), &[1.0, 1.0]).unwrap();
    dbg!(ci);

    // 1 sample: this crashes:
    // thread 'main' panicked at .../stats-ci-0.1.1/src/stats.rs:34:64:
    //   called `Result::unwrap()` on an `Err` value: BadParams
    let ci = mean::Arithmetic::ci(Confidence::new(0.95), &[1.0]).unwrap();
    dbg!(ci);
}

The panic comes from an unwrap in stats-ci.

Obviously it's kind of nuts to be computing intervals for a single sample, but at the same time, I don't think this should cause the library to panic.

What should happen though?

  • Compute an interval for the single sample, if possible?
  • If not, the library should probably raise an error to the caller rather than panicking internally.

I prefer the former, but appreciate that it may not be possible. What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions