From c547611fb9fe7d038c8d11f5a52ee8e18d6e308d Mon Sep 17 00:00:00 2001 From: Heng Li Date: Wed, 20 Apr 2011 23:40:52 -0400 Subject: [PATCH] added Spearman coefficient --- lua/klib.lua | 68 +++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 52 insertions(+), 16 deletions(-) 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; -- 2.47.3