spint.gravity.Production¶

class
spint.gravity.
Production
(flows, origins, d_vars, cost, cost_func, constant=True, framework='GLM', SF=None, CD=None, Lag=None, Quasi=False)[source]¶ Productionconstrained (originconstrained) gravitytype 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.
 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
 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
 oarray
n x 1; index of origin id’s
 dvarray
n x p; 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 = # of origins + 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, twotailed 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 distributionspecific deviance
 resid_devarray
n x 1, residual deviance of model
 llffloat
value of the loglikelihood function evalued at params; see family.py for distributionspecific loglikelihoods
 llnullfloat
value of the loglikelihood function evaluated with only an intercept; see family.py for distributionspecific 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 Production
 >>> 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))
 >>> o = np.array(db.by_col(‘o_tract’)).reshape((1,1))
 >>> d_cap = np.array(db.by_col(‘d_cap’)).reshape((1,1))
 >>> model = Production(flows, o, d_cap, cost, ‘exp’)
 >>> model.params[4:]
 array([ 1.34721352, 0.96357345, 0.85535775, 0.00227444])
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, origins, d_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, origins, d_vars, cost, …)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)