# Program LCLAGPLOT # # Plot of the concentrated log likelihood function # (ln Lc) of the spatial lag model (SAR model) # # Input: # Residual vectors: eO and eL # Spatial weights matrix: W # Number of regions: n # Output: # Coordiate system # x-axis: Autoregressive parameter rho # y-axis: Concentrated log likelihood function (ln Lc) # Autoregressive parameter: rho # Loglikelihood function at rho: Lcmax # ------------------------------------------------------------------- # Plot of Concentrated log likelihood function (ln Lc) # ------------------------------------------------------------------- n = 5; eO = c(-0.0503, -0.0062, 0.0600, -0.1297, 0.1262) eL = c(0.0211, 0.0227, -0.1500, -0.0711, 0.1774) I5 = diag(5) W = matrix(c(0, 0.5, 0.5, 0, 0, 1/3, 0, 1/3, 1/3, 0, 1/3, 1/3, 0, 1/3, 0, 0, 1/3, 1/3, 0, 1/3, 0, 0, 0, 1, 0), nrow=5, ncol=5, byrow=TRUE) x = seq(-1, 1, by=0.0001) Lc = x rho = -0.9999 for (j in 1:20000) { if (j<10000) { d =-(10000-j)/10000 } else { d = (j-1-10000)/10000 } Lc[j] = -n/2*log((eO-d*eL)%*%(eO-d*eL)/n) + log(det(I5-d*W)) if (j==1) { Lcmax = Lc[1] } if (Lc[j]>Lcmax) { rho = d; Lcmax = Lc[j] } } plot(x, Lc, main="Log Lc function of the spatial lag model", cex.main=1.0, xlab="rho", ylab="ln L(rho)", type="l") # grid on; # xlabel(' \rho'); # ylabel('ln L( \rho)'); # 'rho = ', rho, 'ln Lc(rho) = ', Lcmax