Dear Prof Roger,

Thank you so much for your patience.  Your explanations are what I want to
learn.  I have recorded them all.

Wishing you and your family a wonderful Holiday Season
Joe


On Sun, Dec 23, 2012 at 3:15 PM, Roger Bivand <Roger.Bivand@nhh.no> wrote:

> 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
>
>
>
>
>>
>>
>>
>>
>>
>
>
> --
> 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@nhh.no
>
>

	[[alternative HTML version deleted]]

