Error in R density bw.SJ

Viewed 1310

I am using the density function with the SJ method:

rdat <- rnorm(111111)
density(rdat, bw = "sj")
Error in bw.SJ(x, method = "ste") : sample is too sparse to find TD

It seems to fail on large sample, stating the sample is too sparse. This has been asked before here, but has anything changed since 2008? Are there any fixes out there for this/ workarounds?

Edit: Limit seems to be 46341

1 Answers

This bug was fixed in R 3.4.0 (April, 2017).

Here is the relevant fragment from svnlog:

r71965 | maechler | 2017-01-13 04:30:18 -0600 (Fri, 13 Jan 2017) | 1 line
Changed paths:
   M /trunk/doc/NEWS.Rd
   M /trunk/src/library/stats/R/bandwidths.R
   M /trunk/src/library/stats/man/bandwidth.Rd
   M /trunk/src/library/stats/man/density.Rd
   M /trunk/src/library/stats/src/bandwidths.c

fix bw.SJ() integer overflow for large n

Here is the corresponding commit in a mirror of R source code: https://github.com/wch/r-source/commit/5af0f7200128315392cf813127a654153b5e7739

Here is the fragment from R 3.4.0 change log:

Bandwidth selectors bw.ucv(), bw.bcv() and bw.SJ() now avoid integer overflow for large sample sizes.

Related