mgwr.gwr.MGWR

class mgwr.gwr.MGWR(coords, y, X, selector, sigma2_v1=True, kernel='bisquare', fixed=False, constant=True, dmat=None, sorted_dmat=None, spherical=False)[source]

Multiscale GWR estimation and inference.

Parameters:
coords : array-like

n*2, collection of n sets of (x,y) coordinates of observatons; also used as calibration locations is ‘points’ is set to None

y : array

n*1, dependent variable

X : array

n*k, independent variable, exlcuding the constant

selector : sel_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.

family : family object

underlying probability model; provides distribution-specific calculations

sigma2_v1 : boolean

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))

kernel : string

type of kernel function used to weight observations; available options: ‘gaussian’ ‘bisquare’ ‘exponential’

fixed : boolean

True for distance based kernel function and False for adaptive (nearest neighbor) kernel function (default)

constant : boolean

True to include intercept (default) in model and False to exclude intercept.

dmat : array

n*n, distance matrix between calibration locations used to compute weight matrix. Defaults to None and is primarily for avoiding duplicate computation during bandwidth selection.

sorted_dmat : array

n*n, sorted distance matrix between calibration locations used to compute weight matrix. Defaults to None and is primarily for avoiding duplicate computation during bandwidth selection.

spherical : boolean

True for shperical coordinates (long-lat), False for projected coordinates (defalut).

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:
coords : array-like

n*2, collection of n sets of (x,y) coordinates of observatons; also used as calibration locations is ‘points’ is set to None

y : array

n*1, dependent variable

X : array

n*k, independent variable, exlcuding the constant

selector : sel_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.

bw : array-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

family : family object

underlying probability model; provides distribution-specific calculations

sigma2_v1 : boolean

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))

kernel : string

type of kernel function used to weight observations; available options: ‘gaussian’ ‘bisquare’ ‘exponential’

fixed : boolean

True for distance based kernel function and False for adaptive (nearest neighbor) kernel function (default)

constant : boolean

True to include intercept (default) in model and False to exclude intercept.

dmat : array

n*n, distance matrix between calibration locations used to compute weight matrix. Defaults to None and is primarily for avoiding duplicate computation during bandwidth selection.

sorted_dmat : array

n*n, sorted distance matrix between calibration locations used to compute weight matrix. Defaults to None and is primarily for avoiding duplicate computation during bandwidth selection.

spherical : boolean

True for shperical coordinates (long-lat), False for projected coordinates (defalut).

n : integer

number of observations

k : integer

number of independent variables

mean_y : float

mean of y

std_y : float

standard deviation of y

fit_params : dict

parameters passed into fit method to define estimation routine

W : array-like

list of n*n arrays, spatial weights matrices for weighting all observations from each calibration point: one for each covariate (k)

Methods

fit() Method that extracts information from Sel_BW (selector) object and prepares GAM estimation results for MGWRResults object.
predict() Not implemented.
df_model  
df_resid  
__init__(coords, y, X, selector, sigma2_v1=True, kernel='bisquare', fixed=False, constant=True, dmat=None, sorted_dmat=None, spherical=False)[source]

Initialize class