[R-sig-Geo] [localmoran.exact]
Lisa Menez
li@@@menez @ending from free@fr
Mon Aug 13 15:56:22 CEST 2018
Dear all,
I have been trying to obtain local Moran’s I with the exact approach (localmoran.exact)
but I have some issues and would need your help.
I am trying to bring to light how spatial patterns of wealth have evolved from 2000 to 2016 in the European Union.
Looking at the Regional Gross Domestic Product (GDP) of European regions, my lm model looks like this :
lm(log(EU_NUTS using data[,year[i]])~1+factor(EU_NUTS using data$NUTS_L1))
where log(EU_NUTS using data[,year[i]]) are log of regional GDPs
and factor(EU_NUTS using data$NUTS_L1) is the vector of country dummies.
Sadly, I obtain an error message that says :
Error in integrate(integrand, lower = 0, upper = upper) :
a limit is missing
Moreover : Warning messages:
1: In sqrt(2 * t2 - t1^2) : production of NaN
2: In sqrt(2 * t2 - t1^2) : production of NaN
According to the GitHub source code ,
Vi <- listw2star <https://rdrr.io/cran/spdep/man/localmoran.sad.html>(B, select[i], style=style, n, D <https://rdrr.io/r/stats/deriv.html>, a,
zero.policy=zero.policy)
Viu <- lag.listw <https://rdrr.io/cran/spdep/man/lag.listw.html>(Vi, u, zero.policy=TRUE <https://rdrr.io/r/base/logical.html>)
Ii <- c <https://rdrr.io/r/base/c.html>(crossprod <https://rdrr.io/r/base/crossprod.html>(u, Viu) / utu)
ViX <- lag.listw <https://rdrr.io/cran/spdep/man/lag.listw.html>(Vi, X, zero.policy=TRUE <https://rdrr.io/r/base/logical.html>)
MViM <- t <https://rdrr.io/r/base/t.html>(X) %*% ViX %*% XtXinv
t1 <- -sum <https://rdrr.io/r/base/sum.html>(diag <https://rdrr.io/r/base/diag.html>(MViM))
sumsq.Vi <- function <https://rdrr.io/r/base/function.html>(x) {
if <https://rdrr.io/r/base/Control.html> (is.null <https://rdrr.io/r/base/NULL.html>(x)) NA <https://rdrr.io/r/base/NA.html>
else <https://rdrr.io/r/base/Control.html> sum <https://rdrr.io/r/base/sum.html>(x^2)
}
trVi2 <- sum <https://rdrr.io/r/base/sum.html>(sapply <https://rdrr.io/r/base/lapply.html>(Vi$weights <https://rdrr.io/r/stats/weights.html>, sumsq.Vi), na.rm=TRUE <https://rdrr.io/r/base/logical.html>)
t2a <- sum <https://rdrr.io/r/base/sum.html>(diag <https://rdrr.io/r/base/diag.html>(t <https://rdrr.io/r/base/t.html>(ViX) %*% ViX %*% XtXinv))
t2b <- sum <https://rdrr.io/r/base/sum.html>(diag <https://rdrr.io/r/base/diag.html>(MViM %*% MViM))
t2 <- trVi2 - 2*t2a + t2b
e1 <- 0.5 * (t1 + sqrt <https://rdrr.io/r/base/MathFun.html>(2*t2 - t1^2))
en <- 0.5 * (t1 - sqrt <https://rdrr.io/r/base/MathFun.html>(2*t2 - t1^2))
My guess is that my setting causes (2*t2<t1^2) : Is it ? Why would it ?
My database is available here : http://hcc.cnrs.fr/wp-content/uploads/2018/08/mydata2018-1.txt <http://hcc.cnrs.fr/wp-content/uploads/2018/08/mydata2018-1.txt>
and my code : http://hcc.cnrs.fr/wp-content/uploads/2018/08/myCode_2018.txt <http://hcc.cnrs.fr/wp-content/uploads/2018/08/myCode_2018.txt>
I thank you very much for your attention and your help.
Best Regards
Lisa
PhD Student
GREDEG, Université Côté d’Azur
[[alternative HTML version deleted]]
More information about the R-sig-Geo
mailing list