# Spatial error model specification (spdep)

2 messages
Open this post in threaded view
|
Report Content as Inappropriate

## Spatial error model specification (spdep)

 Dear list I am trying to use spdep to estimate a spatial error model using data aggregated by census divisions for an urban area. I have problems with the model specification with my data. When estimating least squares (OLS) model, the reset-test indicates that the correct specification includes quadratic terms. After estimating a model that passes the reset-test, I tested the residuals for spatial autocorrelation using lm.morantest and found evidence for it. Therefore  I tried to run a spatial error model with the same model formula. The problem I run into is that the function errorsarlm will not converge when I include a quadratic term into the equation. My guess is that the problem is related to the high correlation between x and x^2. The error is the following: > Error in solve.default(asyvar, tol = tol.solve) :   system is computationally singular: reciprocal condition number = 1.92175e-14 So my question is how to correctly specify the model? Or how to successfully include quadratic terms? I have run into this problem with real data, but to illustrate the problem, I added below an example that gives the same error with artificial data. many thanks in advance, Daniel -------------------------------- # Load libraries library(lmtest) library(spdep) # Create artificial data dat <- data.frame(x = 1:1000, x2 = (1:1000)^2) dat\$y <- dat\$x2 + rnorm(1000, 0, 10) # Tests suggest that quadratic model is the correct specification dat.lm <- lm(y ~ x, dat) reset(dat.lm) dat.lm <- lm(y ~ x + x2, dat) reset(dat.lm) # Create artificial neighbor matrix nb <- sample(c(1,0), 1e6, replace = T, prob = c(1, 100)) nb <- matrix(nb, nrow = 1000) nb <- nb + t(nb) nb <- mat2listw(nb, style = 'W') # When I try to estimate spatial error model leads to an error dat.errorsarlm <- errorsarlm(y ~ x + x2, dat, nb) > Error in solve.default(asyvar, tol = tol.solve) :   system is computationally singular: reciprocal condition number = 1.92175e-14         [[alternative HTML version deleted]] _______________________________________________ R-sig-Geo mailing list [hidden email] https://stat.ethz.ch/mailman/listinfo/r-sig-geo