mgwr.gwr.MGWR¶
-
class
mgwr.gwr.
MGWR
(coords, y, X, selector, sigma2_v1=True, kernel='bisquare', fixed=False, constant=True, spherical=False, hat_matrix=False)[source]¶ Multiscale GWR estimation and inference. See [FYK17] [YFL+19].
- Parameters
- coordsarray-like
n*2, collection of n sets of (x,y) coordinates of observatons; also used as calibration locations is ‘points’ is set to None
- yarray
n*1, dependent variable
- Xarray
n*k, independent variable, exlcuding the constant
- selectorsel_bw object
valid sel_bw object that has successfully called the “search” method. This parameter passes on information from GAM model estimation including optimal bandwidths.
- familyfamily object
underlying probability model; provides distribution-specific calculations
- sigma2_v1boolean
specify form of corrected denominator of sigma squared to use for model diagnostics; Acceptable options are:
‘True’: n-tr(S) (defualt) ‘False’: n-2(tr(S)+tr(S’S))
- kernelstring
type of kernel function used to weight observations; available options: ‘gaussian’ ‘bisquare’ ‘exponential’
- fixedboolean
True for distance based kernel function and False for adaptive (nearest neighbor) kernel function (default)
- constantboolean
True to include intercept (default) in model and False to exclude intercept.
- sphericalboolean
True for spherical coordinates (long-lat), False for projected coordinates (defalut).
- hat_matrixboolean
True for computing and storing covariate-specific hat matrices R (n,n,k) and model hat matrix S (n,n). False (default) for computing MGWR inference on the fly.
Examples
#basic model calibration
>>> import libpysal as ps >>> from mgwr.gwr import MGWR >>> from mgwr.sel_bw import Sel_BW >>> data = ps.io.open(ps.examples.get_path('GData_utm.csv')) >>> coords = list(zip(data.by_col('X'), data.by_col('Y'))) >>> y = np.array(data.by_col('PctBach')).reshape((-1,1)) >>> rural = np.array(data.by_col('PctRural')).reshape((-1,1)) >>> fb = np.array(data.by_col('PctFB')).reshape((-1,1)) >>> african_amer = np.array(data.by_col('PctBlack')).reshape((-1,1)) >>> X = np.hstack([fb, african_amer, rural]) >>> X = (X - X.mean(axis=0)) / X.std(axis=0) >>> y = (y - y.mean(axis=0)) / y.std(axis=0) >>> selector = Sel_BW(coords, y, X, multi=True) >>> selector.search(multi_bw_min=[2]) [92.0, 101.0, 136.0, 158.0] >>> model = MGWR(coords, y, X, selector, fixed=False, kernel='bisquare', sigma2_v1=True) >>> results = model.fit() >>> print(results.params.shape) (159, 4)
- Attributes
- coordsarray-like
n*2, collection of n sets of (x,y) coordinates of observatons; also used as calibration locations is ‘points’ is set to None
- yarray
n*1, dependent variable
- Xarray
n*k, independent variable, exlcuding the constant
- selectorsel_bw object
valid sel_bw object that has successfully called the “search” method. This parameter passes on information from GAM model estimation including optimal bandwidths.
- bwarray-like
collection of bandwidth values consisting of either a distance or N nearest neighbors; user specified or obtained using Sel_BW with fb=True. Order of values should the same as the order of columns associated with X
- familyfamily object
underlying probability model; provides distribution-specific calculations
- sigma2_v1boolean
specify form of corrected denominator of sigma squared to use for model diagnostics; Acceptable options are:
‘True’: n-tr(S) (defualt) ‘False’: n-2(tr(S)+tr(S’S))
- kernelstring
type of kernel function used to weight observations; available options: ‘gaussian’ ‘bisquare’ ‘exponential’
- fixedboolean
True for distance based kernel function and False for adaptive (nearest neighbor) kernel function (default)
- constantboolean
True to include intercept (default) in model and False to exclude intercept.
- sphericalboolean
True for shperical coordinates (long-lat), False for projected coordinates (defalut).
- ninteger
number of observations
- kinteger
number of independent variables
- mean_yfloat
mean of y
- std_yfloat
standard deviation of y
- fit_paramsdict
parameters passed into fit method to define estimation routine
- Warray-like
list of n*n arrays, spatial weights matrices for weighting all observations from each calibration point: one for each covariate (k)
Methods
fit
(self[, n_chunks, pool])Compute MGWR inference by chunk to reduce memory footprint.
predict
(self)Not implemented.
df_model
df_resid