r-spatial / spatialreg

spatialreg: spatial models estimation and testing
https://r-spatial.github.io/spatialreg/
41 stars 12 forks source link

Try and fix Griddy Gibbs error in spBreg #9

Closed nk027 closed 4 years ago

nk027 commented 4 years ago

Apparently the Griddy Gibbs step sometimes fails:

if (any(cond)) {
    idraw = which.min(cond) - 1 #max(ind)
    rho = detval1[idraw]#FIXME: This sometimes fail...
}

Afaik the idea of this step (as implemented in MATLAB) is to get the position of the last TRUE value (ind = find(den <= rnd); idraw = max(ind);).

This differs from the logic here - i.e. looking for the first FALSE and returning the prior position. I'm unsure whether this actually occurs, but if we have cond == c(FALSE, TRUE, TRUE, TRUE, FALSE) this fails. If we want the last TRUE value max(which(cond)) seems more appropriate. The approach here will yield 0 and fail subsequently.

rsbivand commented 4 years ago

Thanks, useful!