

%This example program performs a simple Monte Carlo experiment with a SAR model using the data from:
%Pace, R. Kelley, and Ronald Barry, Quick Computation of Regressions with a Spatially Autoregressive Dependent Variable,
%Geographical Analysis, Volume 29, Number 3, July 1997, p. 232-247. 

%Written by Kelley Pace, 6/23/97


%This example uses Delaunay weights

load xsub;
load wswdel;
load wwsdel;
load detvalzdel;
wsw=wswdel;
wws=wwsdel;
detvalz=detvalzdel;

[n,k1]=size(xsub);
betas=ones(k1,1);
xbetas=xsub*betas;
iter=10;
true_ar_parm=0.8;

tic;
[rvcorr]=fsimsar1(wsw,randn(n,iter),true_ar_parm);
toc;

elapsed_time =

    1.8830



alphavec=zeros(iter,1);

tic;

for i=1:iter;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;
y=xbetas+rvcorr(:,i);
[alphamax,loglik,emax,bmax,likratios,prhigher]=fsar1(xsub,y,detvalz,wws);
alphavec(i)=alphamax;
end;

toc;

elapsed_time =

    2.0130


true_ar_parm

true_ar_parm =

    0.8000

[min(alphavec) median(alphavec) max(alphavec)]

ans =

    0.7700    0.7950    0.8100


iter

iter =

    10


diary off;
