

%This example program program performs a simple Monte Carlo study of a mixed 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. 

%This routine simulates and subsequently fits a model Y=[X (spatially lagged X=DX) intercept]*parameters+alpha*spatially lagged Y+error
%This model has several names in the literature such as mixed regressive spatially autoregressive models

%Written by Kelley Pace, 6/23/97



%This example uses symmetric nearest neighbor weights in wsw

load xsub;
load y;
load wswnn;
wsw=wswnn;
load detvalznn;
detvalz=detvalznn;


[n,k1]=size(xsub);
o=ones(n,1);
x=[xsub wsw*xsub o];
%creates mixed X matrix [X DX intercept]
[n,k2]=size(x);
beta=ones(k2,1);
xbeta=x*beta;
sigma=10;
iter=5;
truerho=0.65;
%true AR parameter

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

elapsed_time =

    1.5930


alphavec=zeros(iter,1);
tic;

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

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

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

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

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

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

toc;

elapsed_time =

    0.9510


truerho

truerho =

    0.6500

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

ans =

    0.6300    0.6300    0.6400


iter

iter =

     5




diary off;
