Error using predict.sarlm

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Error using predict.sarlm

Chi M
I am running the following code:
Error in predict.sarlm(m1s, newdata = " geodata ", listw = shpw )

and getting the following error:
Error in predict.sarlm(m1s, newdata = "geodata", listw = shpw,  :
  newdata should have region.id as row.names

I did a search and found a post about the same problem:
http://r-sig-geo.2731867.n2.nabble.com/Error-while-using-predict-sarlm-td7592817.html


So, per the post, I have ensured that region.id matches row names:
> str(attr( geodatanb , "region.id"))
 chr [1:74] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14"
"15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
"30" "31" "32" "33" ...
> str(row.names(generalrateforpred))
 chr [1:74] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14"
"15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
"30" "31" "32" "33" ...
all(row.names(geodata@data) %in% attr( geodatanb, "region.id"))
[1] TRUE

Unfortunately, I'm still getting the error.

Could anyone offer any further assistance?

Thank you,
Chi

        [[alternative HTML version deleted]]

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Reply | Threaded
Open this post in threaded view
|

Re: Error using predict.sarlm

Roger Bivand
Administrator
On Tue, 25 Feb 2020, Chiedza Machingaidze wrote:

> I am running the following code:
> Error in predict.sarlm(m1s, newdata = " geodata ", listw = shpw )
>
> and getting the following error:
> Error in predict.sarlm(m1s, newdata = "geodata", listw = shpw,  :
>  newdata should have region.id as row.names

Please try to provide a reproducible example, such as:

data(oldcol, package="spdep")
lw <- spdep::nb2listw(COL.nb)
COL.mix.eig <- lagsarlm(CRIME ~ INC + HOVAL, data=COL.OLD, lw, Dubin=TRUE)
predict(COL.mix.eig, newdata="COL.OLD", listw=lw)
#Error in predict.sarlm(COL.mix.eig, newdata = "COL.OLD", listw = lw) :
#  newdata should have region.id as row.names

If this corresponds to your case, why is the newdata= object in quotation
marks?

Please try to post plain text only, HTML makes it harder to read code.

Hope this clarifies,

Roger

>
> I did a search and found a post about the same problem:
> http://r-sig-geo.2731867.n2.nabble.com/Error-while-using-predict-sarlm-td7592817.html
>
>
> So, per the post, I have ensured that region.id matches row names:
>> str(attr( geodatanb , "region.id"))
> chr [1:74] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14"
> "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
> "30" "31" "32" "33" ...
>> str(row.names(generalrateforpred))
> chr [1:74] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10" "11" "12" "13" "14"
> "15" "16" "17" "18" "19" "20" "21" "22" "23" "24" "25" "26" "27" "28" "29"
> "30" "31" "32" "33" ...
> all(row.names(geodata@data) %in% attr( geodatanb, "region.id"))
> [1] TRUE
>
> Unfortunately, I'm still getting the error.
>
> Could anyone offer any further assistance?
>
> Thank you,
> Chi
>
> [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> [hidden email]
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>

--
Roger Bivand
Department of Economics, Norwegian School of Economics,
Helleveien 30, N-5045 Bergen, Norway.
voice: +47 55 95 93 55; e-mail: [hidden email]
https://orcid.org/0000-0003-2392-6140
https://scholar.google.no/citations?user=AWeghB0AAAAJ&hl=en

_______________________________________________
R-sig-Geo mailing list
[hidden email]
https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Roger Bivand
Department of Economics
Norwegian School of Economics
Helleveien 30
N-5045 Bergen, Norway