adding kurtosis
This commit is contained in:
parent
7f63688a2f
commit
49c4cea4e7
33
scripts-available/CDB_Stats.sql
Normal file
33
scripts-available/CDB_Stats.sql
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
--
|
||||||
|
-- Calculate the Pearson kurtosis of the input data
|
||||||
|
--
|
||||||
|
-- @param in_array A numeric array of numbers to determine the best
|
||||||
|
-- to determine the bin boundary
|
||||||
|
--
|
||||||
|
-- @param breaks The number of bins you want to find.
|
||||||
|
--
|
||||||
|
--
|
||||||
|
-- Returns: upper edges of bins
|
||||||
|
--
|
||||||
|
--
|
||||||
|
|
||||||
|
CREATE OR REPLACE FUNCTION CDB_Kurtosis ( in_array NUMERIC[] ) RETURNS NUMERIC as $$
|
||||||
|
DECLARE
|
||||||
|
a numeric;
|
||||||
|
c numeric;
|
||||||
|
s numeric;
|
||||||
|
k numeric;
|
||||||
|
BEGIN
|
||||||
|
SELECT AVG(e), COUNT(e)::numeric, stddev(e) INTO a, c, s FROM ( SELECT unnest(in_array) e ) x;
|
||||||
|
|
||||||
|
RAISE NOTICE 'avg: %, cnt: %, std: %', a, c, s;
|
||||||
|
|
||||||
|
EXECUTE '
|
||||||
|
SELECT sum(power($1 - e,4)) / ( $2 * power($3, 4))
|
||||||
|
FROM (SELECT unnest($4) e ) x'
|
||||||
|
INTO k
|
||||||
|
USING a, c, s, in_array;
|
||||||
|
|
||||||
|
RETURN k;
|
||||||
|
END;
|
||||||
|
$$ language plpgsql IMMUTABLE;
|
Loading…
Reference in New Issue
Block a user