spint.gravity.Doubly¶
-
class
spint.gravity.
Doubly
(flows, origins, destinations, cost, cost_func, constant=True, framework='GLM', SF=None, CD=None, Lag=None, Quasi=False)[source]¶ Doubly-constrained gravity-type spatial interaction model
- 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; when there are many origins it will be faster to use integers rather than strings for id labels.
- 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 rather than 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
- 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
- oarray
n x 1; index of origin id’s
- darray
n x 1; index of destination id’s
- constantboolean
True to include intercept in model; True by default
- paramsarray
n x k, estimated beta coefficients; k = # of origins + # of destinations; the first x-1 values pertain to the x destinations (leaving out the first destination to avoid perfect collinearity; no fixed effect), the next x values pertain to the x origins, and the final value is the distance decay coefficient
- 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 Doubly
- >>> 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))
- >>> d = np.array(db.by_col(‘d_tract’)).reshape((-1,1))
- >>> o = np.array(db.by_col(‘o_tract’)).reshape((-1,1))
- >>> model = Doubly(flows, o, d, cost, ‘exp’)
- >>> model.params[-1:]
- array([-0.00232112])
Methods
fit
(self[, framework, Quasi])Method that fits a particular count model usign the appropriate estimation technique.
local
(self[, locs])Not inmplemented for doubly-constrained models Not possible due to insufficient degrees of freedom.
SRMSE
SSI
reshape
-
__init__
(self, flows, origins, destinations, 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, origins, destinations, …)Initialize self.
fit
(self[, framework, Quasi])Method that fits a particular count model usign the appropriate estimation technique.
local
(self[, locs])Not inmplemented for doubly-constrained models Not possible due to insufficient degrees of freedom.
reshape
(self, array)