spint.gravity.Attraction¶
-
class
spint.gravity.
Attraction
(flows, destinations, o_vars, cost, cost_func, constant=True, framework='GLM', SF=None, CD=None, Lag=None, Quasi=False)[source]¶ Attraction-constrained (destination-constrained) gravity-type spatial interaction model
- Parameters
- flowsarray of integers
n x 1; observed flows between O origins and D destinations
- destinationsarray of strings
n x 1; unique identifiers of destinations of n flows; when there are many destinations it will be faster to use integers over strings for id labels.
- costarray
n x 1; cost to overcome separation between each origin and destination associated with a flow; typically distance or time
- cost_funcstring or function that has scalar input and output
functional form of the cost function; ‘exp’ | ‘pow’ | custom function
- o_varsarray (optional)
n x p; p attributes for each origin of n flows; default is None
- constantboolean
True to include intercept in model; True by default
- yarray
n x 1; dependent variable used in estimation including any transformations
- Xarray
n x k, design matrix used in estimation
- frameworkstring
estimation technique; currently only ‘GLM’ is avaialble
- Quasiboolean
True to estimate QuasiPoisson model; should result in same parameters as Poisson but with altered covariance; default to true which estimates Poisson model
- SFarray
n x 1; eigenvector spatial filter to include in the model; default to None which does not include a filter; not yet implemented
- CDarray
n x 1; competing destination term that accounts for the likelihood that alternative destinations are considered along with each destination under consideration for every OD pair; defaults to None which does not include a CD term; not yet implemented
- LagW object
spatial weight for n observations (OD pairs) used to construct a spatial autoregressive model and estimator; defaults to None which does not include an autoregressive term; not yet implemented
- Attributes
- farray
n x 1; observed flows; dependent variable; y
- ninteger
number of observations
- kinteger
number of parameters
- carray
n x 1; cost to overcome separation between each origin and destination associated with a flow; typically distance or time
- cffunction
cost function; used to transform cost variable
- darray
n x 1; index of destination id’s
- ovarray
n x p; p attributes for each origin of n flows
- constantboolean
True to include intercept in model; True by default
- paramsarray
n x k, k estimated beta coefficients; k = # of destinations + p + 1
- yhatarray
n x 1, predicted value of y (i.e., fittedvalues)
- cov_paramsarray
Variance covariance matrix (kxk) of betas
- std_errarray
k x 1, standard errors of betas
- pvaluesarray
k x 1, two-tailed pvalues of parameters
- tvaluesarray
k x 1, the tvalues of the standard errors
- deviancefloat
value of the deviance function evalued at params; see family.py for distribution-specific deviance
- resid_devarray
n x 1, residual deviance of model
- llffloat
value of the loglikelihood function evalued at params; see family.py for distribution-specific loglikelihoods
- llnullfloat
value of the loglikelihood function evaluated with only an intercept; see family.py for distribution-specific loglikelihoods
- AICfloat
Akaike information criterion
- D2float
percentage of explained deviance
- adj_D2float
adjusted percentage of explained deviance
- pseudo_R2float
McFadden’s pseudo R2 (coefficient of determination)
- adj_pseudoR2float
adjusted McFadden’s pseudo R2
- SRMSEfloat
standardized root mean square error
- SSIfloat
Sorensen similarity index
- resultsobject
Full results from estimated model. May contain addtional diagnostics
- Example
- ——-
- >>> import numpy as np
- >>> import libpysal
- >>> from spint.gravity import Attraction
- >>> nyc_bikes = libpysal.examples.load_example(‘nyc_bikes’)
- >>> db = libpysal.io.open(nyc_bikes.get_path(‘nyc_bikes_ct.csv’))
- >>> cost = np.array(db.by_col(‘tripduration’)).reshape((-1,1))
- >>> flows = np.array(db.by_col(‘count’)).reshape((-1,1))
- >>> d = np.array(db.by_col(‘d_tract’)).reshape((-1,1))
- >>> o_cap = np.array(db.by_col(‘o_cap’)).reshape((-1,1))
- >>> model = Attraction(flows, d, o_cap, cost, ‘exp’)
- >>> model.params[-4:]
- array([ 1.21962276, 0.87634028, 0.88290909, -0.00229081])
Methods
fit
(self[, framework, Quasi])Method that fits a particular count model usign the appropriate estimation technique.
local
(self[, locs])Calibrate local models for subsets of data from a single location to all other locations
SRMSE
SSI
reshape
-
__init__
(self, flows, destinations, o_vars, cost, cost_func, constant=True, framework='GLM', SF=None, CD=None, Lag=None, Quasi=False)[source]¶ Initialize self. See help(type(self)) for accurate signature.
Methods
SRMSE
(self)SSI
(self)__init__
(self, flows, destinations, o_vars, …)Initialize self.
fit
(self[, framework, Quasi])Method that fits a particular count model usign the appropriate estimation technique.
local
(self[, locs])Calibrate local models for subsets of data from a single location to all other locations
reshape
(self, array)