[R-sig-Geo] Error while using predict.sarlm

Amitha Puranik pur@n|k@@m|th@ @end|ng |rom gm@||@com
Fri May 24 19:47:10 CEST 2019

I am facing an error while using predict.sarlm to make predictions for spatial
lag model generated using lagsarlm. I used the following code:

predicted = predict(fit.lag, listw=weightmatrix, newdata=missed_data,
pred.type="TS", zero.policy = T)

For the argument newdata, I have passed the same data missed_data which I
used to fit the spatial lag model.

When I run the above code, I get the following error message: “Error in
predict.sarlm(fit.lag, listw = weightmatrix, newdata = missed_data,  :
mismatch between newdata and spatial weights. newdata should have region.id
as row.names”

I have obtained the weight matrix from the function below

weightMat <- function(shp){

  dnb <- knearneigh(coordinates(shp), k=4)

  dnb <- knn2nb(dnb) #create nb

  lw <- nb2listw(dnb, style="W",zero.policy=TRUE) #create lw



To cross check and make sure there are no discrepancies, I have run the
following lines




For all the codes above, the result is 182, which is the sample size of

Can anyone offer me some guidance in solving this problem? Thanks for your

       Thanks & regards,

*Amitha Puranik*

Assistant Professor,

Department of Statistics, PSPH

Address:Department of Statistics,

Health Sciences Library, Level 6,

Manipal Academy of Higher Education,Manipal,Karnataka,India

An Institute of Eminence (Status Accorded by MHRD)

	[[alternative HTML version deleted]]

More information about the R-sig-Geo mailing list