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

Ability to specify categories / ranges in spatial markov method #721

Closed
stuartlynn opened this issue Nov 30, 2015 · 5 comments
Closed

Ability to specify categories / ranges in spatial markov method #721

stuartlynn opened this issue Nov 30, 2015 · 5 comments

Comments

@stuartlynn
Copy link
Contributor

Right now the spatial markov methods calculate the quantile bins for the markov chain. It would be great to have the option to pass through either a list of bins or categories for the data. So for example

 bins = [0,10, 20 ,30 ,40 ,50 ,60 ,70, 80, 90, 100]
 sm = pysal.Spatial_Markov(data, weights, bins= bins, fixed = True)

or

categories = [ 'republican', 'democrat']
sm = pysal.Spatial_Markov(data, weights, categories= categories, fixed = True)    

Where the data for a geometry in the first would be numbers in the range 0 ... 100 which would get mapped to the specified bins and in the second example each step in the input data would be either republican or democrat and the chain would calculate the probabilities of switching between the two.

@ljwolf
Copy link
Member

ljwolf commented Nov 30, 2015

@sjsrey I think this might be done well by breaking off l403-l410 into a _classify() method that could get passed over by providing the categories ahead of time. If we make this a separate callable, it'd also make it easy to subclass into your own classifier method, defining

class YourMarkov(pysal.Spatial_Markov):
... init-ing goes here ...
    def _classify(self, k):
           return np.random.randint(0,k, size=len(self.y))

or what have you.

@sjsrey
Copy link
Member

sjsrey commented Nov 30, 2015

@ljwolf yes, adding a general _classify() method would allow for user specified classes.

There are a few things we should keep in mind, however, related to the request from @stuartlynn. First, is that the spatial markov method assumes the attribute is continuous not discrete as it uses the spatial lag. For discrete values, the interpretation of the lag is not straightforward.

Second, the current implement uses quantiles so that the alternative and null hypotheses are clear. H0 is that there is only one kxk transition matrix, H1 has k (kxk) transition matrices (i.e., different transition dynamics for different strata based on the lag class). So as k grows, one has to estimate many more parameters under H1 - which might be an issue depending on sample size.

We could change this so that the number of classes/strata for the lag does not have to be equal to the number of states in the chain.

@ljwolf
Copy link
Member

ljwolf commented Nov 30, 2015

Ahh, I see. So, in a naive dichotomous case, you'd need to figure out some reasonable way to ensure that somelag_spatial_categoricalwas intelligible. Seems reasonable to use mode, but ties could get weird... interesting.

@sjsrey sjsrey added this to the Release + 1 milestone Jan 21, 2016
@ljwolf
Copy link
Member

ljwolf commented Jul 16, 2016

Lag categorical was submitted, but we still need to allow for this abstraction.

@ljwolf
Copy link
Member

ljwolf commented Jul 11, 2017

This'll move to giddy and is still of active interest.

@ljwolf ljwolf closed this as completed Jul 11, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants