From: Heng Li Date: Thu, 21 Apr 2011 03:40:52 +0000 (-0400) Subject: added Spearman coefficient X-Git-Tag: ksprintf-final~49 X-Git-Url: http://www.kaiwu.me/postgresql/commit/?a=commitdiff_plain;h=c547611fb9fe7d038c8d11f5a52ee8e18d6e308d;p=klib.git added Spearman coefficient --- diff --git a/lua/klib.lua b/lua/klib.lua index 68e5d37..6a4bdd7 100644 --- a/lua/klib.lua +++ b/lua/klib.lua @@ -40,7 +40,6 @@ io.xopen() table.ksmall() table.shuffle() - table.pearson() math.lgamma() >math.lbinom() >math.igamma() math.igamma() matrix.chi2() math.erfc() @@ -48,6 +47,8 @@ math.bernstein_poly() 1 then T[k], same = T[k] + aux_func(same), 1 end + end + end + S[k] = aux_func(#a) - T[k] + end + -- compute the coefficient + local sum = 0 + for _, v in pairs(a) do -- TODO: use nested loops to reduce loss of precision + local t = (v.r[1] - v.r[2]) / 2 + sum = sum + t * t + end + return (S[1] + S[2] - sum) / 2 / math.sqrt(S[1] * S[2]) +end + -- Description: Hooke-Jeeves derivative-free optimization function math.fmin(func, x, data, r, eps, max_calls) local n, n_calls = #x, 0;