[R-sig-Geo] Partial residual plot from SAR model

Roger Bivand Roger.Bivand at nhh.no
Mon Sep 5 10:07:06 CEST 2011


On Mon, 5 Sep 2011, Clément Tisseuil wrote:

> Dear Mr. Bivand,
>
> Like the prplot function from the faraway package, I am trying to find a way
> to make partial residuals plots from a simultaneous autoregressive error
> model. When I look at the list of parameters from the SAR model ouput, I am
> just lost when trying to rebuild the correct SAR equation which should help
> me to make the partial plots...
>
> Would you have an idea ?

Did you actually try the advice I gave when you contacted me off-list, and 
which you append below? Do please try:

"Depending on which version of spdep you are running, the following may 
work:

library(spdep)
data(oldcol)
COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
  nb2listw(COL.nb, style="W"), method="eigen")
tarlm <- lm(COL.errW.eig$tary ~ COL.errW.eig$tarX - 1)
library(faraway)
prplot(tarlm, 1)
prplot(tarlm, 2)

but I think it grabs the whole matrix name in creating the labels. Maybe:

df0 <- as.data.frame(COL.errW.eig$tarX)
names(df0) <- names(COL.errW.eig$coefficients)
df <- cbind(y=COL.errW.eig$tary, df0[,-1])
str(df)
tarlm <- lm(y ~ INC + HOVAL, data=df)
prplot(tarlm, 1)
prplot(tarlm, 2)

The plots look the same, the first version is less code, but prplot() gets 
the legends wrong, and does not accept xlab=, ylab= to correct the 
problem. The tarX component includes the (I - \lambda W) X, which are the 
X you would need here, I think, not the unfiltered X."

Consider asking the author of prplot() to add ... to the function to pass 
plot arguments to the underlying plot function to save you the extra work.

Hope this helps,

Roger


>
> Thank you in advance for your attention.
>
> Kind regards
>
> Clement Tisseuil (PhD)
> Mus??um National d'Histoire Naturelle
> Equipe BOREA
> Paris
>
>
>
>
> ********************************************************************
>>> Please *do* write to the R-sig-geo list rather than to me directly -
>>> others can answer your question as well, perhaps better, and in a more
>>> timely way than I can. In addition, threads in the list can be searched
> in
>>> the archives, so others can avoid the same problem later.
>>>
>>> Depending on which version of spdep you are running, the following may
> work:
>>>
>>> library(spdep)
>>> data(oldcol)
>>> COL.errW.eig <- errorsarlm(CRIME ~ INC + HOVAL, data=COL.OLD,
>>>  nb2listw(COL.nb, style="W"), method="eigen")
>>> tarlm <- lm(COL.errW.eig$tary ~ COL.errW.eig$tarX - 1)
>>> library(faraway)
>>> prplot(tarlm, 1)
>>> prplot(tarlm, 2)
>>>
>>> but I think it grabs the whole matrix name in creating the labels. Maybe:
>>>
>>> df0 <- as.data.frame(COL.errW.eig$tarX)
>>> names(df0) <- names(COL.errW.eig$coefficients)
>>> df <- cbind(y=COL.errW.eig$tary, df0[,-1])
>>> str(df)
>>> tarlm <- lm(y ~ INC + HOVAL, data=df)
>>> prplot(tarlm, 1)
>>> prplot(tarlm, 2)
>>>
>>> The plots look the same, the first version is less code, but prplot()
> gets the legends wrong,
>>> and does not accept xlab=, ylab= to correct the problem. The tarX
> component includes
>>> the (I - \lambda W) X, which are the X you would need here, I think, not
> the unfiltered X.
>>>
>>> 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 at nhh.no
>
>

-- 
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