-
Notifications
You must be signed in to change notification settings - Fork 60
adding alternative option in local_moran and moral_local_rate #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
22ed3af
cdcd839
f197358
c4892d9
5b4435d
a89ae03
f3c9a1c
1ae6263
68595a3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -509,9 +509,7 @@ def by_col( | |||||||
def Moran_BV_matrix(variables, w, permutations=0, varnames=None): | ||||||||
""" | ||||||||
Bivariate Moran Matrix | ||||||||
|
||||||||
Calculates bivariate Moran between all pairs of a set of variables. | ||||||||
|
||||||||
Parameters | ||||||||
---------- | ||||||||
variables : array or pandas.DataFrame | ||||||||
|
@@ -531,36 +529,24 @@ def Moran_BV_matrix(variables, w, permutations=0, varnames=None): | |||||||
results : dictionary | ||||||||
(i, j) is the key for the pair of variables, values are | ||||||||
the Moran_BV objects. | ||||||||
|
||||||||
Examples | ||||||||
-------- | ||||||||
|
||||||||
open dbf | ||||||||
|
||||||||
>>> import libpysal | ||||||||
>>> f = libpysal.io.open(libpysal.examples.get_path("sids2.dbf")) | ||||||||
|
||||||||
pull of selected variables from dbf and create numpy arrays for each | ||||||||
|
||||||||
>>> varnames = ['SIDR74', 'SIDR79', 'NWR74', 'NWR79'] | ||||||||
>>> vars = [np.array(f.by_col[var]) for var in varnames] | ||||||||
|
||||||||
create a contiguity matrix from an external gal file | ||||||||
|
||||||||
>>> w = libpysal.io.open(libpysal.examples.get_path("sids2.gal")).read() | ||||||||
|
||||||||
create an instance of Moran_BV_matrix | ||||||||
|
||||||||
>>> from esda.moran import Moran_BV_matrix | ||||||||
>>> res = Moran_BV_matrix(vars, w, varnames = varnames) | ||||||||
|
||||||||
check values | ||||||||
|
||||||||
>>> round(res[(0, 1)].I,7) | ||||||||
0.1936261 | ||||||||
>>> round(res[(3, 0)].I,7) | ||||||||
0.3770138 | ||||||||
|
||||||||
""" | ||||||||
try: | ||||||||
# check if pandas is installed | ||||||||
|
@@ -889,6 +875,9 @@ class Moran_Local(object): | |||||||
value to use as a weight for the "fake" neighbor for every island. If numpy.nan, | ||||||||
will propagate to the final local statistic depending on the `stat_func`. If 0, then | ||||||||
the lag is always zero for islands. | ||||||||
alternative: string | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
This follows the pattern used above. |
||||||||
possible values -> "one-tailed"/ "two-tailed" | ||||||||
default value ->"two-tailed" | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this part should contain a description of what the argument controls, i.e. what does it mean if I use |
||||||||
|
||||||||
Attributes | ||||||||
---------- | ||||||||
|
@@ -1005,6 +994,7 @@ def __init__( | |||||||
keep_simulations=True, | ||||||||
seed=None, | ||||||||
island_weight=0, | ||||||||
alternative = "two-tailed" | ||||||||
): | ||||||||
y = np.asarray(y).flatten() | ||||||||
self.y = y | ||||||||
|
@@ -1063,6 +1053,12 @@ def __init__( | |||||||
self.VI_sim = np.nan | ||||||||
self.z_sim = np.nan | ||||||||
self.p_z_sim = np.nan | ||||||||
if alternative=="one-tailed": | ||||||||
self.p_z_sim= self.p_z_sim*2 | ||||||||
folded_replicates = np.abs(self.rlisas - np.median(self.rlisas, axis=1, keepdims=True)) | ||||||||
self.p_sim = (folded_replicates >= np.abs(self.Is[:,None])).mean(axis=1) | ||||||||
|
||||||||
|
||||||||
|
||||||||
def __calc(self, w, z): | ||||||||
zl = slag(w, z) | ||||||||
|
@@ -1575,6 +1571,7 @@ def __init__( | |||||||
keep_simulations=True, | ||||||||
seed=None, | ||||||||
island_weight=0, | ||||||||
alternative="two-tailed" | ||||||||
): | ||||||||
e = np.asarray(e).flatten() | ||||||||
b = np.asarray(b).flatten() | ||||||||
|
@@ -1592,6 +1589,7 @@ def __init__( | |||||||
n_jobs=n_jobs, | ||||||||
keep_simulations=keep_simulations, | ||||||||
seed=seed, | ||||||||
alternative=alternative | ||||||||
) | ||||||||
|
||||||||
@classmethod | ||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that your editor removed blank lines in the docstring. Can you please put them back (all of them)?