Skip to main content

ConfidenceInterval

Struct ConfidenceInterval 

Source
pub struct ConfidenceInterval<T> { /* private fields */ }
Expand description

A statistical confidence interval.

A confidence interval represents a bounded range of values associated with a statistical estimate, together with a confidence level describing the reliability of the construction procedure.

§Structure

A confidence interval consists of:

§Geometry

The interval is closed:

lower ≤ x ≤ upper

Implementations§

Source§

impl<T: Copy> ConfidenceInterval<T>

Source

pub fn level(&self) -> ConfidenceLevel<T>

Returns the confidence level associated with the confidence interval

Source§

impl<T: Float> ConfidenceInterval<T>

Source

pub fn new( lower: T, upper: T, confidence_level: ConfidenceLevel<T>, ) -> Result<Self, ValidationError>

Creates a confidence interval from a lower and upper bounds and a confidence level.

§Examples
use confi::{ConfidenceInterval, ConfidenceLevel};

let cl = ConfidenceLevel::new(0.95)?;
let (lower, upper) = (0.0, 1.0);

let ci = ConfidenceInterval::new(lower, upper, cl)?;

assert_eq!(ci.lower(), lower);
assert_eq!(ci.upper(), upper);
assert_eq!(ci.level().into_inner(), 0.95);
§Errors
  • If the lower or upper bound are NaN
  • If the lower or upper bound are infinite
  • If the lower or upper bound do not form an ordered interval
Source§

impl<T: Float> ConfidenceInterval<T>

Source

pub fn lower(&self) -> T

Returns the lower bound for the confidence interval

§Examples
use confi::{ConfidenceInterval, ConfidenceLevel};

let cl = ConfidenceLevel::new(0.95)?;
let (lower, upper) = (0.0, 1.0);

let ci = ConfidenceInterval::new(lower, upper, cl)?;

assert_eq!(ci.lower(), lower);
Source

pub fn upper(&self) -> T

Returns the upper bound for the confidence interval

§Examples
use confi::{ConfidenceInterval, ConfidenceLevel};

let cl = ConfidenceLevel::new(0.95)?;
let (lower, upper) = (0.0, 1.0);

let ci = ConfidenceInterval::new(lower, upper, cl)?;

assert_eq!(ci.upper(), upper);
Source§

impl<T: Float> ConfidenceInterval<T>

Source

pub fn contains(&self, value: T) -> bool

Returns true if the interval contains the argument

§Examples
use confi::{ConfidenceInterval, ConfidenceLevel};

let cl = ConfidenceLevel::new(0.95)?;
let (lower, upper) = (0.0, 1.0);

let ci = ConfidenceInterval::new(lower, upper, cl)?;

assert_eq!(ci.contains(0.5), true);
assert_eq!(ci.contains(1.5), false);
Source

pub fn width(&self) -> T

Returns the width of the confidence interval

§Examples
use confi::{ConfidenceInterval, ConfidenceLevel};

let cl = ConfidenceLevel::new(0.95)?;
let (lower, upper) = (0.0, 1.0);

let ci = ConfidenceInterval::new(lower, upper, cl)?;

assert_eq!(ci.width(), upper - lower);
Source

pub fn centre(&self) -> T

Returns the centre of the confidence interval

§Examples
use confi::{ConfidenceInterval, ConfidenceLevel};

let cl = ConfidenceLevel::new(0.95)?;
let (lower, upper) = (0.0, 1.0);

let ci = ConfidenceInterval::new(lower, upper, cl)?;

assert_eq!(ci.centre(), 0.5);
Source

pub fn radius(&self) -> T

Returns the radius of the confidence interval

§Examples
use confi::{ConfidenceInterval, ConfidenceLevel};

let cl = ConfidenceLevel::new(0.95)?;
let (lower, upper) = (0.0, 1.0);

let ci = ConfidenceInterval::new(lower, upper, cl)?;

assert_eq!(ci.radius(), 0.5);
Source§

impl<T> ConfidenceInterval<T>
where T: ToPrimitive,

Trait Implementations§

Source§

impl<T: Clone> Clone for ConfidenceInterval<T>

Source§

fn clone(&self) -> ConfidenceInterval<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for ConfidenceInterval<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Display for ConfidenceInterval<T>
where T: Float + ToPrimitive,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ConfidenceInterval<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ConfidenceInterval<T>
where T: RefUnwindSafe,

§

impl<T> Send for ConfidenceInterval<T>
where T: Send,

§

impl<T> Sync for ConfidenceInterval<T>
where T: Sync,

§

impl<T> Unpin for ConfidenceInterval<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ConfidenceInterval<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for ConfidenceInterval<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.