[Rd] density(), with argument of length 1 (PR#2593)
John Maindonald
u9801539@leonard.anu.edu.au
Sun Mar 2 05:55:03 2003
> From p.dalgaard@biostat.ku.dk Sat Mar 1 21:22:47 2003
> X-Authentication-Warning: blueberry.kubism.ku.dk: pd set sender to p.dalgaard@biostat.ku.dk using -f
> To: u9801539@leonard.anu.edu.au
> Cc: r-devel@stat.math.ethz.ch, R-bugs@biostat.ku.dk
> Subject: Re: [Rd] density(), with argument of length 1 (PR#2593)
> From: Peter Dalgaard BSA <p.dalgaard@biostat.ku.dk>
> Date: 01 Mar 2003 11:22:48 +0100
> User-Agent: Gnus/5.09 (Gnus v5.9.0) Emacs/21.2
> MIME-Version: 1.0
> X-Sender: p.dalgaard@biostat.ku.dk
> X-Sender-Domain: biostat.ku.dk
> X-Spam-Status: Scanned
> X-Spam-Score: (-3.6)
> X-Spam-Tests: IN_REP_TO,X_AUTH_WARNING,MAILTO_TO_SPAM_ADDR
> X-Scanned-By: MIMEDefang 2.15 (www dot roaringpenguin dot com slash mimedefang)
>
> u9801539@leonard.anu.edu.au writes:
>
> > The following is from version 1.6.2 of R under Windows,
> > or 1.6.1 under Mac OSX/X11
> >
> > > density(1)
> > Error in if (!(lo <- min(hi, IQR(x)/1.34))) (lo <- hi) || (lo <- abs(x[1])) || :
> > missing value where logical needed
> >
> > I am not sure how this should be handled.
>
> It comes from this bit of code:
>
> > bw.nrd0
> function (x)
> {
> hi <- sd(x)
> if (!(lo <- min(hi, IQR(x)/1.34)))
> (lo <- hi) || (lo <- abs(x[1])) || (lo <- 1)
> 0.9 * lo * length(x)^(-0.2)
> }
>
> in which hi is NA if x has length 1. A pragmatic way out would seem to
> be to change the first line to
>
> hi <- if (length(x) > 1) sd(x) else 0
>
> (and I wonder why the author didn't go all the way with the ||
> sneakiness and said
>
> (lo <- min(hi, IQR(x)/1.34)) ||
> (lo <- hi) || (lo <- abs(x[1])) || (lo <- 1)
Note that two of the other three bandwith rules also require attention:
> bw.ucv(1)
Error in fmin(function(arg) f(arg, ...), lower, upper, tol) :
invalid xmin value
> bw.SJ(1)
Error in TDh(cnt, b, n, d) : NA/NaN/Inf in foreign function call (arg 5)
The remaining rule has:
> bw.nrd(1)
[1] NA
which is reasonable.
John Maindonald email : john.maindonald@anu.edu.au
Centre for Bioinformation Science, phone : (6125)3473
c/o MSI, fax : (6125)5549
John Dedman Mathematical Sciences Building (Building 27)
Australian National University
Canberra ACT 0200
Australia