Tool for Quality Control Design and Evaluation

minfn=(10^(-100));

pce[em_,m_,s_,taae_]:=NIntegrate[((E^(-((((-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,-Infinity,em(1-taae)}]+NIntegrate[((E^(-((((-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,em(1+taae),Infinity}]

ped[em_,m_,s_,d_,dm_,sd_,c_]:=If[m<em,1-(((1-NIntegrate[((E^(-((((dm-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,-Infinity,m-d s}]-NIntegrate[((E^(-((((dm-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,m+d s,Infinity}]))^c),1-(((1-NIntegrate[((E^(-((((-dm-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,-Infinity,m-d s}]-NIntegrate[((E^(-((((-dm-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,m+d s,Infinity}]))^c)]

qc[em_,m_,s_,taae_,a_,minpsed_,minpred_, c_]:=Module[{ra,dr,sa,ds, sd,d,dd,bias},ra=sd/.FindRoot[NIntegrate[((E^(-((((-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,-Infinity,em(1-taae)}]+NIntegrate[((E^(-((((-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,em(1+taae),Infinity}]==a,{sd,s,20s,0,30 s},AccuracyGoal->100,PrecisionGoal->100];dr=d/.FindRoot[(((1-NIntegrate[((E^(-((((-m+x))^2)/(2 (ra^2)))))/((Sqrt[2 π]) ra)),{x,-Infinity,m-d s}]-NIntegrate[((E^(-((((-m+x))^2)/(2 (ra^2)))))/((Sqrt[2 π]) ra)),{x,m+d s,Infinity}]))^c)==1-minpred,{d,1 ,20 ,0,30 }];
sa=bias/.If[m<em,FindRoot[NIntegrate[((E^(-((((bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,-Infinity,em(1-taae)}]+NIntegrate[((E^(-((((bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,em(1+taae),Infinity}]==a,{bias,1s,20s,0,30 s},AccuracyGoal->100,PrecisionGoal->100],FindRoot[NIntegrate[((E^(-((((-bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,-Infinity,em(1-taae)}]+NIntegrate[((E^(-((((-bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,em(1+taae),Infinity}]==a,{bias,1s,20 s,0,30 s}]];
ds=dd/.If[m<em,FindRoot[(((1-NIntegrate[((E^(-((((-m+sa+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,-Infinity,m-dd s}]-NIntegrate[((E^(-((((-m+sa+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,m+dd s,Infinity}]))^c)==1-minpsed,{dd,1,20,0,30}],FindRoot[(((1-NIntegrate[((E^(-((((-m-sa+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,-Infinity,m-dd s}]-NIntegrate[((E^(-((((-m-sa+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,m+dd s,Infinity}]))^c)==1-minpsed,{dd,1,20,0,30}]];
Min[dr,ds]]

Manipulate[
Quiet[
taae=ptaae/100;
fn=pce[em,m,s,taae];
If[minfn⩽fn⩽a,
Which[
type==0,
rc=sd/.FindRoot[NIntegrate[((E^(-((((-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,-Infinity,em(1-taae)}]+NIntegrate[((E^(-((((-m+x))^2)/(2 (sd^2)))))/((Sqrt[2 π]) sd)),{x,em(1+taae),Infinity}]==a,{sd,s,20s,0,30 s}];
sc=bias/.If[m<em,FindRoot[NIntegrate[((E^(-((((bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,-Infinity,em(1-taae)},AccuracyGoal->100,PrecisionGoal->100]+NIntegrate[((E^(-((((bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,em(1+taae),Infinity},AccuracyGoal->100,PrecisionGoal->100]==a,{bias,1s,20 s,0,30 s},AccuracyGoal->100,PrecisionGoal->100],FindRoot[NIntegrate[((E^(-((((-bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,-Infinity,em(1-taae)},AccuracyGoal->100,PrecisionGoal->100]+NIntegrate[((E^(-((((-bias-m+x))^2)/(2 (s^2)))))/((Sqrt[2 π]) s)),{x,em(1+taae),Infinity},AccuracyGoal->100,PrecisionGoal->100]==a,{bias,1s,20 s,0,30 s},AccuracyGoal->100,PrecisionGoal->100]];
d=qc[em,m,s,taae,a,minpsed,minpred,c];
pfr=ped[em,m,s,d,0,s,c];
pred=ped[em,m,s,d,0,rc,c];
psed =ped[em,m,s,d,sc,s,c];
Pane[
Text@Grid[{{Style["measurement process parameters",Bold, Larger]},{"fraction nonconforming ",fn},{"critical random error ",NumberForm[rc,{6,2}]},
{"critical systematic error ",NumberForm[sc,{6,2}]},{Style["\nquality control parameters",Bold, Larger]},{Style["quality control rule ",Bold,Blue],Style[StringJoin["S(1, ",ToString[c],", ",ToString[NumberForm[d,{4,2}]]," σ)"],Bold,Blue]},{Style["lower quality control decision limit ",Bold,Red],Style[NumberForm[m-d s,{6,2}],Bold,Red]},{Style["upper quality control decision limit ",Bold,Red],Style[NumberForm[m+d s,{6,2}],Bold,Red]},{"probability for critical random error detection ",NumberForm[pred,{6,2}]},{"probability for critical systematic error detection",NumberForm[psed,{6,2}]},
{"probability for false rejection ",N[pfr,{6,6}]}},Alignment->{Left}],ImageSize->{500,250}],
type==1,
Plot[Tooltip[PDF[NormalDistribution[m,s],x],"pdf of the control measurements"],{x,m-2 sc,m+2 sc},AspectRatio->1,PlotLabel->"probability density function (pdf)",PlotStyle->{ColorData["HTML","SlateBlue"], RGBColor[1,.47,0]} ,Filling->Bottom,ImageSize->{500,250}],
type==2,
Plot[Tooltip[CDF[NormalDistribution[m,s],x],"cdf of the control measurements"],{x,m-2 sc,m+2 sc},AspectRatio->1,PlotLabel->"cumulative density function (cdf)",PlotStyle->{ColorData["HTML","SlateBlue"], RGBColor[1,.47,0]} ,Filling->Bottom,ImageSize->{500,250}],
type==3,
ds=qc[em,m,s,taae,a,minpsed,minpred,c];
Plot[Tooltip[ped[em,m,s,d,0,x,c],"pfg for the random error"],{x,1,2 sc},AxesLabel->{"re","ped"},AspectRatio->1,PlotLabel->"power function graph (pfg)",PlotStyle->{ColorData["HTML","Brown"]} ,FillingStyle->LightBrown,Filling->Bottom,ImageSize->{500,250}],
type==4,
ds=qc[em,m,s,taae,a,minpsed,minpred,c];
Plot[Tooltip[ped[em,m,s,d,x,s,c],"pfg for the random error"],{x,0,2rc},AxesLabel->{"se","ped"},AspectRatio->1,PlotLabel->"power function graph (pfg)",PlotStyle->{ColorData["HTML","Brown"]} ,Filling->Bottom,FillingStyle->LightBrown,ImageSize->{500,250}]],
If[fn>a,
Pane[Text@Grid[{{"fraction nonconforming",fn},{Style["the fraction nonconforming is not acceptable",Bold,Red, Larger]}},Alignment->{Left,Left}],ImageSize->{500,250}],Pane[Text@Grid[{{"fraction nonconforming < (10^(-100))"},{Style["The fraction nonconforming is too small for this Demonstration.",Bold,Red, Larger]}},Alignment->{Left,Left}],ImageSize->{500,250}]]]],
{{type,0,"output"},{0->"qc parameters",1->"pdf",2->"cdf",3->"pfg re", 4->"pfg se"}},
Style["parameters of the control measurements (in measurement units) ",Bold],
{{em,100,"assigned mean (Subscript[m, a])"},0.001,100000,ImageSize->Tiny,Appearance->"Labeled"},
{{m,99,"observed mean (Subscript[m, o])"},0.001,100000,ImageSize->Tiny,Appearance->"Labeled"},
{{s,1.5,"standard deviation σ"},0.001,100000,ImageSize->Tiny,Appearance->"Labeled"},
Style["quality specifications",Bold],
{{ptaae,10,"total allowable analytical error p (%)"},0.0001,200,1,ImageSize->Tiny,Appearance->"Labeled"},
{{a,0.1,"maximum fraction nonconforming (Subscript[f, max])"},0.01,1,.01,ImageSize->Tiny,Appearance->"Labeled"},
{{minpred,0.5,"minimum probability for critical random error detection (Subscript[r, min])"},0.01,0.999999,.01,ImageSize->Tiny,Appearance->"Labeled"},
{{minpsed,0.9,"minimum probability for critical systematic error detection (Subscript[s, min])"},0.01,0.999999,.01,ImageSize->Tiny,Appearance->"Labeled"},
Style["number of control measurements",Bold],
{{c,1,"control measurements"},{1,2,3,4,5,6}},ControlPlacement->Top,
SaveDefinitions->True,SynchronousUpdating->False,TrackedSymbols->True,
AutorunSequencing->{1}]

This Demonstration can be used to estimate various parameters of a measurement process and to design the quality control rule to be applied. You define the parameters of the control measurements that are the assigned mean, the observed mean, and the standard deviation, in arbitrary measurement units. In addition, you define the quality specifications of the measurement process, that is, the total allowable analytical error (as a percentage of the assigned mean), the maximum acceptable fraction of measurements nonconforming to the specifications, and the minimum acceptable probabilities for random and systematic error detection. Finally, you choose the number n of control measurements.

S(1,n,d σ) is a quality control rule that rejects the analytical run if at least one of the c control measurements is less than (Subscript[m, o])-d σ or greater than (Subscript[m, o])+d σ, where d is a positive real number and (Subscript[m, o]) and σ are the mean and the standard deviation of the control measurements. The quantities (Subscript[m, o])-d σ and (Subscript[m, o])+d σ are the lower and the upper quality control decision limits. Then the fraction nonconforming f, the critical random and systematic errors of the measurement process, as well as the quality control decision limits and the respective probabilities for critical random and systematic error detection and for false rejection are estimated. Finally, by choosing the type of output, you can see the estimated quality control (qc) parameters or plot the probability density function (pdf), the cumulative density function (cdf) of the control measurements, or the power function graphs for the random error (pfg re) and systematic error (pfg se).

The parameters are estimated and the functions are plotted if (10^(-100))≤f≤(Subscript[f, max]), where f is the fraction nonconforming and (Subscript[f, max]) is the maximum acceptable fraction nonconforming.