[R-sig-Geo] [Local.moran.exact] Error in integrate : evaluation of function gave a result of wrong type
Lisa Menez
lisa.menez at free.fr
Mon Jul 17 15:25:37 CEST 2017
Good morning to all
I am currently trying to use local.moran.exact function from spdep package.
More precisely, I am willing to use the alternative version (local.moran.exact.alt)
but I obtain an error message I can’t figure out :
"Error in integrate(integrand, lower = 0, upper = upper) : evaluation of function gave a result of wrong type"
#======================================
#My issue is somewhere is those lines :
#======
setwd(".")
library(spdep)
EU_NUTS <- read.table("./mydata.txt")
###distance based neighbors - - -
Coord <- cbind(EU_NUTS$"x", EU_NUTS$"y")
EU_NUTS_kn0 <- knn2nb(knearneigh(Coord, k = 1), row.names =EU_NUTS$NUTS_ID)
dist <- unlist(nbdists(EU_NUTS_kn0, Coord))
summary(dist)
max_k0 <- max(dist)
EU_NUTS_kd1 <- dnearneigh(Coord, d1 = 0, d2 = 1 * max_k0, row.names =EU_NUTS$NUTS_ID)
Kd1list<-nb2listw(EU_NUTS_kd1, glist=NULL, style="W", zero.policy=FALSE)
###OLS model
OLS<-lm(EU_NUTS$"GrowthR" ~ log(EU_NUTS$"X2000"))
###SAR model
ERROR<-errorsarlm(OLS,, Kd1list , na.omit, etype="emixed", method="eigen", quiet=NULL,tol.solve=1.0e-10, zero.policy= TRUE)
lm.error <- lm(ERROR$tary ~ ERROR$tarX - 1)
Omega <- invIrW(Kd1list, rho=ERROR$lambda)
Omega <- tcrossprod(Omega)
localmoran.exact.alt(lm.error, nb=EU_NUTS_kd1, Omega=Omega, style = "S", zero.policy = TRUE, alternative = "greater", spChk = NULL, resfun = residuals,
save.Vi = FALSE, useTP=TRUE, truncErr=1e-6, zeroTreat=0.1)
#======
#The error message is get is :
#======
Error in integrate(integrand, lower = 0, upper = upper) : evaluation of function gave a result of wrong type
#=======================
Does someone have any idea of what I am doing wrong ?
The full dataset is available here :
http://www.i3s.unice.fr/~menez/RCode/mydata.txt <http://www.i3s.unice.fr/~menez/RCode/mydata.txt>
The Rcode is here : http://www.i3s.unice.fr/~menez/RCode/moran.R <http://www.i3s.unice.fr/~menez/RCode/moran.R>
Thank you for your attention and your help.
Best Regards
Lisa
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list