spint.gravity.BaseGravity¶
-
class
spint.gravity.
BaseGravity
(flows, cost, cost_func='pow', o_vars=None, d_vars=None, origins=None, destinations=None, constant=True, framework='GLM', SF=None, CD=None, Lag=None, Quasi=False)[source]¶ Base class to set up gravity-type spatial interaction models and dispatch estimaton technqiues.
- Parameters
- flowsarray of integers
n x 1; observed flows between O origins and D destinations
- originsarray of strings
n x 1; unique identifiers of origins of n flows
- destinationsarray of strings
n x 1; unique identifiers of destinations of n flows
- 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
- d_varsarray (optional)
n x p; p attributes for each destination of n flows; default is None
- constantboolean
True to include intercept in model; True by default
- 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
- ovarray
n x p(o); p attributes for each origin of n flows
- dvarray
n x p(d); p attributes for each destination of n flows
- 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
- paramsarray
n x k, k estimated beta coefficients; k = p(o) + p(d) + 1
- yhatarray
n x 1, predicted value of y (i.e., fittedvalues)
- cov_paramsarray
Variance covariance matrix (k x k) 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 BaseGravity
- >>> db = libpysal.io.open(libpysal.examples.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))
- >>> model = BaseGravity(flows, cost)
- >>> model.params
- array([17.84839637, -1.68325787])
Methods
fit
(self[, framework, Quasi])Method that fits a particular count model usign the appropriate estimation technique.
SRMSE
SSI
reshape
-
__init__
(self, flows, cost, cost_func='pow', o_vars=None, d_vars=None, origins=None, destinations=None, 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, cost[, cost_func, …])Initialize self.
fit
(self[, framework, Quasi])Method that fits a particular count model usign the appropriate estimation technique.
reshape
(self, array)