地理加权问题GWR-经管之家官网!

人大经济论坛-经管之家 收藏本站
您当前的位置> 会计>>

会计库

>>

地理加权问题GWR

地理加权问题GWR

发布:项伟 | 分类:会计库

关于本站

人大经济论坛-经管之家:分享大学、考研、论文、会计、留学、数据、经济学、金融学、管理学、统计学、博弈论、统计年鉴、行业分析包括等相关资源。
经管之家是国内活跃的在线教育咨询平台!

经管之家新媒体交易平台

提供"微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯"等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】

提供微信号、微博、抖音、快手、头条、小红书、百家号、企鹅号、UC号、一点资讯等虚拟账号交易,真正实现买卖双方的共赢。【请点击这里访问】

这是matlab自带的GWR程序,我按照给的例子和数据用大样本进行运行,但是错误,请哪位高手帮我纠纠错?谢谢!studentize什么意思?functionresult=gwr(y,x,east,north,info);%PURPOSE:computegeographicallyweightedr ...
免费学术公开课,扫码加入


这是matlab自带的GWR程序,我按照给的例子和数据用大样本进行运行,但是错误,请哪位高手帮我纠纠错?谢谢!studentize什么意思?
function result = gwr(y,x,east,north,info);
% 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
%---------------------------------------------------
% written by: James P. LeSage 2/98
% University of Toledo
% Department of Economics
% Toledo, OH 43606
% jpl@jpl.econ.utoledo.edu
if nargin == 5 % user options
if ~isstruct(info)
error('gwr: must supply the option argument as a structure variable');
else
fields = fieldnames(info);
nf = length(fields);
% set defaults
[n k] = size(x);
bwidth = 0; dtype = 0; q = 0; qmin = k+2; qmax = 5*k;
bmin = 0.1; bmax = 20.0;
for i=1:nf
if strcmp(fields{i},'bwidth')
bwidth = info.bwidth;
elseif strcmp(fields{i},'dtype')
dstring = info.dtype;
if strcmp(dstring,'gaussian')
dtype = 0;
elseif strcmp(dstring,'exponential')
dtype = 1;
elseif strcmp(dstring,'tricube')
dtype = 2;
end;
elseif strcmp(fields{i},'q')
q = info.q;
elseif strcmp(fields{i},'qmax');
qmax = info.qmax;
elseif strcmp(fields{i},'qmin');
qmin = info.qmin;
elseif strcmp(fields{i},'bmin');
bmin = info.bmin;
elseif strcmp(fields{i},'bmax');
bmax = info.bmax;
end;
end; % end of for i
end; % end of if else
elseif nargin == 4
bwidth = 0; dtype = 0; dstring = 'gaussian';
bmin = 0.1; bmax = 20.0;
else
error('Wrong # of arguments to gwr');
end;
% error checking on inputs
[nobs nvar] = size(x);
[nobs2 junk] = size(y);
[nobs3 junk] = size(north);
[nobs4 junk] = size(east);
result.north = north;
result.east = east;
if nobs ~= nobs2
error('gwr: y and x must contain same # obs');
elseif nobs3 ~= nobs
error('gwr: north coordinates must equal # obs');
elseif nobs3 ~= nobs4
error('gwr: east coordinates must equal # in north');
end;
switch dtype
case{0,1} % bandwidth cross-validation
if bwidth == 0 % cross-validation
options = optimset('fminbnd');
optimset('MaxIter',500);
if dtype == 0 % Gaussian weights
[bdwt,junk,exitflag,output] = fminbnd('scoref',bmin,bmax,options,y,x,east,north,dtype);
elseif dtype == 1 % exponential weights
[bdwt,junk,exitflag,output] = fminbnd('scoref',bmin,bmax,options,y,x,east,north,dtype);
end;
if output.iterations == 500,
fprintf(1,'gwr: cv convergence not obtained in %4d iterations',output.iterations);
else
result.iter = output.iterations;
end;
else
bdwt = bwidth*bwidth; % user supplied bandwidth
end;
case{2} % q-nearest neigbhor cross-validation
if q == 0 % cross-validation
q = scoreq(qmin,qmax,y,x,east,north);
else
% use user-supplied q-value
end;
otherwise
end;
% do GWR using bdwt as bandwidth
[n k] = size(x);
bsave = zeros(n,k);
ssave = zeros(n,k);
sigv= zeros(n,1);
yhat= zeros(n,1);
resid = zeros(n,1);
wt = zeros(n,1);
d = zeros(n,1);
for iter=1:n;
dx = east - east(iter,1);
dy = north - north(iter,1);
d = (dx.*dx + dy.*dy);
sd = std(sqrt(d));
% sort distance to find q nearest neighbors
ds = sort(d);
if dtype == 2, dmax = ds(q,1); end;
if dtype == 0, % Gausian weights
wt = stdn_pdf(sqrt(d)/(sd*bdwt));
elseif dtype == 1, % exponential weights
wt = exp(-d/bdwt);
elseif dtype == 2, % tricube weights
wt = zeros(n,1);
nzip = find(d <= dmax);
wt(nzip,1) = (1-(d(nzip,1)/dmax).^3).^3;
end; % end of if,else
wt = sqrt(wt);
% computational trick to speed things up
% use non-zero wt to pull out y,x observations
nzip = find(wt >= 0.01);
ys = y(nzip,1).*wt(nzip,1);
xs = matmul(x(nzip,:),wt(nzip,1));
xpxi = invpd(xs'*xs);
b = xpxi*xs'*ys;
% compute predicted values
yhatv = xs*b;
yhat(iter,1) = x(iter,:)*b;
resid(iter,1) = y(iter,1) - yhat(iter,1);
% compute residuals
e = ys - yhatv;
% find # of non-zero observations
nadj = length(nzip);
sige = (e'*e)/nadj;
% compute t-statistics
sdb = sqrt(sige*diag(xpxi));
% store coefficient estimates and std errors in matrices
% one set of beta,std for each observation
bsave(iter,:) = b';
ssave(iter,:) = sdb';
sigv(iter,1) = sige;
end;
% fill-in results structure
result.meth = 'gwr';
result.nobs = nobs;
result.nvar = nvar;
if (dtype == 0 | dtype == 1)
result.bwidth = sqrt(bdwt);
else
result.q = q;
end;
result.beta = bsave;
result.tstat = bsave./ssave;
result.sige = sigv;
result.dtype = dstring;
result.y = y;
result.yhat = yhat;
% compute residuals and conventional r-squared
result.resid = resid;
sigu = result.resid'*result.resid;
ym = y - mean(y);
rsqr1 = sigu;
rsqr2 = ym'*ym;
result.rsqr = 1.0 - rsqr1/rsqr2; % r-squared
rsqr1 = rsqr1/(nobs-nvar);
rsqr2 = rsqr2/(nobs-1.0);
result.rbar = 1 - (rsqr1/rsqr2); % rbar-squared
然后是大样本的运行例子
>> % PURPOSE: An example of using gwr()
% Geographically weighted regression model
% (on a fairly large data set)
%---------------------------------------------------
% USAGE: gwr_d2
%---------------------------------------------------
load boston.dat; % Harrison-Rubinfeld data
[n k] = size(boston);
y = boston(:,k-2); % median house values
latit = boston(:,k-1);% lattitude coordinates
longi = boston(:,k); % longitude coordinates
x = [ones(n,1) boston(:,1:k-3)]; % other variables
vnames = strvcat('hprice','crime','zoning','industry','charlesr', ...
'noxsq','rooms2','houseage','distance','access','taxrate', ...
'pupil/teacher','blackpop','lowclass');
ys = studentize(log(y)); xs = studentize(x(:,2:end));
clear boston;
clear y;
clear x;
info.dtype = 'exponential';
result = gwr(ys,xs,latit,longi,info);
prt(result,vnames);
plt(result,vnames);
出现错误提示
??? Undefined function or method 'studentize' for input arguments of type 'double'.
「经管之家」APP:经管人学习、答疑、交友,就上经管之家!
免流量费下载资料----在经管之家app可以下载论坛上的所有资源,并且不额外收取下载高峰期的论坛币。
涵盖所有经管领域的优秀内容----覆盖经济、管理、金融投资、计量统计、数据分析、国贸、财会等专业的学习宝库,各类资料应有尽有。
来自五湖四海的经管达人----已经有上千万的经管人来到这里,你可以找到任何学科方向、有共同话题的朋友。
经管之家(原人大经济论坛),跨越高校的围墙,带你走进经管知识的新世界。
扫描下方二维码下载并注册APP
本文关键词:

本文论坛网址:https://bbs.pinggu.org/thread-837058-1-1.html

人气文章

1.凡人大经济论坛-经管之家转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
经管之家 人大经济论坛 大学 专业 手机版