Open rsbivand opened 1 year ago
Hi Roger: sorry for the delay in my response. From what I recall, when I wrote listw2dgCMatrix() I was having issues with Na's. In fact, the help of listw2dgCMatrix() make reference to lagsarlm() in spatialreg pakage. From the help in lagsarlm():
zero.policy | default NULL, use global option value; if TRUE assign zero to the lagged value of zones without neighbours, if FALSE (default) assign NA - causing lagsarlm() to terminate with an error
I think I was applying the same logic in listw2dgCMatrix(). Does this make sense? One easy fix would be to to check if there are Na's in listw. If there aren't any then coerce zero.policy to TRUE, and eliminate the argument zero.policy from the function. What do you think?
I also posted to R-sig-geo: https://stat.ethz.ch/pipermail/r-sig-geo/2023-November/029353.html and subsequent, and https://stat.ethz.ch/pipermail/r-sig-geo/2023-November/029356.html. I'm working through spdep
now to try to detect and structure policy, so Josiah @JosiahParry and Connor's @ConnorDonegan comments are helpful. The changes upstream in spdep
add an attribute to listw
objects storing the zero.policy
status when it was created, with further branches when converting matrices to listw, and when subsetting listw objects (this affects predict methods for out-of-sample predictions). @JosiahParry @ConnorDonegan - should I start a discussion on https://github.com/r-spatial/discuss and invite any further responders from the mailing list posting?
Yes, I would probably try to involve more people from r-spatial in the discussion.
Also, should I wait before making any changes to listw2dgCMatrix()?
Yes, please wait until upstream stabilises.
Thanks for including me! Quick heads up: there's a typo in the reprex:
The line should compare m0
to M0
rather than mo
.
all.equal(m0, M0, check.attributes=FALSE)
@gpiras
listw2dgCMatrix
insphet
andsplm
seems to do the same asas(, "CsparseMatrix")
inspatialreg
. The apparent difference is thatlistw2dgCMatrix
takes azero.policy
argument, but:M1a <- listw2dgCMatrix(lw1, zero.policy=FALSE)
fails with:The only other difference is in
listw2dgCMatrix
not providing row or column names.I'm thinking of adding an attribute recording whether a
listw
object was created withzero.policy
TRUE
orFALSE
, but in this case I don't see what thezero.policy
argument does inlistw2dgCMatrix
over and above the coercion - which implicitly assumeszero.policy
is TRUE because the alternative is full rows and columns of NAs for observations without neighbours. This is part of trying to tidy up interfaces between the SE packages.