On Mon, 16 Aug 2010, Malcolm Fairbrother wrote:
Dear list,
I am running some simulations, trying to use lagsarlm (from the spdep
package) to recover the parameters used to generate the data. In a basic
simulation I am running, I am finding that I am able to recover rho
almost perfectly, and all but one of the betas perfectly. However, the
beta attached to the constant is substantially biased, for reasons I
cannot understand.
The code I am using is below. The spatial weights matrix is from the 48
contiguous U.S. states (rows sum to 1). Can anyone see where I am going
wrong? Or is the biased B0 coefficient somehow a consequence of the
particular neighbourhood structure I'm using? Any help or tips would be
much appreciated.
Malcolm,
You didn't set a seed, so I can't reproduce this exactly, but I think that
the mean of e will be added to your constant, won't it?
n <- 48
e <- matrix(rnorm(n*1000, mean=0, sd=4), 1000, n)
summary(apply(e, 1, mean))
Could you do a scale(e, center=TRUE, scale=FALSE) to force it to mean
zero?
Hope this helps,
Roger
- Malcolm
n <- dim(W)[1] # sample size
Bs <- c(2, 5, 3, -2) # vector of Beta coefficients
rho <- 0.2 # set autocorrelation coefficient
bres <- matrix(NA, nrow=1000, ncol=5)
for (i in 1:1000) {
+ e <- rnorm(n, mean=0, sd=4)
+ X1 <- rnorm(n, 4, 2) # create some independent variables
+ X2 <- rnorm(n, 2, 2)
+ X3 <- rnorm(n, -3, 1)
+ X <- cbind(rep(1, n), X1, X2, X3)
+ y <- (solve(diag(n)-rho*W)) %*% ((X%*%Bs)+e) # generate lagged Ys
+ data <- as.data.frame(cbind(y, X))
+ lagmod <- lagsarlm(y ~ X1 + X2 + X3, data=data, oxw.listw1)
+ bres[i,] <- coefficients(lagmod)
+ }
apply(bres, 2, mean)
[1] 0.1876292 2.6275783 4.9897827 3.0060831 -1.9883803
apply(bres, 2, median)
[1] 0.1907057 2.4000895 4.9887496 3.0043258 -2.0076960
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
--
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: roger.biv...@nhh.no
_______________________________________________
R-sig-Geo mailing list
R-sig-Geo@stat.math.ethz.ch
https://stat.ethz.ch/mailman/listinfo/r-sig-geo