Closed nk027 closed 1 year ago
I have been looking into how to address this and I don't think there's a nice way.
hi, I have the same issue, have you found the solution?
The main problem in this and #23 is the "naive" construction of the listw
object. The next problem is omitting the intercept, which is not really covered. The work in creating the WX is connected to the need to drop the lagged intercept if the row sums of W are identical to the unity intercept term. I don't see a great need to accommodate no-intercept formulae, nor to handle the lack of the style=
argument in spdep::mat2listw()
, which is covered in the reprex. Should spdep::mat2listw()
check whether all row sums are unity and if style=
is missing, impose "W"
and recalculate?
I'm adding:
library(spatialreg)
data(oldcol, package="spdep")
lwB <- spdep::nb2listw(COL.nb, style="B")
mod0 <- lmSLX(CRIME ~ INC + HOVAL, data=COL.OLD, listw=lwB)
coef(mod0)
INCB <- spdep::lag.listw(lwB, COL.OLD$INC)
HOVALB <- spdep::lag.listw(lwB, COL.OLD$HOVAL)
INTERCEPTB <- spdep::card(lwB$neighbours)
mod1 <- lm(CRIME ~ INC + HOVAL + INTERCEPTB + INCB + HOVALB, data=COL.OLD)
expect_true(isTRUE(all.equal(unname(coef(mod0)), unname(coef(mod1)))))
expect_warning(modx <- lmSLX(CRIME ~ INC + HOVAL + 0, data=COL.OLD, listw=lwB))
mod1x <- lm(CRIME ~ INC + HOVAL + 0 + INCB + HOVALB, data=COL.OLD)
expect_true(isTRUE(all.equal(unname(coef(modx)), unname(coef(mod1x)))))
as a tinytest. I cannot replicate any of the cases in #23, #24 or #26 (my version above, no made-up neighbours, no mat2listw()
), some are because the style
component of the listw
is set to "M"
that is missing by spdep::mat2listw()
. I'm adding warnings to that function to try to indicate that not setting the style=
argument is unsafe.
Hey, I stumbled upon some arguably unexpected behaviour with the
lmSLX()
function that exist on version 1.2-1.I can work on a PR fixing these, but I'll need some time. Below is a quick example.