Kbase P16028: How to calculate the Standard Deviation using 4GL?
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  02/02/2003 |
|
Status: Unverified
GOAL:
How to calculate the Standard Deviation using 4GL?
FIX:
The standard deviation of a collection of numbers is the square root of their Variance.
The variance is a statistical measure of variation or dispersion or scatter of set of values from their mean (arithmetic average).
The variance computation varies depending on whether the data being considered is a sample or the whole population.
The following procedure demonstrates a way to compute the Standard Deviation of a collection of numbers given as the elements of an array.
/***4GL Procedure to calculate the Standard Deviation***/
DEFINE VARIABLE dArray AS DECIMAL EXTENT 3 INITIAL [1, 2, 3] NO-UNDO.
DEFINE VARIABLE lSample AS LOGICAL NO-UNDO INITIAL TRUE.
DEFINE VARIABLE iCounter AS INTEGER NO-UNDO.
DEFINE VARIABLE dTotal AS DECIMAL NO-UNDO.
DEFINE VARIABLE dMean AS DECIMAL NO-UNDO.
DEFINE VARIABLE dVariance AS DECIMAL NO-UNDO.
DEFINE VARIABLE dStdDeviation AS DECIMAL NO-UNDO.
/* Calculate the total of the array elements */
ASSIGN
dTotal = 0.
DO iCounter = 1 TO EXTENT(dArray):
dTotal = dTotal + dArray[iCounter].
END.
/* Calculate the Average (Mean) of the array elements */
ASSIGN
dMean = dTotal / EXTENT(dArray).
/* Calculate the total squared deviation */
ASSIGN
dTotal = 0.
DO iCounter = 1 TO EXTENT(dArray):
dTotal = dTotal + EXP(dArray[iCounter] - dMean , 2).
END.
/* Calculate the Variance */
IF lSample THEN
ASSIGN
/* If only a sample population is used: */
dVariance = dTotal / (EXTENT(dArray) - 1).
ELSE
/* If the whole population is used: */
dVariance = dTotal / EXTENT(dArray).
/* Calculate the Standard Deviation */
dStdDeviation = SQRT(dVariance).
MESSAGE dStdDeviation
VIEW-AS ALERT-BOX INFO BUTTONS OK.
/*******************************************************************/