October 2006
Intermediate to advanced
888 pages
16h 55m
English
The correlation coefficient is one of the simplest and most universally useful statistical measures. It is a measure of the “linearity” of a set of x-y pairs, ranging from -1.0 (complete negative correlation) to +1.0 (complete positive correlation).
We compute this using the mean and sigma (standard deviation) functions defined previously in sections 5.25 and 5.26. For an explanation of this tool, consult any statistics text.
The following version assumes two arrays of numbers (of the same size):
def correlate(x,y) sum = 0.0 x.each_index do |i| sum += x[i]*y[i] end xymean = sum/x.size.to_f xmean = mean(x) ymean = mean(y) sx = sigma(x) sy = sigma(y) (xymean-(xmean*ymean))/(sx*sy) end a = [3, 6, 9, 12, 15, ...
Read now
Unlock full access