Skip to content

Constants

This section covers the constants used for the creation of SPC control charts.

lost_spc.constants.get_d(m, sim_size=10000)

Correction factors for the R and X control charts.

Refer to Shewhart charts for further reference.

Parameters:

Name Type Description Default
m int

Size of each sample.

required
sim_size int

Number of simulations performed to estimate d2 and d3 if no predifined value is available.

10000

Returns:

Type Description
D

Dataclass with the corrisponding d2 and d3 value.

Examples:

>>> d = get_d(5)
>>> d.d2
2.326
>>> d.d3
0.864
Source code in lost_spc/constants/__init__.py
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
def get_d(m: int, sim_size: int = 10_000) -> D:
    """Correction factors for the R and X control charts.

    Refer to
    [Shewhart charts](http://spc.pages.gitlab.ost.ch/statistische-\
    qualitaetskontrolle/cc_variable_data.html#die-shewhart-kontrollkarte) for
    further reference.

    Args:
        m: Size of each sample.
        sim_size: Number of simulations performed to estimate d2 and d3 if no
                  predifined value is available.

    Returns:
        Dataclass with the corrisponding d2 and d3 value.

    Examples:
        >>> d = get_d(5)
        >>> d.d2
        2.326
        >>> d.d3
        0.864
    """
    _check_sample_size(m)

    if m in _D_TABLE:
        return _D_TABLE[m]

    x = np.array(st.norm.rvs(size=(sim_size, m)))
    R_i = x.max(axis=1) - x.min(axis=1)
    d2 = np.mean(R_i)
    d3 = np.std(R_i, ddof=1)
    return D(d2=d2, d3=d3)

lost_spc.constants.get_c4(m)

Correction factor used for the s and corrisponding X control charts.

Refer to http://spc.pages.gitlab.ost.ch/statistische-qualitaetskontrolle/cc_variable_data.html#s-karte for further reference.

Parameters:

Name Type Description Default
m int

Size of each sample.

required

Returns:

Type Description
float

Calculated c4 value.

Examples:

>>> get_c4(5)
np.float64(0.9399856029866253)
Source code in lost_spc/constants/__init__.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
def get_c4(m: int) -> float:
    """Correction factor used for the s and corrisponding X control charts.

    Refer to
    http://spc.pages.gitlab.ost.ch/statistische-qualitaetskontrolle/cc_variable_data.html#s-karte
    for further reference.

    Args:
        m: Size of each sample.

    Returns:
        Calculated c4 value.

    Examples:
        >>> get_c4(5)
        np.float64(0.9399856029866253)
    """
    if m > 343:
        return 1

    _check_sample_size(m)

    return gamma(m / 2) / gamma((m - 1) / 2) * np.sqrt(2 / (m - 1))