Control Chart for Variables 1.0
by Guillermo Sanchez, guillerm@gugu.usal.es

Introduction (Loading the package)

Control chart is a statistic tool to distinguish when a process is out of control.   A control chart requires data obtained by sampling a specific quality characteristic of the process at approximately regular intervals. The intervals may be defined in terms of time (for example hourly) or quantity (every lot). Every sampling is usually is named  "subgroup", each subgroup consists of the same measure units and the same subgroup size.  One o more parameters are derived from each subgroup such as: the subgroup average,  \(TraditionalForm\`X\&_\), subgroup standards deviation, s, etc.   
Shewhart control chart, and others, contains a center line (CL)  that represents the average value of the quality characteristics, and two other horizontal lines, called the upper control limit (UCL) and the lower control limit (LCL). The Shewhart Control Charts (ex.: XbarS) only use the information of the process contained in the last subgroup. To detect systematic manner it is necessary introduce additional criteria. This makes the  Shewhart CC relatively insensitive to small shifts in the process. Two alternative kind of control charts may be used to detect small shifts: Cusum and EWMA. 
When the quality characteristic is measured using a scale is said that it is a variable. The result of measurements can be represented by a list of data .

Download the package

This package can be used to make the most known variable control charts: Xbar-S, Individuals, Cusum and EWMA for individual values, T2 Multivariable. The package is downloaded as usual:

Needs["QualityControl`VariableChart`"]

(It dawnload also the packages: MultiDescriptiveStatistics and MultipleListPlot)

Mean and standard deviation chart

Introduction

This kind of control chart , also known as \(TraditionalForm\`X\&_\),s charts or Xbar-S Chart, calculate the average, \(TraditionalForm\`X\&_\_k\),  and standard deviation, (Subscript[s, k]) for each subgroup k .

The limits (UCL and LCL)  and center line (CL) are estimated depending of the situation: If standards values are unknown and must be estimated or if standards values are given.  Table 1 gives the formulae for both situation.

Table 1.- Formulae for \(TraditionalForm\`X\&_\),s charts

({{Stad., (CL^1), LC  L  & (UCL^1), (CL^2),  LCL  & (UCL^2)}, {\(X\&-\), \(\(\ \)\(\(X\&_\)\&_\)\), \(\(X\&_\)\&_\)±(Subscript[A, 3])(OverBar[s]), (Subscript[X, 0])or μ, (Subscript[X, 0])±A (Subscript[σ, 0])}, {s,  \(s\&_\), (Subscript[B, 3])\(s\&_\),(Subscript[B, 4])\(s\&_\), (Subscript[s, 0])or (Subscript[c, 4]) (Subscript[σ, 0]), (Subscript[B, 5])(Subscript[σ, 0]),(Subscript[B, 6])(Subscript[σ, 0])}})

(1) No standards values given. (OverBar[(OverBar[X])]),  and (OverBar[s]) must be calculated, where (OverBar[(OverBar[X])]) and (OverBar[s]) are the average of {\(TraditionalForm\`X\&_\_k\)} and {(Subscript[s, k])}, respectively.(OverBar[\(X\&_\)])  is often called great mean.
(2) (Subscript[X, 0]),  μ,  (Subscript[σ, 0]), and (Subscript[s, 0]) are given standard values.

A, (Subscript[A, 3]), (Subscript[B, 3]) ,(Subscript[B, 4]), (Subscript[B, 5]), (Subscript[B, 6]), (Subscript[D, 1]), (Subscript[D, 2]) and (Subscript[c, 4]) are tabulated in many statistics books and standards (ex.: ISO 8258:1991(E)). We can also expressed analytically:

(Subscript[c, 4 ])= (Sqrt[(2/(m - 1))])\(TraditionalForm
      \`\(Γ(m/2)\)\/Γ[\((m - 1)\)/2]\)A = 3/(Sqrt[m]), (Subscript[A, 3]) = 3/((Subscript[c, 4 ]) (Sqrt[m])),

(Subscript[B, 3]) =   1 - (3/(Subscript[c, 4]))(Sqrt[1 - (Subscript[c, 4]^2)]), (Subscript[B, 4]) =    1 + (3/(Subscript[c, 4]))(Sqrt[1 - (Subscript[c, 4]^2)]), (Subscript[B, 5]) = (Subscript[c, 4])- 3(Sqrt[1 - (Subscript[c, 4]^2)]), (Subscript[B, 6]) = (Subscript[c, 4])+ 3(Sqrt[1 - (Subscript[c, 4]^2)])

The package  gives a general report, a short report, and plot the control chart using the values from data.

data = {{(Subscript[X, 11]), (Subscript[X, 12]), ..., (Subscript[X, 1  m])}, {(Subscript[X, 21]), (Subscript[X, 22]), ..., (Subscript[X, 2  m])}, ..., {(Subscript[X, k1]), (Subscript[X, k2]), ..., (Subscript[X, ki]), ...,(Subscript[X, km])}, ...}, where k is the subgroup, and i the observation in each subgroup. It is assumed that the size of subgroups is the same and  m>1.

X bar S chart for no standard values given (Initial Study)

Mean and deviation of process are calculated using data values

X bar S chart for standard values given

Mean, mu,  and deviation, sig,  of process are supposed that are known.

Examples

data1  = 
        {{5.65, 5.71, 4.76, 4.64, 5.92}, {4.43, 7.03, 4.34, 3.77, 4.03}, 
          {5.54, 4.1, 7.75, 4.18, 4.79}, {5.26, 5.45, 3.09, 5.37, 5.16}, 
          {5.41, 4.06, 5.53, 6.09, 5.64}, {4.44, 4.81, 4.11, 4.56, 6.14}, 
          {3.09, 5.66, 4.06, 4.78, 4.72}, {4.05, 4.89, 6.85, 6.96, 4.16}, 
          {3.71, 4.63, 6.83, 5.32, 4.46}, {3.68, 3.7, 5.75, 6.66, 5.51}, 
          {7.21, 5.38, 4.29, 3.93, 4.04}, {5.42, 5.16, 4.67, 4.41, 3.55}, 
          {4.21, 3.58, 4.43, 4.17, 5.46}, {4.83, 3.40, 6.4, 4.0, 4.02}, 
          {5.57, 5.12, 5.05, 4.68, 3.61}, {2.5, 3.87, 4.68, 6.19, 5.19}, 
          {4.64, 5.41, 4.48, 6.45, 3.99}, {5.47, 6.14, 5.24, 4.37, 5.74}, 
          {3.89, 4.65, 6.03, 5.39, 3.84}, {5.35, 5.85, 6.52, 6.53, 5.41}};

No standard values given

?XbarSReport

XbarSReport[data1]

?XbarSReportSh

XbarSReportSh[data1]

?XbarSChart

XbarSChart[data1]

Standard values given

Standard values are known: μ = 5, σ = 1

?XbarSReportShSG

XbarSReportShSG[data1, 5, 1]

?XbarSReportSG

XbarSReportSG[data1, 5, 1]

?XbarSChartSG

XbarSChartSG[data1, 5, 1]

Control Charts for Individual Measurements

Introduction

In the \(TraditionalForm\`X\&_\) Chart only one value is taken for each subgroup (m = 1).  The limits (UCL and LCL)  and center line (CL) are calculated depending on the situation: If standards values are unkown and must be estimated or if standars values are given.  Table 2 gives the formulae for both situation.

data  = {(Subscript[X, 1]), (Subscript[X, 2]), ...., (Subscript[X, n])},

The moving range is denoted by MR =  {|(Subscript[X, 1])- (Subscript[X, 2])|, |(Subscript[X, 2])- (Subscript[X, 3])|....,|(Subscript[X, n - 1])-(Subscript[X, n])|}

Table 2.- Formulae for X charts for individuals.

({{Stad., (CL^1), UCL  & (LCL^1), (CL^2),  UCL  & (LCL^2)}, {X,  (OverBar[X]), \(\(X\&_\)\&_\)±(Subscript[E, 2])\(MR\&_\)
(Subscript[E, 2]) = 3/1.128, (Subscript[X, 0])or μ, (Subscript[X, 0])±3 (Subscript[σ, 0  ])}, {Moving range, MR,  \(MR\&_\), \(\(D\_4\) MR\&_\),(Subscript[D, 3])\(MR\&_\)
(Subscript[D, 4]) =  3.267, (Subscript[D, 3]) =  0, (Subscript[R, 0])or (Subscript[d, 2]) (Subscript[σ, 0])
(Subscript[d, 2])  =  1.128, (Subscript[D, 2])(Subscript[σ, 0]),(Subscript[D, 1])(Subscript[σ, 0])
(Subscript[D, 2]) =  3.686, (Subscript[D, 1]) =  0}})

\(MR\&_\)  denotes the average moving range of n =2 observations. 
(1) No standards values given.\(\(\(\ \)\(\(X\&_\)\&_\)\)\),  and \(MR\&_\) must be calculated.
(2) (Subscript[X, 0]),  (Subscript[R, 0]) , μ,  (Subscript[σ, 0]), and are given standard values.

No standard values are given (Initial Study)

Mean and deviation of process are calculated using data values

Standard values are given

Mean, mu,  and deviation, (Subscript[σ, 0]),  of process are supposed that are known.

Example

data2  =  
        {33.75,  33.05,  34.00,  33.81,  33.46,  34.02,  33.68,  
          33.27,  33.49,  33.20,  33.62,  33.00,  33.54,  33.12,  
          33.84};

No standard given

?XforIReportSh

XforIReportSh[data2]

?XforIReport

XforIReport[data2]

?XforIChart

XforIChart[data2]

Standard given

Standard values are known: μ = 33.5, σ = 0.4.

?XforIReportShSG

XforIReportShSG[33.5, 0.4]

?XforIReportSG

XforIReportSG[data2,  33.5, 0.4]

?XforIChartSG

XforIChartSG[data2,  33.5, 0.4]

Cusum Chart

Introduction

Cusum Control Chart is useful when we are interested in detecting small shifts. It is typically used with individual observations {(Subscript[X, 1]), (Subscript[X, 2]), ...., (Subscript[X, n])}. If (Subscript[μ, 0]) is the target of the process mean, the cumulative sum is formed by plotting the quantity (Subscript[C, k]) = \(TraditionalForm\`∑\+\(j = 1\)\%k\((x\&_\_j - μ\_0)\)\) against the sample k.  It is very effective with samples of size m = 1. In this case  
(Subscript[C, k]) = \(TraditionalForm
      \`\((x\_k - μ\_0)\) + 
        ∑\+\(j = 1\)\%\(k - 1\)\((x\_j - μ\_0)\)\) = ((Subscript[x, k]) - (Subscript[μ, 0])) - (Subscript[C, k - 1]), with (Subscript[C, 0]) = 0. 
But (Subscript[C, i])  is not a control chart because it doesn't have limits. The procedure to represent a cusum chart is using the called Tabular Cusum method. The tabular cusum works accumulating deviation from the target (Subscript[μ, 0]) computing the statistics \(TraditionalForm\`\(C\_i\%+\)\) and \(TraditionalForm\`\(C\_i\%-\)\) -called one-sided upper and lower cusums, respectively- as follows:
\(\(C\_k\%+\) = 
          max[0, x\_k - \((μ\_0 + K)\)\  + \(C\_\(k - 1\)\%+\)]\),
\(\(C\_k\%-\) = 
          max[0, \((μ\_0 - K)\) - x\_k\  + \(C\_\(k - 1\)\%-\)]\)
with  \(TraditionalForm\`\(C\_0\%+\)\) = \(TraditionalForm\`\(C\_0\%-\)\) = 0. 
K (called reference value) is a constant often chosen in the center between the target (Subscript[μ, 0]) and the out-of-control value (Subscript[μ, 1]). So, if the shift is expressed in standard deviation units as (Subscript[μ, 1]) = (Subscript[μ, 0]) + δσ, them 
K = (δ/2) σ = ((|(Subscript[μ, 1]) - (Subscript[μ, 0])|)/2)
If  \(TraditionalForm\`\(C\_k\%+\)\) or \(TraditionalForm\`\(C\_k\%-\)\) exceeds the decision interval  H, the process is considered to be out of control.  The election of H is very important. It is usually taken H = 5 σ.  \(TraditionalForm\`\(C\_k\%+\)\) or \(TraditionalForm\`\(C\_k\%-\)\) . It also is convenient to calculate \(TraditionalForm\`\(N\^+\)\) and \(TraditionalForm\`\(N\^-\)\). These indicate the number of consecutive periods that the cusums  \(TraditionalForm\`\(C\_k\%+\)\) or \(TraditionalForm\`\(C\_k\%-\)\) have been nonzero.

Cusum Chart

Example

data3  = 
        {9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 
          9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 8.52, 10.84, 
          10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52};

The cusum report assuming  (Subscript[μ, 0]) = 10, σ = 1 is

?CusumReport

CusumReport[data3, 10, 1]

?CusumChart

The tabular cusum chart assuming  (Subscript[μ, 0]) = 10, σ = 1 and H=5 is

CusumChart[ data3, 10, 1, 5]

The exponentially weighted moving-average EWMA Chart

Introduction

The EWMA control chart is useful when we are interested in detecting small shifts . As with the cusum, the EWMA is typically used with individual observations {(Subscript[X, 1]), (Subscript[X, 2]), ...., (Subscript[X, n])}. The EWMA  is defined as
\(TraditionalForm
      \`z\_k = λ\ x\_k + \((1 - λ)\) z\_\(k - 1\)\)
where 0<λ≤1 is a constant and the starting value (i=0) is (Subscript[z, 0]) = (Subscript[μ, 0]). Often (Subscript[μ, 0]) = \(TraditionalForm\`x\&_\), is estimated making a preliminary study taking several (Subscript[x, i]) values when the process is in control. 
The EWMA control chart is represented by plotting (Subscript[z, i]) versus i. The center  line and control limits are represented as well. They are evaluated as follows:
(Subscript[UCL, i]) = \(TraditionalForm
      \`μ\_0 + 
        L\ σ 
          \@\( λ\/\(2 - λ\)\)[1 - \((1 - λ)\)\^\(2  k\)]\) 
CL = (Subscript[μ, 0])
(Subscript[LCL, k]) = \(TraditionalForm
      \`μ\_0 - 
        L\ σ 
          \@\( λ\/\(2 - λ\)\)[1 - \((1 - λ)\)\^\(2  k\)]\)
L is the width of the control limits, and, like λ,  it should be chosen carefully (see Montgomery 1996)

EWMA Chart

Example

data3  = 
        {9.45, 7.99, 9.29, 11.66, 12.16, 10.18, 8.04, 11.46, 9.2, 10.34, 
          9.03, 11.47, 10.51, 9.4, 10.08, 9.37, 10.62, 10.31, 8.52, 10.84, 
          10.9, 9.33, 12.29, 11.5, 10.6, 11.08, 10.38, 11.62, 11.31, 10.52};

Typical values  of λ and L are λ=0.1, L =2.7.

?EWMAReport

EWMAReport[data3, 10,  0.1, 1,  2.7]

?EWMAChart

EWMAChart[data3, 10,  0.1, 1,  2.7]

Multivariable Control Chart

Introduction

Many processes have multiple quality characteristics and however they require multivariable monitoring methods. Hotelling's (T^2) is the most popular control chart for monitoring a multivariable process. It is applied to the case where the p quality characteristics are controlled jointly, and the probability distribution of the p qualify characteristics is the p-variable normal distribution. The multinormal distribution is usually denoted by N\(TraditionalForm\`\_p\)(μ, Σ), where  p is the number of control variables, μ'((Subscript[μ, 1]), (Subscript[μ, 2]), ..., (Subscript[μ, p])) is the vector of in-control means (' = transpose) for each quality characteristic and ∑ is the covariance matrix.
One statistics derived of Multinormal and used to make Multivariable Control Chart is
	(Subscript[χ, 0]^2) = n ((OverBar[x]) - μ) (Σ^(-1)) ((OverBar[x]) - μ) 	
In practice, it is necessary to estimate μ and Σ  making a initial evaluation of process. This evaluation consists in taking m samples of size n  when the process is assumed to be in control, (Subscript[x, ijk])  is the i-th observation on the j-th quality characteristic in  k-th sample. The sample means , \(x\&_\_jk\), and variances  (Subscript[S, jk]^2),are calculated from each sample. That is 
 	\(TraditionalForm\`x\&_\_jk\) = (1/n)(∑_(i = 1)^n)(Subscript[x, ijk]), and (Subscript[S, jk]^2)= (1/(n - 1))(∑_(i = 1)^n)((Subscript[x, ijk])-(Subscript[\(x\&_\), jk])), where j = 1, 2, ..., p, k = 1, 2,..., m
The covariance between j and h in k sample is
 
	(Subscript[S, jkh]^2)= (1/(n - 1))(∑_(i = 1)^n)((Subscript[x, ijk])-(Subscript[\(x\&_\), jk]))((Subscript[x, ijh])-(Subscript[\(x\&_\), jh])), with j ≠ h

and the averages \(x\&_\_jk\), (Subscript[S, jk]^2) and (Subscript[S, jhk]) over all m samples are

	\(TraditionalForm\`\(x\&_\)\&_\_j\) = (1/m)(∑_(k = 1)^m)\(x\&_\_jk\), with j = 1,2 ,..., p
	(OverBar[(Subscript[S, j]^2)]) = (1/m)(∑_(k = 1)^m)(Subscript[S, jk]^2), with j = 1,2 ,..., p
	(Subscript[\(S\&_\), jh]) = (1/m)(∑_(k = 1)^m)(Subscript[S, jhk]), with j ≠ h

The {\(TraditionalForm\`\(x\&_\)\&_\_j\)} are the elements of the vector (OverBar[(OverBar[x])]) and the covariance matrices S is formed as

	S = (({{\(\(S\_1\%2\)\&_\), \(S\&_\_12\), \(S\&_\_13\), .., \(S\&_\_\(1  P\)\)}, {□, (OverBar[(Subscript[S, j]^2)]), \(S\&_\_23\), .., \(S\&_\_\(2  P\)\)}, {□, □, (OverBar[(Subscript[S, j]^2)]), .., ..}, {□, □, □, .., (OverBar[(Subscript[S, j]^2)])}}))
	
S is an estimated of Σ when the process is in control. If we replace μ for  (OverBar[(OverBar[x])]) and Σ for S in (Subscript[χ, 0]^2) equation we obtain 

	(T^2)= n ((OverBar[x]) - (OverBar[(OverBar[x])]))' (S^(-1))((OverBar[x]) - (OverBar[(OverBar[x])]))

Also, we need to define the limits. In the initial study of a process these are:  

	UCL = ((p (m  - 1) (n - 1))/(m n - m - p + 1)) 
            (Subscript[F, α,  p, m n - m - p + 1 ]), LCL = 0

This procedure is usually called the Hotelling (T^2) Control Chart.

Performing a T2 Chart

We have a list of the way:  {(Subscript[x, ijk])},  i =1, 2, ..., n, j = 1, 2, ..., p, k = 1, 2,..., m, where the i-th observation on the j-th quality characteristic in  k-th sample. We will need calculate \(TraditionalForm\`x\&_\_jk\) , (Subscript[S, jk]^2), \(TraditionalForm\`\(x\&_\)\&_\_j\), (OverBar[(Subscript[S, j]^2)]) , (Subscript[\(S\&_\), jh]), (S^(-1))and finally  (Subscript[T, k]^2)=n ((Subscript[(OverBar[x]), k])-(OverBar[(OverBar[x])]))'(S^(-1))((Subscript[(OverBar[x]), k])-(OverBar[(OverBar[x])])) where n is the size of sample (or subgroup), (Subscript[(OverBar[x]), k]) = {(Subscript[\(x\&_\), 1  k]), (Subscript[\(x\&_\), 2  k]), ..., (Subscript[\(x\&_\), jk]), ..., (Subscript[\(x\&_\), pk])}, (OverBar[(OverBar[x])]) = {(Subscript[\(\(x\&_\)\&_\), 1]), (Subscript[\(\(x\&_\)\&_\), 2]), ..., (Subscript[\(\(x\&_\)\&_\), j]), ..., (Subscript[\(\(x\&_\)\&_\), p])}, (') =Transpose, and (S^(-1)) is the inverse matrix of covariances S. Finally we will represent these values (Subscript[T, k]^2) comparing then with UCL for an α given .

Example

We will generate a list that represent a multinormal population , 20 samples of size 10, means:{7,4,5,6} and covariances {{1,0.5,0.5,0.5},{0.5,1,0.5,0.5},{0.5,0.5,1,0.5},{0.5,0.5,0.5,1}}.

Needs["Statistics`MultinormalDistribution`"]

ndist = 
        MultinormalDistribution[{7, 4, 5, 6}, 
          {{1, 0.5, 0.5, 0.5}, {0.5, 1, 0.5, 0.5}, {0.5, 0.5, 1, 0.5}, 
            {0.5, 0.5, 0.5, 1}}];

exampleList  := Random[ndist]

data4  = Transpose[Table[Transpose[Table[exampleList, {10}]], {20}]];

Check the list to verify that has the way {p=variables, m = samples or subgroups, n = size each sample}

Dimensions[%]

Now We will obtain (Subscript[T, k]^2) values and represents T2 control chart with alfa = 0.05.

?T2Report

T2Report[data4, 0.05]

?T2Chart

T2Chart[data4, 0.05]

References and Author

Douglas C. Montgomery (1996) Introduction to Statistical Quality Control, 3rd ed., John Wiley&Sons.
International Standards: ISO 7870:1993(E), ISO 8258:1991(E)
Roman E. Maeder. (1996), Programming in Mathematica, 3rd ed., Addison-Wesley.
Wolfram,S.(1998),The Mathematica Book,4rd ed.,Wolfram Media/Cambridge University Press,Champaign,IL.

Control Chart for Variables by Guillermo Sanchez, guillerm@gugu.usal.es
August 1999