<div style="font-family: Courier New,Courier,monospace;">-----Roger Bivand <Roger.Bivand@nhh.no> wrote: -----<br></div><font style="font-family: Courier New,Courier,monospace;" color="#990099"><br></font><blockquote style="border-left: 2px solid rgb(0, 0, 0); padding-right: 0px; padding-left: 5px; margin-left: 5px; margin-right: 0px; font-family: Courier New,Courier,monospace;"><font size="3">On Wed, 18 Oct 2006 White.Denis@epamail.epa.gov wrote:<br><br>> I have a 1000 x 1000 grid of categorical values (nine of these) and want<br>> to compute and plot a correlogram. Function cell2nb() will take a while<br>> it appears but if that succeeds then can methods of sp.correlogram() be<br>> used on categorical data? What are "style" options in sp.correlogram()?<br>> <br><br>Sorry, could you say how a correlogram might be constructed for <br>categorical values (eg. land cover)? Wouldn't join counts be a more <br>natural choice? joincoint.multi() in spdep has a Jtot value of total <br>different category joins, so using that with different lags of a cell2nb() <br>neighbour list might work. However, the 1M cell grid is pretty large for <br>cell2nb(), using dnearneigh() on cell centres may be faster and scale <br>better, (and other possibilities should exist) and nblag() will be <br>definitely sub-optimal in this setting. For join counts, the "B" weights <br>style is the obvious one to chose. Note that joincoint.multi() is not <br>coded in C.<br><br>This would need trying on a small subset and scaling up - I think that <br>alternative routes to constructing the lagged neighbour lists would be <br>preferable.<br><br>Roger<br><br></font></blockquote><br>I wrote a short function to compute proportion agreement between classes at different lags, R code below. Because it's a brute force O(n^2) algorithm, it takes way too long in R for datasets with more than some 10's of points. So I wrote a C version that took about 20 hours for 1M points on a 2GHz linux computer. Subsampling from the 1000x1000 image reduced time considerably, naturally.<br><br>I haven't looked at Cliff and Ord or other texts on these kinds of statistics for a long time and I don't know whether this simple proportion agreement measure is closely related to a multinomial joincount or not. And so I don't know what the test for non-randomness is or what a variance measure is, etc. It does seem to portray the spatial pattern in agreement though.<br><br>isotaxogram <- function (pts, nlags=10, maxdist)<br><br># Calculate proportion agreement of categorical point data <br># at successive lags<br>#<br># pts matrix or data frame with columns/names<br># "x", "y", "val"<br># nlags number of lags in the output function<br># maxdist maximum distance over which to compute the function;<br># needs to be specified<br><br>{<br> agree <- num <- lag <- rep (0, nlags)<br> for (i in 1:(nrow(pts)-1))<br> {<br> x1 <- pts[i, "x"]<br> y1 <- pts[i, "y"]<br> for (j in (i+1):nrow(pts))<br> {<br> x2 <- pts[j, "x"]<br> y2 <- pts[j, "y"]<br> d <- sqrt ((x2-x1)^2 + (y2-y1)^2)<br> d <- round (d / maxdist * nlags)<br> a <- as.integer (pts[i, "val"] == pts[j, "val"])<br> if (d %in% 1:nlags)<br> {<br> agree[d] <- agree[d] + a<br> num[d] <- num[d] + 1<br> }<br> }<br> }<br> for (k in 1:nlags) <br> {<br> lag[k] <- k * (maxdist / nlags)<br> if (num[k] != 0) agree[k] <- agree[k] / num[k]<br> }<br> return (list (agree=agree, lag=lag, num=num))<br>}<br><br style="font-family: Courier New,Courier,monospace;">