Skip to content
Prev 12689 / 29559 Next

Partial residual plot from SAR model

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

            
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