Skip to main content

PChart

Struct PChart 

Source
pub struct PChart { /* private fields */ }
Expand description

Proportion nonconforming (P) chart.

Monitors the fraction of defective items in samples that may have different sizes. Control limits vary per subgroup when sample sizes differ.

§Formulas

  • CL = p-bar = total_defectives / total_inspected
  • UCL_i = p-bar + 3 * sqrt(p-bar * (1 - p-bar) / n_i)
  • LCL_i = max(0, p-bar - 3 * sqrt(p-bar * (1 - p-bar) / n_i))

§Phase I and Phase II

PChart::new estimates p-bar from the samples it is given (Phase I). To judge later samples against an established process, build the chart with PChart::with_center: every limit then uses that p-bar with each sample’s own n. Re-estimating from Phase I and Phase II samples together would let a shift in Phase II pull the centre toward itself and widen its own limits.

§Examples

use u_analytics::spc::PChart;

let mut chart = PChart::new();
chart.add_sample(3, 100).unwrap();  // 3 defectives out of 100
chart.add_sample(5, 100).unwrap();
chart.add_sample(2, 100).unwrap();
chart.add_sample(4, 100).unwrap();

let p_bar = chart.p_bar().expect("should have p_bar after adding samples");
assert!(p_bar > 0.0);

§Reference

Montgomery, D.C. (2019). Introduction to Statistical Quality Control, 8th ed., Chapter 7, Section 7.3.

Implementations§

Source§

impl PChart

Source

pub fn new() -> Self

Create a new P chart that estimates p-bar from its samples (Phase I).

Source

pub fn with_center(p_bar: f64) -> Result<Self, ControlChartError>

Create a P chart whose centre line is a known p-bar, typically from a Phase I study (Phase II).

§Errors

ControlChartError::InvalidStandard unless p_bar is finite and strictly between 0 and 1 — at 0 or 1 every limit collapses onto the centre line.

Source

pub fn add_sample( &mut self, defectives: u64, sample_size: u64, ) -> Result<(), ControlChartError>

Add a sample with the number of defective items and the total sample size.

§Errors

ControlChartError::ZeroSampleSize if sample_size is 0, or ControlChartError::DefectivesExceedSampleSize if defectives > sample_size. The chart is left unchanged; such a sample used to be dropped silently, shifting every later point.

Source

pub fn p_bar(&self) -> Option<f64>

The centre line in use — the known p-bar for a chart built with_center, otherwise the estimate — or None if no data.

Source

pub fn points(&self) -> &[AttributeChartPoint]

Get all chart points.

Source

pub fn is_in_control(&self) -> bool

Check if the process is in statistical control.

Trait Implementations§

Source§

impl Default for PChart

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.