

%This program simulates and estimates Y=XB+alpha*Y+e 
%This is a simple Monte Carlo program with iter replicates of Y
%We examine the min,median, and max of alpha and compare it to
%the value of the true autoregressive parameter, truerho.

%It uses 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
%It uses the symmetric weighting matrix in wsw

load xsub;
load y;
load wswdel;
wsw=wswdel;
load detvalzdel;
detvalz=detvalzdel;

[n,k1]=size(xsub);
o=ones(n,1);

x=[xsub  o];
%creates pure AR with X matrix [X  intercept]

[n,k2]=size(x);
beta=ones(k2,1);
xbeta=x*beta;
sigma=10;
iter=10;
truerho=0.85;

tic;
[rvcorr,invxbeta]=fsimmix1(wsw,randn(n,iter),truerho,xbeta);
toc;

elapsed_time =

    1.9630


alphavec=zeros(iter,1);
tic;

for i=1:iter;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;
y=invxbeta+sigma*rvcorr(:,i);

[alphamax,loglik,emax,bmax,likratios,prhigher]=fpar1(xsub,y,detvalz,wsw);
alphavec(i)=alphamax;
end;

toc;

elapsed_time =

    1.3120


truerho

truerho =

    0.8500

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

ans =

    0.8400    0.8500    0.8600


iter

iter =

    10


diary off;
