[R] truehist bug?

Martin Maechler maechler at stat.math.ethz.ch
Tue Mar 20 08:49:16 CET 2007


>>>>> "Gad" == Gad Abraham <g.abraham at ms.unimelb.edu.au>
>>>>>     on Tue, 20 Mar 2007 17:02:18 +1100 writes:

    Gad> Hi,
    Gad> Is this a bug in truehist()?

    >> library(MASS)
    >> x <- rep(1, 10)
    >> truehist(x)
    Gad> Error in pretty(data, nbins) : invalid 'n' value

You get something similar though slightly more helpful
from
	hist(x, "scott")

which then uses the same method for determining the number of bins /
classes for the histogram.

I'd say the main "bug" is in   
  nclass.scott()   [ and  also nclass.FD() ]

which do not work when  var(x) == 0  as in this case.
One could argue that  

1) truehist(x) should not use "scott" as
  default when var(x) == 0   {hence a buglet in truehist()}

and either

2) both hist() and truehist() should produce a better error
  message when "scott" (or "FD") is used explicitly and var(x) == 0

or, rather IMO,

3) nclass.scott(x) and nclass.FD(x) should be extended to return a 
  non-negative integer even when  var(x) == 0

Martin Maechler, ETH Zurich



More information about the R-help mailing list