Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import logging, math
- proc covar(vx, vy : openArray[float]) : float =
- if len(vx) != len(vy) or len(vx) < 2:
- error("Covar requires equal length arrays, length greater than 2.")
- var result : float = 0.0
- var mx = mean(vx)
- var my = mean(vy)
- for i in 0..len(vx)-1:
- var xd = vx[i] - mx
- var yd = vy[i] - my
- result += (xd * yd - result) / (float(i) + 1.0)
- return result
- proc variance(vx : openArray[float]) : float =
- return covar(vx, vx)
- proc correl(vx, vy : openArray[float]) : float =
- return covar(vx, vy) / (sqrt(variance(vx)) * sqrt(variance(vy)))
Advertisement
Add Comment
Please, Sign In to add comment