geosnap.analyze.transition

geosnap.analyze.transition(gdf, cluster_col, temporal_index='year', unit_index='geoid', w_type='rook', w_options=None, permutations=0)[source]

Model neighborhood change as a discrete spatial Markov process.

Parameters:
gdfgeopandas.GeoDataFrame or pandas.DataFrame

Long-form geopandas.GeoDataFrame or pandas.DataFrame containing neighborhood attributes with a column defining neighborhood clusters.

cluster_colstr or int

Column name for the neighborhood segmentation, such as “ward”, “kmeans”, etc.

temporal_indexstr, optional

Column defining time and or sequencing of the long-form data. Default is “year”.

unit_indexstr, optional

Column identifying the unique id of spatial units. Default is “geoid”.

w_typestr, optional

Type of spatial weights type (“rook”, “queen”, “knn” or “kernel”) to be used for spatial structure. Default is None, if non-spatial Markov transition rates are desired.

w_optionsdict

additional options passed to a libpysal weights constructor (e.g. k for a KNN weights matrix)

permutationsint, optional

number of permutations for use in randomization based inference (the default is 0).

Returns:
margiddy.markov.Markov instance or giddy.markov.Spatial_Markov

if w_type=None, a classic Markov instance is returned. if w_type is given, a Spatial_Markov instance is returned.

Examples

>>> from geosnap import Community
>>> columbus = Community.from_ltdb(msa_fips="18140")
>>> columbus1 = columbus.cluster(columns=['median_household_income',
... 'p_poverty_rate', 'p_edu_college_greater', 'p_unemployment_rate'],
... method='ward', n_clusters=6)
>>> gdf = columbus1.gdf
>>> a = transition(gdf, "ward", w_type="rook")
>>> a.p
array([[0.79189189, 0.00540541, 0.0027027 , 0.13243243, 0.06216216,
    0.00540541],
   [0.0203252 , 0.75609756, 0.10569106, 0.11382114, 0.        ,
    0.00406504],
   [0.00917431, 0.20183486, 0.75229358, 0.01834862, 0.        ,
    0.01834862],
   [0.1959799 , 0.18341709, 0.00251256, 0.61809045, 0.        ,
    0.        ],
   [0.32307692, 0.        , 0.        , 0.        , 0.66153846,
    0.01538462],
   [0.09375   , 0.0625    , 0.        , 0.        , 0.        ,
    0.84375   ]])
>>> a.P[0]
array([[0.82119205, 0.        , 0.        , 0.10927152, 0.06622517,
    0.00331126],
   [0.14285714, 0.57142857, 0.14285714, 0.14285714, 0.        ,
    0.        ],
   [0.5       , 0.        , 0.5       , 0.        , 0.        ,
    0.        ],
   [0.21428571, 0.14285714, 0.        , 0.64285714, 0.        ,
    0.        ],
   [0.18918919, 0.        , 0.        , 0.        , 0.78378378,
    0.02702703],
   [0.28571429, 0.        , 0.        , 0.        , 0.        ,
    0.71428571]])