[R-sig-Geo] classIntervals issue

Roger Bivand Roger.Bivand at nhh.no
Thu May 26 22:05:55 CEST 2011


On Thu, 26 May 2011, Carson Farmer wrote:

> Hi List, not sure if this is *really* an r-sig-geo question, but since
> Roger is the maintainer for the classInt package, I thought I'd start
> here.
>
> For some reason, whenever creating a classIntervals object, if I try
> to print/access said object's "table" attribute for using in a legend
> (see p. 79 in ASDA with R), I get the following error message:
>
>> classIntervals(layer$incoming, n=5, style="fisher", cutlabels=TRUE)
> style: fisher
>      [3,813)  [813,2782.5) [2782.5,6365)  [6365,12569) [12569,20422]
>         2993           306            84            20             6
> Warning messages:
> 1: In factorial(n - 1) : value out of range in 'gammafn'
> 2: In factorial(n - k) : value out of range in 'gammafn'
>
> Can anyone tell me why? For reference, the data that I'm trying to
> classify looks like this (nothing too weird that I can see):
>
>> summary(layer$incoming)
>   Min. 1st Qu.  Median    Mean 3rd Qu.    Max.
>    3.0    43.0    86.0   434.1   263.0 20420.0

Class intervals must be relevant, no?

Reproducing:

> x <- exp(runif(3409, 0, 10))
> summary(x)
     Min.  1st Qu.   Median     Mean  3rd Qu.     Max.
     1.00    11.48   143.70  2277.00  1776.00 21970.00
> cl <- classIntervals(x, n=5, style="fisher", cutlabels=TRUE)
> cl
style: fisher
   [1.000301,1745.2)   [1745.2,5520.098) [5520.098,10475.15) 
[10475.15,16236.95)
                2549                 375                 217 
147
[16236.95,21965.68]
                 121
Warning messages:
1: In factorial(n - 1) : value out of range in 'gammafn'
2: In factorial(n - k) : value out of range in 'gammafn'

> factorial(3409-1)
[1] Inf
Warning message:
In factorial(3409 - 1) : value out of range in 'gammafn'
> factorial(3409-5)
[1] Inf
Warning message:
In factorial(3409 - 5) : value out of range in 'gammafn'
> factorial
function (x)
gamma(x + 1)
<environment: namespace:base>
> gamma(3409)
[1] Inf
Warning message:
value out of range in 'gammafn'
> nPartitions
function (x)
{
     n <- attr(x, "nobs")
     k <- length(x$brks) - 1
     (factorial(n - 1))/(factorial(n - k) * factorial(k - 1))
}
<environment: namespace:classInt>
> nPartitions(cl)
[1] NaN
Warning messages:
1: In factorial(n - 1) : value out of range in 'gammafn'
2: In factorial(n - k) : value out of range in 'gammafn'

This is coming from the code in the print method that shows how many 
combinations of 3409 objects into 5 classes are possible, which is so 
large that the calls to factorial() and from there to gamma() fail. I can 
put in a check for n > 170 to suppress this information, because 
factorial(n-1) fails just above there.

Interesting point!

Roger


>
>> sessionInfo()
> R version 2.13.0 (2011-04-13)
> Platform: x86_64-pc-linux-gnu (64-bit)
>
> locale:
> [1] LC_CTYPE=en_IE.utf8       LC_NUMERIC=C
> LC_TIME=en_IE.utf8
> [4] LC_COLLATE=en_IE.utf8     LC_MONETARY=C
> LC_MESSAGES=en_IE.utf8
> [7] LC_PAPER=en_IE.utf8       LC_NAME=C                 LC_ADDRESS=C
> [10] LC_TELEPHONE=C            LC_MEASUREMENT=en_IE.utf8
> LC_IDENTIFICATION=C
>
> attached base packages:
> [1] stats     graphics  grDevices utils     datasets  methods   base
>
> other attached packages:
> [1] lattice_0.19-26   classInt_0.1-14   e1071_1.5-25      class_7.3-3
>     TeachingDemos_2.7
> [6] sp_0.9-80         CircStats_0.2-4   boot_1.2-43       MASS_7.3-13
>
> loaded via a namespace (and not attached):
> [1] grid_2.13.0  tools_2.13.0
>
>

-- 
Roger Bivand
Economic Geography Section, Department of Economics, Norwegian School of
Economics and Business Administration, Helleveien 30, N-5045 Bergen,
Norway. voice: +47 55 95 93 55; fax +47 55 95 95 43
e-mail: Roger.Bivand at nhh.no



More information about the R-sig-Geo mailing list