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 of at least 2.")
- let mx = mean(vx)
- let my = mean(vy)
- for i in 0..high(vx):
- let xd = vx[i] - mx
- let yd = vy[i] - my
- result += (xd * yd - result) / float(i + 1)
- proc variance(vx: openArray[float]) : float =
- covar(vx, vx)
- proc correl(vx, vy: openArray[float]) : float =
- covar(vx, vy) / (sqrt(variance(vx)) * sqrt(variance(vy)))
Advertisement
Add Comment
Please, Sign In to add comment