2

I run into errors with distance-based spatial weights in pysal. When running a spatial lag model (e.g. twosls_sp.GM_Lag), I get the following exception:

Exception: All entries on diagonal must equal 0.

Trying the example here, the diagonal is 1 (i.e., an observation is also its own neighbor), and the output is different from that given in the docs:

import pysal
points=[(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)]
w = pysal.DistanceBand(points,threshold=11.2,binary=False)
w.weights[0]
    [0.10000000000000001, inf, 0.089442719099991588]
w.neighbors[0]
    [1, 0, 3]

After row standardization, there are only zeros and nans in the weights matrix:

 w.transform = 'r'
 w.weights[0]
     [0.0, nan, 0.0]

Is this a bug in pysal, or likely a problem with my installation?

I am running the Enthought Canopy Python installation, with pysal installed separately, on a Mac OSX 10.8. Pysal is v1.11.0.

2

This is a bug that is currently being addressed.

| improve this answer | |
2

The workaround I found is to use the insert_diagonal function. I'm still curious whether there is a problem with my pysal installation, however.

import pysal
import numpy as np
points=[(10, 10), (20, 10), (40, 10), (15, 20), (30, 20), (30, 30)]
w = pysal.DistanceBand(points,threshold=11.2,binary=False)
w.weights[0]
    [0.10000000000000001, inf, 0.089442719099991588]
w = pysal.weights.insert_diagonal(w, np.zeros(w.n))
w.weights[0]
    array([ 0.1       ,  0.08944272])
w.neighbors[0]
    [1, 3]

The new output is the same as the documented example, but I shouldn't need to manually modify the diagonal.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.