R:如何处理"非独特的row.names给出" in" predict.sarlm"

时间:2017-09-22 16:13:42

标签: r prediction predict

我在R中遇到一个错误,试图用新数据预测囊模型。我使用以下代码:

# I've fitted a sac model and now I'm trying to predict for a new dataset:
>newdata = read.csv("location" , header=T , sep=",")
#Calculate the new matrix from this new data:
>cord <- coordinates(newdata[,c("X","Y")])
>k1 <- knn2nb(knearneigh(cord, k=5))
>all.linked <- max(unlist(nbdists(k1, cord)))
>d <- dnearneigh(cord, 0, all.linked)
>dlist <- nbdists(d, coordinates(cord))
>wn = nb2listw(d, glist=dlist, style="W")
#predict:
>prediction = predict.sarlm(sac_model, newdata = newdata, pred.type = "TC", wn )

出现问题的地方:

  

mat2listw中的错误(W,row.names = region.id,style = style):给定的非唯一row.names

老实说,我无法看到代码中的错误在哪里。

0 个答案:

没有答案