[R-sig-Geo] (no subject)

Roger Bivand Roger.Bivand at nhh.no
Sun Dec 23 21:15:08 CET 2012


On Sun, 23 Dec 2012, Joseph Duncan wrote:

> Hi Everyone
>
> Happy Christmas!
>
> I have tried several days but cannot solve the problem.  Can any one help
> me ? Below is R command for a simple spatial regression. The data is
> attached.
>
>
> library(spdep)
> library(sphet)
> mat0 <- read.table("50state1.txt", header=FALSE, sep="\t", fill=TRUE)
> mat <- as.matrix(mat0)
> dim(mat)
> summary(c(mat))
> mat[is.na(mat)] <- 0
> summary(c(mat))
> lw <- mat2listw(mat, style="B")
> summary(lw, zero.policy=TRUE)
> is.symmetric.nb(lw$neighbours)
>
> lit <- read.csv(file="lit1.csv", h=T, sep= ",")

One row of lit is all missing values. So the easiest thing to do is to 
find out which:

> dim(lit)
[1] 52  9
> which(is.na(lit$lpax2010))
[1] 52
> lm(lpax2010 ~ sh65up + lpoptot + lypc, data = lit)
Call:
lm(formula = lpax2010 ~ sh65up + lpoptot + lypc, data = lit)

Coefficients:
(Intercept)       sh65up      lpoptot         lypc
     142.559       -1.616        1.669        6.210

> lm(lpax2010 ~ sh65up + lpoptot + lypc, data = lit[-52,])

Call:
lm(formula = lpax2010 ~ sh65up + lpoptot + lypc, data = lit[-52,
     ])

Coefficients:
(Intercept)       sh65up      lpoptot         lypc
     142.559       -1.616        1.669        6.210

(lm can handle dropping the empty row, but lagsarlm cannot when the 
weights were imported as a matrix)

> sarml <- lagsarlm(lpax2010 ~ sh65up + lpoptot + lypc, data = lit, listw =
> lw, method ="eigen", zero.policy=TRUE)

Next, the intercept is scaled in an unfortunate way, so rescale:

> sarml <- lagsarlm(lpax2010 ~ sh65up + lpoptot + lypc, data = lit[-52,], 
listw = lw, method ="eigen", zero.policy=TRUE)
Error in solve.default(inf, tol = tol.solve) :
   system is computationally singular: reciprocal condition number = 
8.55692e-14
> sarml <- lagsarlm(I(lpax2010/100) ~ sh65up + lpoptot + lypc,
  data = lit[-52,], listw = lw, method ="eigen", zero.policy=TRUE)

is OK. You can also declare the binary status of the weights by:

attr(lw$weights, "mode") <- "binary"

then you don't need to drop the NA row in lit, but expecting the software 
to know what you mean by itself when you haven't told it is perhaps risky, 
it might have guessed wrong.

plot(lw$neighbours, as.matrix(lit[-52,c(4,3)]))

looks rather unusual - was it what you intended?

Hope this helps,

Roger


> summary(sarml)
>
>
> Thank you very much
>
> Fairy
>

-- 
Roger Bivand
Department of Economics, NHH Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list