Statistical dataprocessing for process control

When you have a process to manage, you need to know how good your equipment is. Therefore parameters have been
defined that do so.

The best known parameter is the average. It tells us the direction we're heading for. But a good average is
not enough. A range of data is nice to know. But a range alone tells us nothing about the way in which the
data fit in the specification. Therefore we have the standard deviation.

But a good std dev alone is not enough, if you need to pay money for a certain commodity. Therefore the Cpk
has been invented. It tells us how well a certain lot fits in our allowed margins.

If you need to know more about this all, just get yourself some good math books and get a real background.
Just remember that you have instant access to these parameters when you use Modula-2.

DEFINITION MODULE for statistical functions

DEFINITION MODULE Statistics; (* This is FREE software, as described in the GNU General Public Licences. Therefore it comes WITH THE FULL SOURCES. Please feel free to improve this code when necessary. You OWN this code. I am not Bill Gates. I would appreciate that people let in this message when extending this library, as a small tribute to me (for laying the foundation). In case people need extra information, contact me via: snail mail: Jan Verhoeven, 5012 GH 272, The Netherlands electronic mail: I remain full copyrights to these sources. If you want to send me a small "thanks", please send me a postcard of your hometown to the above shown snailmail address. Yes it is in code; the internal code of our national mail deliverer. Use this software at your own risk. Please find yourself a GNU GPL if you are in any doubt. I use these functions for all my own software, but there is NO GUARANTEE OF ANY KIND covering it. *) PROCEDURE Square (value : REAL) : REAL; (* Calculate the square of a number *) PROCEDURE Average (Data : ARRAY OF REAL; Samples : CARDINAL) : REAL; (* Calculate the average over [Samples] values, stored in array [Data]. *) PROCEDURE Range (Data : ARRAY OF REAL; Samples : CARDINAL) : REAL; (* Determine the range of the datapoints *) PROCEDURE StdDev (Data : ARRAY OF REAL; Samples : CARDINAL) : REAL; (* Determine the Standard Deviation of a set of samples (n-1 method). *) PROCEDURE Cpk (USL, LSL, Avg, StdDev : REAL) : REAL; (* Determine Cpk value for this set of data. *) END Statistics.

IMPLEMENTATION MODULE for statistical functions

I cut away almost the full GPL notice to keep this document somewhat shorter. If you need to know about the
GPL, just look in the section above which handles the
` DEFINITION MODULE`,
or click on
this link.

IMPLEMENTATION MODULE Statistics; (* This is FREE software, as described in the GNU General Public Licences. ...etcetera... is NO GUARANTEE OF ANY KIND covering it. *) FROM MathLib0 IMPORT sqrt; PROCEDURE Square (value : REAL) : REAL; (* Calculate the square of a number *) BEGIN RETURN value * value END Square; PROCEDURE Average (Data : ARRAY OF REAL; Samples : CARDINAL) : REAL; (* Calculate the average over 'Samples' values, stored in array 'Data'. *) VAR sum : REAL; n : CARDINAL; BEGIN sum := 0.0; FOR n := 0 TO Samples - 1 DO sum := sum + Data [n] END; RETURN sum / FLOAT (Samples) END Average; PROCEDURE Range (Data : ARRAY OF REAL; Samples : CARDINAL) : REAL; (* Determine the range of the datapoints *) VAR Lowest, Highest : REAL; n : CARDINAL; BEGIN Lowest := Data [0]; Highest := Data [0]; FOR n := 0 TO Samples - 1 DO IF Data [n] > Highest THEN Highest := Data [n] END; IF Data [n] < Lowest THEN Lowest := Data [n] END END; RETURN Highest - Lowest END Range; PROCEDURE StdDev (Data : ARRAY OF REAL; Samples : CARDINAL) : REAL; (* Determine the Standard Deviation of a set of samples (n-1 method). *) VAR n : CARDINAL; sum, avg : REAL; BEGIN avg := Average (Data, Samples); sum := 0.0; FOR n := 0 TO Samples - 1 DO sum := sum + Square (avg - Data [n]) END; RETURN sqrt (sum / (FLOAT (Samples - 1))) END StdDev; PROCEDURE Cpk (USL, LSL, Avg, StdDev : REAL) : REAL; (* Determine Cpk value for this set of data. *) VAR dL, dU, delta : REAL; BEGIN dU := USL - Avg; (* gap between Average and USL *) dL := Avg - LSL; (* gap between Average and LSL *) IF dU > dL THEN delta := dL ELSE delta := dU (* Determine smallest gap *) END; RETURN delta / (3.0 * StdDev) (* Cpk is the "safety margin" *) END Cpk; END Statistics.

Page created 2002 and