[R-sig-Geo] Could you add my 'Jenks' method to your classInt package?

Hisaji ONO hi_ono2001 at ybb.ne.jp
Wed Nov 21 09:33:55 CET 2007


Hello.

 I've tried to port Java code for Jenks optimization
classification method "natural break" to R, although far
from smart coding.

 My java code was ported Jenks's Basic code and I checked
these results compared to results of ArcView 3.x.

 Jenks method derived from Fischer, but seems to be a
little different in the algorithm.

 My code's results are similar to results of current
ArcGIS's, but not equal to them. Accordindg to Murray, A.
T. & Shyy, T. K.'s papaer (IJGIS, 2000, 14-7, 649-667,
http://geog-www.sbs.ohio-state.edu/faculty/murray/personal/research/crimepubs/murray-shyy2000.pdf),
there are difference between ArcGIS's and MapInfo's. How
about Autodesk's Map Guide Open Source which has employed
Jenks's method as a function.

 Could you try my following code and add this into your
classInt package if you like?


 Regards.





else if (style == "fisher") {
---- cut ---- cut ---- cut ---- cut ---- cut ----
        }
 else if (style == "Jenks") { # Jenks Optimisation Method
            d<- sort(var)
           #work<-matrix(0,k,length(d))
           mat1<-matrix(1,length(d),k)
           mat2<-matrix(0,length(d),k)
           mat2[2:length(d),1:k]<-10000000 #R's max double
value?
           v<-0

           for(l in 2:length(d)){
             s1=s2=w=0
             for(m in 1:l){
               i3 <- l - m + 1
               val <- d[i3]
               s2 <- s2 + val * val
               s1 <- s1 + val
               w<-w+1
               v <- s2 - (s1 * s1) / w
               i4 <- trunc(i3 - 1)

               if(i4 !=0){
                 for(j in 2:k){
                   if(mat2[l,j] >= (v + mat2[i4, j - 1])){
                     mat1[l,j] <- i3
                     mat2[l,j] <- v + mat2[i4, j - 1]
                   }
                 }
               }
             }
             mat1[l,1] <- 1
             mat2[l,1] <- v
           }

           kclass<-1:k
           kclass[k] <-length(d)
           k <- length(d)
           last<-length(d)
           for(j in length(kclass):1){
             id <- trunc(mat1[k,j]) - 1
             kclass[j - 1] <- id
             k <- id #lower
             last <- k -1 #upper
           }
           brks<-d[c(1, kclass)]
         }
         else stop(paste(style, "unknown"))




More information about the R-sig-Geo mailing list