Calculation of COEFFICIENT OF RANK CORRELATION
           and PEARSON'S COEFFICIENT
by David Judson
from Home Computing Weekly, 7th June 1983


Plan ahead, and find out if you were right

Make sense of figures with two practical programs for the Spectrum
by Dave Judson


It's obvious that sales of raincoats drop in fine weather and that sales of
software rise as more home computers are sold. The technique of measuring the
effect of one on the other is called correlation, and the advantage of
knowing the strength of the relationships is that you are better able to make
plans and predictions.

Program 1 for the Spectrum - Coefficient of Ranked Correlation - compares
predicted results with what actually happens. Correlation is measured between
-1 and +1 with, for instance, +0.8 indicating a strong positive correlation
while -0.3 would show only a weak negative correlation.

Ranked information is familiar to us all: Top 20 records, Miss World placings
or 1-2-3 result in a horse race. People in business might see a ranked list
of products.

Here's an example: a range of rust preventatives for cars is recommended to
you in this order, best first:
	Antirot     1st
	Beatrot     2nd
	Counterrot  3rd
	Deadrot     4th
	Eatrot      5th
Test rankings on your company's fleet however indicate:
	Counterrot  1
	Beatrot     2
	Antirot     3
	Eatrot      4
	Deadrot     5
Question: Do you trust the experts who made the preliminary recommendation?

Using the program you will find the coefficient of rank correlation is +0.5,
which indicates only a weak positive correlation between the advice given and
your practical experience.

Why not measure your forecasts of the Grand National result against the
actual placings? If you don't get a strong negative correlation, well done.


Program 1
Variables

t    accumulated variations squared
n    the number of categories of data
c$   category title
e    expected rank or position
a    actual rank or position
d    difference between actual and expected rank
r&r2 coefficient of ranked correlation


Program 2 calculates what is called Pearson's Coefficient, measuring the
correlation - with the same range of results - between two variable sets of
data.
It could, for example, be used like this:

Comparison of expenditure on advertising with sales:
	period  advertising  sales
	        expenditure (units)
	           100s      000s
	   1         20        70
	   2         30       100
	   3         30       110
	   4         40       120
... gives +0.944, a strong positive correlation.

Comparison of ice cream sales with rainfall:
	period  ice cream   rainfall
	         sales      inches
	   1        200        1.5
	   2        200        1.4
	   3        300        1.2
	   4        400        0.8
	   5        400        0.6
... gives -0.969, a strong negative correlation.


Program 1 - How it works
  60      set up number of categories
          (say the top 10 records or first five in a race)
  90-160  input data, square the difference between actual and forecast
          ranking and accumulate sum of the squares
 170-180  calculate the coefficient of rank correlation rounded to one
          decimal place
 190-240  print out your original data and the coefficient of rank
          correlation
 260-290  set out a suggested interpretation


Program 2 - How it works
  10      set counter for data collection loop which follows at line 50
  30-40   enter titles of the two sets of data to be compared
  50-130  collect raw data, period by period; accumulate total for later
          calculation of an arithmetic mean
 133-139  print on screen the data collected for examination before any
          calculations are done; give option of re-start
 160-290  all the number crunching
 340-390  suggest an interpretation of the results
