new signatures for moran (w/o significance)

This commit is contained in:
Andy Eschbacher 2016-03-22 10:34:22 -04:00
parent 8762f6ca1c
commit 3eda8ecd16

View File

@ -1,37 +1,89 @@
-- Moran's I -- Moran's I (global)
CREATE OR REPLACE FUNCTION CREATE OR REPLACE FUNCTION
cdb_moran_local ( cdb_moran (
t TEXT, subquery TEXT,
attr TEXT, attr_name TEXT,
significance float DEFAULT 0.05,
num_ngbrs INT DEFAULT 5,
permutations INT DEFAULT 99, permutations INT DEFAULT 99,
geom_column TEXT DEFAULT 'the_geom', geom_col TEXT DEFAULT 'the_geom',
id_col TEXT DEFAULT 'cartodb_id', id_col TEXT DEFAULT 'cartodb_id',
w_type TEXT DEFAULT 'knn') w_type TEXT DEFAULT 'knn',
num_ngbrs INT DEFAULT 5)
RETURNS TABLE (moran FLOAT, quads TEXT, significance FLOAT, ids INT) RETURNS TABLE (moran FLOAT, quads TEXT, significance FLOAT, ids INT)
AS $$ AS $$
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
from crankshaft.clustering import moran_local from crankshaft.clustering import moran_local
# TODO: use named parameters or a dictionary # TODO: use named parameters or a dictionary
return moran_local(t, attr, significance, num_ngbrs, permutations, geom_column, id_col, w_type) return moran(subquery, attr, num_ngbrs, permutations, geom_col, id_col, w_type)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
-- Moran's I Local
CREATE OR REPLACE FUNCTION
cdb_moran_local (
subquery TEXT,
attr TEXT,
permutations INT DEFAULT 99,
geom_col TEXT DEFAULT 'the_geom',
id_col TEXT DEFAULT 'cartodb_id',
w_type TEXT DEFAULT 'knn',
num_ngbrs INT DEFAULT 5)
RETURNS TABLE (moran NUMERIC, quads TEXT, significance NUMERIC, ids INT, y NUMERIC)
AS $$
from crankshaft.clustering import moran_local
# TODO: use named parameters or a dictionary
return moran_local(subquery, attr, permutations, geom_col, id_col, w_type, num_ngbrs)
$$ LANGUAGE plpythonu;
-- Moran's I Rate (global)
CREATE OR REPLACE FUNCTION
cdb_moran_rate (
subquery TEXT,
numerator TEXT,
denominator TEXT,
permutations INT DEFAULT 99,
geom_col TEXT DEFAULT 'the_geom',
id_col TEXT DEFAULT 'cartodb_id',
w_type TEXT DEFAULT 'knn',
num_ngbrs INT DEFAULT 5)
RETURNS TABLE (moran FLOAT, quads TEXT, significance FLOAT, ids INT)
AS $$
from crankshaft.clustering import moran_local
# TODO: use named parameters or a dictionary
return moran_rate(subquery, numerator, denominator, permutations, geom_col, id_col, w_type, num_ngbrs)
$$ LANGUAGE plpythonu;
-- Moran's I Local Rate -- Moran's I Local Rate
CREATE OR REPLACE FUNCTION CREATE OR REPLACE FUNCTION
cdb_moran_local_rate(t TEXT, cdb_moran_local_rate(
subquery TEXT,
numerator TEXT, numerator TEXT,
denominator TEXT, denominator TEXT,
significance FLOAT DEFAULT 0.05,
num_ngbrs INT DEFAULT 5,
permutations INT DEFAULT 99, permutations INT DEFAULT 99,
geom_column TEXT DEFAULT 'the_geom', geom_col TEXT DEFAULT 'the_geom',
id_col TEXT DEFAULT 'cartodb_id', id_col TEXT DEFAULT 'cartodb_id',
w_type TEXT DEFAULT 'knn') w_type TEXT DEFAULT 'knn',
RETURNS TABLE(moran FLOAT, quads TEXT, significance FLOAT, ids INT, y numeric) num_ngbrs INT DEFAULT 5)
RETURNS
TABLE(moran NUMERIC, quads TEXT, significance NUMERIC, ids INT, y NUMERIC)
AS $$ AS $$
plpy.execute('SELECT cdb_crankshaft._cdb_crankshaft_activate_py()')
from crankshaft.clustering import moran_local_rate from crankshaft.clustering import moran_local_rate
# TODO: use named parameters or a dictionary # TODO: use named parameters or a dictionary
return moran_local_rate(t, numerator, denominator, significance, num_ngbrs, permutations, geom_column, id_col, w_type) return moran_local_rate(subquery, numerator, denominator, permutations, geom_col, id_col, w_type, num_ngbrs)
$$ LANGUAGE plpythonu; $$ LANGUAGE plpythonu;
-- -- Moran's I Local Bivariate
-- CREATE OR REPLACE FUNCTION
-- cdb_moran_local_bv(
-- subquery TEXT,
-- attr1 TEXT,
-- attr2 TEXT,
-- permutations INT DEFAULT 99,
-- geom_col TEXT DEFAULT 'the_geom',
-- id_col TEXT DEFAULT 'cartodb_id',
-- w_type TEXT DEFAULT 'knn',
-- num_ngbrs INT DEFAULT 5)
-- RETURNS TABLE(moran FLOAT, quads TEXT, significance FLOAT, ids INT, y numeric)
-- AS $$
-- from crankshaft.clustering import moran_local_bv
-- # TODO: use named parameters or a dictionary
-- return moran_local_bv(t, attr1, attr2, permutations, geom_col, id_col, w_type, num_ngbrs)
-- $$ LANGUAGE plpythonu;