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
working moran plot func #797
Changes from 1 commit
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 |
---|---|---|
@@ -1,6 +1,5 @@ | ||
""" | ||
Moran Plot using PySAL and Matplotlib | ||
|
||
Canned Views using PySAL and Matplotlib | ||
""" | ||
|
||
__author__ = "Marynia Kolak <marynia.kolak@gmail.com>" | ||
|
@@ -15,42 +14,33 @@ def moran(var, w, xlabel='', ylabel='', title='', custom=(5,5)): | |
''' | ||
Produce basic Moran Plot | ||
... | ||
|
||
Arguments | ||
--------- | ||
|
||
var : array | ||
var : array | ||
values of variable | ||
w : array | ||
values of spatial weight | ||
w : spatial weight | ||
''' | ||
|
||
|
||
## really shouldn't have w transformed here -- error if doesn't match size? (MK) | ||
w.transform = 'r' | ||
w.transform = 'r' | ||
slag = ps.lag_spatial(w, var) | ||
|
||
## Z-Score standardisation -- again, how to grab zx and zy from Moran call? (MK) | ||
y_std = (var - var.mean())/var.std() | ||
yl_std = (slag - slag.mean())/slag.std() | ||
zx = (var - var.mean())/var.std() | ||
zy = (slag - slag.mean())/slag.std() | ||
|
||
fit = ps.spreg.OLS(zx[:, None], zy[:,None]) | ||
|
||
## Customize plot | ||
fig1 = plt.figure(figsize=custom) | ||
plt.xlabel(xlabel, fontsize=20) | ||
plt.ylabel(ylabel, fontsize=20) | ||
plt.suptitle(title, fontsize=30) | ||
plt.ylabel(ylabel, fontsize=20) | ||
plt.suptitle(title, fontsize=30) | ||
|
||
plt.scatter(y_std, yl_std, s=60, color='k', alpha=.6) | ||
|
||
## Add Moran line here -- how much do we assume has been done so far? | ||
plt.scatter(zx, zy, s=60, color='k', alpha=.6) | ||
plot(zy, fit.predy, color='r') | ||
|
||
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. We might want to add a linear (and potentially non-linear) fit line. Also, maybe we could add a legend for that line that includes the coefficient for Moran's I (as it's its slope)? At the very least, I'd add the linear fit and maybe introduce an option for a LOESS line, although that'd make us depend on 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. Definitely, the idea with this first pass is just to test the waters and
On Sun, Apr 24, 2016 at 3:26 AM, Dani Arribas-Bel notifications@github.com
|
||
plt.axvline(0, alpha=0.5) | ||
plt.axhline(0, alpha=0.5) | ||
|
||
plt.show() | ||
return None | ||
|
||
|
||
|
||
|
||
|
||
return None |
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.
Would be nice to add a
Returns
section explaining what the output is?