Skip to content
Prev 9014 / 29559 Next

lagsarlm with simulated data

Dear Roger (and any other interested parties),

Thanks very much for responding. I tried adding the scale() argument you suggested, but that didn't seem to make any difference. I've set a seed, and to make it even more easily reproducible, I've loosely followed code from: http://www.mail-archive.com/r-sig-geo at stat.math.ethz.ch/msg00799.html. The contiguities (in addition to the data) are now generated directly using the code below.

I'm still getting consistent upward bias for the Intercept, and otherwise perfect recoveries of the data-generating parameters. I tried reversing the sign of rho, and that didn't make any difference.

Any ideas? Sorry to bother you with this, but I'd like to know why the simulation is generating this result.

Thanks again,
Malcolm


library(spdep)
sims <- 1000 # set number of simulations
rho <- 0.2 # set autocorrelation coefficient
Bs <- c(2, 5, 3, -2) # set a vector of betas
nb7rt <- cell2nb(7, 7, torus=TRUE) # generate contiguities
listw <- nb2listw(nb7rt)
mat <- nb2mat(nb7rt) # create contiguity matrix
set.seed(20100817)
e <- matrix(rnorm(sims*length(nb7rt)), nrow=length(nb7rt)) # create random errors
e <- scale(e, center=TRUE, scale=FALSE) # constrain mean of errors to zero
X0 <- matrix(1, ncol=sims, nrow=length(nb7rt)) # create Intercept
X1 <- matrix(rnorm(sims*length(nb7rt), 4, 2), nrow=length(nb7rt)) # generate some covariates
X2 <- matrix(rnorm(sims*length(nb7rt), 2, 2), nrow=length(nb7rt))
X3 <- matrix(rnorm(sims*length(nb7rt), -3, 1), nrow=length(nb7rt))
Xbe <- X0*Bs[1]+X1*Bs[2]+X2*Bs[3]+X3*Bs[4]+e
y <- solve(diag(length(nb7rt)) - rho*mat) %*% Xbe # generate lagged y data
lag_res1 <- lapply(1:sims, function(i) lagsarlm(y[,i] ~ X1[,i] + X2[,i] + X3[,i], listw=listw)) # fit the model
apply(do.call("rbind", lapply(lag_res1, coefficients)), 2, mean) # mean estimates are excellent, except Int
apply(do.call("rbind", lapply(lag_res1, coefficients)), 2, var) # variance is also a lot higher for Int
On 16 Aug 2010, at 19:53, Roger Bivand wrote: