[Rd] Unwanted behaviour of bw.nrd: sometimes, zero is returned as a valid bandwidth

Andreï V. Kostyrka fifis.himik at gmail.com
Wed Feb 21 00:17:09 CET 2018

Dear all,

Sorry if I am posting to the wrong place, but I could not find the link for
registration on the bug tracker, that’s why I am writing here.

I think there is inconsistency between two R functions from the stats
package, bw.nrd0 and bw.nrd.

Consider the following vector:
D <- c(0, 1, 1, 1, 1)

bw.nrd(D) returns zero bandwidth for this object even without a warning.
Considering the fact that in most cases, one divides something by the
bandwidth, it is highly undesirable that these function return zero
bandwidth without a warning.

Contrast bw.nrd0: it has three failsafes. First, if the minimum of SD and
IQR/1.34 is 0, it tries three things: set the base multiplier to SD, or to
|x[1]|, or to 1.

In my opinion, bw.nrd should have either one of these failsafes or a
warning that the vanilla formula equals to zero and that the user should
try another method of bandwidth selection (just like bw.ucv warns if the
minimum occurred at one end). It would be better than suddenly discovering
NaNs or NAs without even knowing the possible cause.

Bien cordialement,  |  Yours sincerely,
Andreï V. Kostyrka.
http://kostyrka.ru, http://kostyrka.ru/blog

	[[alternative HTML version deleted]]

More information about the R-devel mailing list