mgwr.sel_bw.Sel_BW¶
-
class
mgwr.sel_bw.
Sel_BW
(coords, y, X_loc, X_glob=None, family=<spglm.family.Gaussian object>, offset=None, kernel='bisquare', fixed=False, multi=False, constant=True, spherical=False)[source]¶ Select bandwidth for kernel
Methods: p211 - p213, bandwidth selection
[FBC02]: Fotheringham, A. S., Brunsdon, C., & Charlton, M. (2002). Geographically weighted regression: the analysis of spatially varying relationships.
- Parameters
- yarray
n*1, dependent variable.
- X_globarray
n*k1, fixed independent variable.
- X_locarray
n*k2, local independent variable, including constant.
- coordslist of tuples
(x,y) of points used in bandwidth selection
- familyfamily object/instance, optional
underlying probability model: Gaussian(), Poisson(), Binomial(). Default is Gaussian().
- offsetarray
n*1, the offset variable at the ith location. For Poisson model this term is often the size of the population at risk or the expected size of the outcome in spatial epidemiology Default is None where Ni becomes 1.0 for all locations
- kernelstring, optional
kernel function: ‘gaussian’, ‘bisquare’, ‘exponential’. Default is ‘bisquare’.
- fixedboolean
True for fixed bandwidth and False for adaptive (NN)
- multiTrue for multiple (covaraite-specific) bandwidths
False for a traditional (same for all covariates) bandwdith; defualt is False.
- 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).
Examples
>>> import libpysal as ps >>> 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)) >>> pov = np.array(data.by_col('PctPov')).reshape((-1,1)) >>> african_amer = np.array(data.by_col('PctBlack')).reshape((-1,1)) >>> X = np.hstack([rural, pov, african_amer])
Golden section search AICc - adaptive bisquare
>>> bw = Sel_BW(coords, y, X).search(criterion='AICc') >>> print(bw) 93.0
Golden section search AIC - adaptive Gaussian
>>> bw = Sel_BW(coords, y, X, kernel='gaussian').search(criterion='AIC') >>> print(bw) 50.0
Golden section search BIC - adaptive Gaussian
>>> bw = Sel_BW(coords, y, X, kernel='gaussian').search(criterion='BIC') >>> print(bw) 62.0
Golden section search CV - adaptive Gaussian
>>> bw = Sel_BW(coords, y, X, kernel='gaussian').search(criterion='CV') >>> print(bw) 68.0
Interval AICc - fixed bisquare
>>> sel = Sel_BW(coords, y, X, fixed=True) >>> bw = sel.search(search_method='interval', bw_min=211001.0, bw_max=211035.0, interval=2) >>> print(bw) 211025.0
- Attributes
- yarray
n*1, dependent variable.
- X_globarray
n*k1, fixed independent variable.
- X_locarray
n*k2, local independent variable, including constant.
- coordslist of tuples
(x,y) of points used in bandwidth selection
- familystring
GWR model type: ‘Gaussian’, ‘logistic, ‘Poisson’‘
- kernelstring
type of kernel used and wether fixed or adaptive
- fixedboolean
True for fixed bandwidth and False for adaptive (NN)
- criterionstring
bw selection criterion: ‘AICc’, ‘AIC’, ‘BIC’, ‘CV’
- search_methodstring
bw search method: ‘golden’, ‘interval’
- bw_minfloat
min value used in bandwidth search
- bw_maxfloat
max value used in bandwidth search
- intervalfloat
interval increment used in interval search
- tolfloat
tolerance used to determine convergence
- max_iterinteger
max interations if no convergence to tol
- multiTrue for multiple (covaraite-specific) bandwidths
False for a traditional (same for all covariates) bandwdith; defualt is False.
- constantboolean
True to include intercept (default) in model and False to exclude intercept.
- offsetarray
n*1, the offset variable at the ith location. For Poisson model this term is often the size of the population at risk or the expected size of the outcome in spatial epidemiology Default is None where Ni becomes 1.0 for all locations
- sphericalboolean
True for shperical coordinates (long-lat), False for projected coordinates (defalut).
- search_paramsdict
stores search arguments
- int_scoreboolan
True if adaptive bandwidth is being used and bandwdith selection should be discrete. False if fixed bandwidth is being used and bandwidth does not have to be discrete.
- bwscalar or array-like
Derived optimal bandwidth(s). Will be a scalar for GWR (multi=False) and a list of scalars for MGWR (multi=True) with one bandwidth for each covariate.
- Sarray
n*n, hat matrix derived from the iterative backfitting algorthim for MGWR during bandwidth selection
- Rarray
n*n*k, partial hat matrices derived from the iterative backfitting algoruthm for MGWR during bandwidth selection. There is one n*n matrix for each of the k covariates.
- paramsarray
n*k, calibrated parameter estimates for MGWR based on the iterative backfitting algorithm - computed and saved here to avoid having to do it again in the MGWR object.
Methods
search
(self[, search_method, criterion, …])Method to select one unique bandwidth for a gwr model or a bandwidth vector for a mgwr model.