43 Calculates the correlation coefficient between xs and ys as
45 sum[(xi-<x>)*(yi-<y>)]
46 r=----------------------
49 where <x>, <y> are the mean of dataset xs and ys, and, sx and sy are the
53 raise RuntimeError(
"Can't calculate correl. Sequence lengths do not match.")
55 raise RuntimeError(
"Can't calculate correl of sequences with length 1.")
58 sigma_x, sigma_y=(0.0, 0.0)
60 for x, y
in zip(xs, ys):
61 cross_term+=(x-mean_x)*(y-mean_y)
62 sigma_x+=(x-mean_x)**2
63 sigma_y+=(y-mean_y)**2
64 sigma_x=math.sqrt(sigma_x)
65 sigma_y=math.sqrt(sigma_y)
66 return cross_term/(sigma_x*sigma_y)