Skip to content
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

Spatial_Pearson issue #268

Open
rudyarthur opened this issue Sep 21, 2023 · 1 comment
Open

Spatial_Pearson issue #268

rudyarthur opened this issue Sep 21, 2023 · 1 comment

Comments

@rudyarthur
Copy link

rudyarthur commented Sep 21, 2023

from scipy import sparse
import libpysal
import esda

print(libpysal.__version__)
print(esda.__version__)

x = np.array([[1,1],
			  [0,1]])
y = np.array([[0,1],
			  [1,1]])
w = np.array([[0,1,1,0],
			  [1,0,0,1],
			  [1,0,0,1],
			  [0,1,1,0]])
sw = sparse.csr_matrix(w)

from esda.lee import Spatial_Pearson

sp = Spatial_Pearson()
sp.fit(x,y)
print(sp.association_)

sp = Spatial_Pearson(sw)
sp.fit(x,y)
print(sp.association_)

The above with pysal version 4.7.0 and esda version 2.5.0 doesn't produce what it ought to. The first fit returns a 4x4 array where the docs say to expect a 2x2. The second crashes with "dimension mismatch" error.

Looking at the code in lee.py I think the x and y inputs need to be flattened. The default connectivity is the unit matrix which is probably never what is required in practice. I'd suggest requiring the user to input the spatial weight matrix as in the moran code.

Cheers,
Rudy

@ljwolf
Copy link
Member

ljwolf commented Sep 25, 2023

Thanks for the report!

The input x and y arrays must be of shape (n,1). So, I think the flattening should happen in the user code.

We can definitely improve documentation and force the validation step to catch this, however!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants