Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Relative Frequence Code
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Relative Frequence Code
Miscellaneous
Thread ID:
01131214
Message ID:
01131214
Views:
52
I'm taking Statistice for my MBA. We covered how to compute the Relative Frequency and the
Cumulative Relative Frequency.

For those who don't know what this is, imagine the array in the code below represented weights of
boxes to be shipped and you were trying to set prices for shipping by weight category.

First, run the code

The first column are the weights.

The middle column, the Relative Frequency, represents the percentage of the total weight of the
data item in the first column.

The third column, the Cumulative Relative Frequenct, represents the percentage of the total weight of all data items up to that point.

You could then set prices by either the percentage of the total weight for a package, or by a category
consisting of a range of weights.

The output is:
 Data     Relative     Cumulative
 Item     Frequency     Frequency
 -----------------------------------
 120          6.16           6.16
 175          8.98          15.14
 182          9.34          24.48
 187          9.59          34.07
 193          9.90          43.97
 196          10.06         54.03
 210          10.77         64.80
 211          10.83         75.63
 212          10.88         86.51
 263          13.49           100
------
1949
And the code:
CLEAR

DIMENSION aDataItems[10]
aDataItems[01] = 120
aDataItems[02] = 212
aDataItems[03] = 211
aDataItems[04] = 263
aDataItems[05] = 182
aDataItems[06] = 193
aDataItems[07] = 196
aDataItems[08] = 210
aDataItems[09] = 187
aDataItems[10] = 175

nSum = RFreq(@aDataItems)

? "      Data     Relative     Cumulative"
? "      Item     Frequency     Frequency"
? "     " + REPLICATE("-", 35)

** Display the results
FOR nElement = 1 TO ALEN(aDataItems, 1)

	? aDataItems[nElement, 1], aDataItems[nElement, 2], aDataItems[nElement, 3]  

ENDFOR

? "      ------"
? "      " + TRANSFORM(nSum)



********************************************************************************
* PROCEDURE: 	RFreq
* PURPOSE:		Computes the Relative Frequence and the Cumulative Relative
*             Frequencies of a set a numbers.
*
********************************************************************************
PROCEDURE RFreq
LPARAMETERS aDataItems

  ** Define variables
  LOCAL nNumItems, nSum, nData, nFreq, aTemp[1], nRF, nCRF
  nSum = 0
  nRF = 0
  nCRF = 0

  =ASORT(aDataItems)

  ** Determine the number of elements in the array
  nNumItems = ALEN(aDataItems, 1)


  ** Copy the array to a temp array
  DIMENSION aTemp[nNumItems, 3]
  FOR nElement = 1 TO nNumItems
    aTemp[nElement, 1] = aDataItems[nElement]
  ENDFOR


  ** Sum the values
  FOR nElement = 1 TO nNumItems
	nSum = nSum + aTemp[nElement, 1]
  ENDFOR



  ** Next, compute the relative frequency of each item and store it
  ** to the array
  FOR nElement = 1 TO nNumItems

    nData = aTemp[nElement, 1]
    nFreq = (nData / nSum) * 100
    aTemp[nElement, 2] = ROUND(nFreq, 2)

  ENDFOR



  ** Next, compute the cumulative relative frequencies and store them to
  ** the array
  nRF = aTemp[1, 2]
  aTemp[1, 3] = nRF

  FOR nElement = 2 TO nNumItems

    nCRF = nCRF + nRf	
    nRF  = aTemp[nElement, 2]

    aTemp[nElement, 3] = nCRF + nRF

  ENDFOR


  ** Copy thr working array to the parameter array
  DIMENSION aDataItems[nNumItems, 3]
  =ACOPY(aTemp, aDataItems)

RETURN nSum
Everything makes sense in someone's mind
public class SystemCrasher :ICrashable
In addition, an integer field is not for irrational people
Reply
Map
View

Click here to load this message in the networking platform