1
Matlab:地理加权回归模型命令简介
在Matlab软件中,可以调用gwr.m来实现地理加权回归模型的参数过程,下面介绍 GWR 在Matlab中的实现过程:
“gwr.m”函数命令的调用方式如下所示:
#%% 地理加权回归模型MATLAB程序代码如下>> help gwr PURPOSE: compute geographically weighted regression ---------------------------------------------------- USAGE: results = gwr(y,x,east,north,info) where: y = dependent variable vector x = explanatory variable matrix east = x-coordinates in space north = y-coordinates in space info = a structure variable with fields: info.bwidth = scalar bandwidth to use or zero for cross-validation estimation (default) info.bmin = minimum bandwidth to use in CV search info.bmax = maximum bandwidth to use in CV search defaults: bmin = 0.1, bmax = 20 info.dtype = 'gaussian' for Gaussian weighting (default) = 'exponential' for exponential weighting = 'tricube' for tri-cube weighting info.q = q-nearest neighbors to use for tri-cube weights (default: CV estimated) info.qmin = minimum # of neighbors to use in CV search info.qmax = maximum # of neighbors to use in CV search defaults: qmin = nvar+2, qmax = 4*nvar --------------------------------------------------- NOTE: res = gwr(y,x,east,north) does CV estimation of bandwidth --------------------------------------------------- RETURNS: a results structure results.meth = 'gwr' results.beta = bhat matrix (nobs x nvar) results.tstat = t-stats matrix (nobs x nvar) results.yhat = yhat results.resid = residuals results.sige = e'e/(n-dof) (nobs x 1) results.nobs = nobs results.nvar = nvars results.bwidth = bandwidth if gaussian or exponential results.q = q nearest neighbors if tri-cube results.dtype = input string for Gaussian, exponential weights results.iter = # of simplex iterations for cv results.north = north (y-coordinates) results.east = east (x-coordinates) results.y = y data vector --------------------------------------------------- See also: prt,plt, prt_gwr, plt_gwr to print and plot results --------------------------------------------------- References: Brunsdon, Fotheringham, Charlton (1996) Geographical analysis, pp. 281-298 --------------------------------------------------- NOTES: uses auxiliary function scoref for cross-validation ---------------------------------------------------
选项含义为:
2
高斯距离权重函数地理加权回归模型
选择高斯距离权重函数进行地理加权回归模型代码如下:
%--------------------------------------------------------------------------%计量经济学服务中心《空间计量经济学及Matlab应用》%--------------------------------------------------------------------------%高斯距离权重函数地理加权回归模型% load the Anselin data set% 导入数据load anselin.dat;y = anselin(:,1);nobs = length(y);x = [ones(nobs,1) anselin(:,2:3)];[nobs nvar] = size(x);north = anselin(:,4);east = anselin(:,5);vnames = strvcat('crime','constant','income','hvalue');
%--------------------------------------------------------------------------%计量经济学服务中心《空间计量经济学及Matlab应用》%--------------------------------------------------------------------------% Gaussian distance weighting%高斯距离权重函数地理加权回归模型info.dtype = 'gaussian'; tic; result1 = gwr(y,x,east,north,info); toc;prt(result1,vnames);
结果为: