The effects of two flavors of spatial autocorrelation on OLS

The following simulation (adapted from Anselin) shows the effect of spatial autocorrelation on the variance and bias of simple OLS coefficients. The following figures show 1000 estimates of \( \beta_1 \) under varying levels of spatial autocorrelation. The “true” \( \beta=1 \), if the mean of the histogram is not 1 then the model is biased (it systematically over/under estimates \( \beta \)). The width of the histogram shows the variance in estimate of \( \beta \). Each panel of each plot shows different levels of spatial autocorrelation (increasing from left to right). The first plot shows the effect of residual spatial autocorrelation on OLS estimates, the second shows the effect of spatial dependence in Y on OLS estimates.

spatial dependence in the error process

plot of chunk unnamed-chunk-2

When rho > 0 OLS estimates are unbiased but inefficient.

Spatial dependence in Y

plot of chunk unnamed-chunk-4

When rho > 0 OLS estimates are both biased and inefficient.

##Simulation code

## ERROR.  SPATIAL DEPENDENCE IN ERROR.
library(spdep)
n <- 100  #number of observation
r <- 1000  #number of models for each level of rho
rho <- c(0, 0.2, 0.7, 0.9)  #Vector of Rhos to test
X <- rnorm(n, 0, 3)  #simulate Xs
w <- cell2nb(10, 10)  #nb object for simulating autocorrelated data
bres <- data.frame()  #holds the results of the simulatation
ctr <- 0  #counter
for (j in 1:length(rho)) {
    iw <- invIrM(w, rho[j])
    for (i in 1:r) {
        ctr <- ctr + 1
        e <- iw %*% rnorm(n)
        y <- X + e
        lm1 <- lm(y ~ X)
        bres[ctr, 1] <- lm1$coef[2]
        bres[ctr, 2] <- paste("Spatial AC (rho=", rho[j], ")", sep = "")
    }
}

### LAG.  SPATIAL DEPENDENCE IN Y.
n <- 100
r <- 1000
rho <- c(0, 0.2, 0.7, 0.9)
X <- rnorm(n, 0, 3)
w <- cell2nb(10, 10)
bres <- data.frame()
ctr <- 0
for (j in 1:length(rho)) {
    iw <- invIrM(w, rho[j])
    for (i in 1:r) {
        ctr <- ctr + 1
        e <- rnorm(n)
        y <- X + e
        y <- iw %*% y
        lm1 <- lm(y ~ X)
        bres[ctr, 1] <- lm1$coef[2]
        bres[ctr, 2] <- paste("Spatial AC (rho =", rho[j], ")", sep = "")
    }
}

## PLOTTING
library(ggplot2)
bres$V2 <- as.factor(bres$V2)
bres$V2 <- relevel(bres$V2, 4)
p1 <- ggplot(data = bres, aes(x = V1)) + geom_histogram() + facet_grid(. ~ V2)