Dear list members, i need a hint - i am stuck on my search for a function. I would like to calculate cross-correlograms between two variables (predator and prey densities) and use this as an index of spatial overlap. I used the spdep pakcage and use e.g. sp.correlogram(xy.data.nb, prey, order = 5 , method = "I", zero.policy=TRUE, style = "W") sp.correlogram(xy.data.nb, predator, order = 5 , method = "I", zero.policy=TRUE, style = "W") to calculate the (auto-) correlograms for predator and prey individually. But how do i combine them to calculate the cross-correlogram ? Any hint would be highly appreciated... Best wishes ! jens
How to calculate a cross-correlogram based on Morans I
3 messages · Jens Floeter, Edzer Pebesma
An HTML attachment was scrubbed... URL: <https://stat.ethz.ch/pipermail/r-sig-geo/attachments/20101006/1f859f22/attachment.html>
Jens, in your code snippet below, the number 6370 rings a bell. According to http://en.wikipedia.org/wiki/Earth_radius it is close to the average earth radius. In km. Given that there's just one such number, it seems the code assumes a sphere is close enough to approximate the earth.
On 10/06/2010 12:37 PM, Jens Floeter wrote:
Hello again,
okay, i found the ncf package and the correlog function.
# correlog(x, y, z, w = NULL, increment, resamp = 100, latlon = FALSE, na.rm =
FALSE, quiet = FALSE)
my short question is:
*if latlon = T and the positions are "degree, decimal-minutes" then increment
has the unit of "km" and distance bins are in "km" as well - is that correct ?*
I found it in the sourcecode :
#then generating geographic distances
if(latlon){
#these are geographic distances from lat-lon coordinates
dmat <- matrix(0, nrow = n, ncol = n)
for(i in 1:(n-1)) {
for(j in (i+1):n) {
dmat[j, i] <- gcdist(x[i], y[i], x[j], y[j])
dmat[i, j] <- dmat[j, i]
with gcdist =
r <- 360/(2 * pi)
lon1 <- x1 / r
lat1 <- y1 / r
lon2 <- x2 / r
lat2 <- y2 / r
dlon <- lon2 - lon1
dlat <- lat2 - lat1
a <- (sin(dlat/2))^2 + cos(lat1) * cos(lat2) * (sin(dlon/2))^2
c <- 2 * atan2( sqrt(a), sqrt(1-a) )
return(6370 * c)
}
but i cannot the answer from this....does gcdist deliver km units ?
Cheers!
jens
Am 05.10.2010 12:57, schrieb Jens Floeter:
Dear list members, i need a hint - i am stuck on my search for a function. I would like to calculate cross-correlograms between two variables (predator and prey densities) and use this as an index of spatial overlap. I used the spdep pakcage and use e.g. sp.correlogram(xy.data.nb, prey, order = 5 , method = "I", zero.policy=TRUE, style = "W") sp.correlogram(xy.data.nb, predator, order = 5 , method = "I", zero.policy=TRUE, style = "W") to calculate the (auto-) correlograms for predator and prey individually. But how do i combine them to calculate the cross-correlogram ? Any hint would be highly appreciated... Best wishes ! jens
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
_______________________________________________ R-sig-Geo mailing list R-sig-Geo at stat.math.ethz.ch https://stat.ethz.ch/mailman/listinfo/r-sig-geo
Edzer Pebesma Institute for Geoinformatics (ifgi), University of M?nster Weseler Stra?e 253, 48151 M?nster, Germany. Phone: +49 251 8333081, Fax: +49 251 8339763 http://ifgi.uni-muenster.de http://www.52north.org/geostatistics e.pebesma at wwu.de