#StackBounty: #r #gis #geospatial #spatial Solving "Error in if (obs <= ei) 2 * pv else 2 * (1 – pv) : missing value where TRUE…

Bounty: 50

developers!

I have encountered an error message

Error in if (obs <= ei) 2 * pv else 2 * (1 – pv) : missing value where
TRUE/FALSE needed

stopping me to get the value from Moran’s I function from ape package. Here is what I did:

library(ape)

nrstp <- data.frame(
     X = c(300226.9, 300224.6, 300226.4, 300226.1, 300224.0, 300226.4, 300225.7, 300226.4, 300226.1, 300226.4, 300226.3, 300226.3, 300227.1),
     Y = c(5057949, 5057952, 5057950, 5057950, 5057956, 5057950, 5057950, 5057950, 5057950, 5057950, 5057950, 5057950, 5057949),
     V3 = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0))

nrstp = data.frame(nrstp)
dist = as.matrix(dist(cbind(nrstp$X, nrstp$Y)))
invdist = 1/dist
invdist[is.infinite(invdist)] <- 0
moranI = Moran.I(nrstp$V3, invdist)

The intention of this code is to calculate Moran’s I from a series of point to check spatial autocorrelation. So far, this seems to be the only function working for Moran’s I in R. After a few testing (I have thousands groups of points), this error seems only happen to the input vector having only one value (I tried other numbers than 0, it still raise this error).

Could someone help me improve this code? Or are their better suggestion to calculate Moran’s I or test spatial autocorrelation from linestring (those point groups are origin point of one linestring and the closest points from other linestring within 10 meter buffer of such origin point)?

Thank you ahead for any help!


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.