Bugzilla – Bug 13631

quantile and IQR do not check for numeric input

Last modified: 2009-03-30 17:57:36 UTC

From: Simone Giannerini <sgiannerini@gmail.com> This report follows the post http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html where it is shown that quantile() and IQR() do not work as documented. In fact they do not check for numeric input even if the documentation says : ?quantile x numeric vectors whose sample quantiles are wanted. Missing values are ignored. ?IQR x a numeric vector. > quantile(factor(1:9)) 0% 25% 50% 75% 100% 1 3 5 7 9 Levels: 1 2 3 4 5 6 7 8 9 > IQR(factor(1:9)) [1] 4 > R.version _ platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status alpha major 2 minor 9.0 year 2009 month 03 day 26 svn rev 48224 language R version.string R version 2.9.0 alpha (2009-03-26 r48224) -- ______________________________________________________ Simone Giannerini Dipartimento di Scienze Statistiche "Paolo Fortunati" Universita' di Bologna Via delle belle arti 41 - 40126 Â Bologna, Â ITALY Tel: +39 051 2098262 Â Fax: +39 051 232153 http://www2.stat.unibo.it/giannerini/

From: Thomas Lumley <tlumley@u.washington.edu> On Mon, 30 Mar 2009 sgiannerini@gmail.com wrote: > This report follows the post > > http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html > > where it is shown that quantile() and IQR() do not work as documented. Nothing of the sort is shown! The thread argued that methods for these functions for ordered factors would be useful. > In fact they do not check for numeric input even if the documentation says = > : > > ?quantile > x numeric vectors whose sample quantiles are wanted. Missing > values are ignored. > > ?IQR > > x a numeric vector. > The documentation says that you are not allowed to pass anything except a numeric vector to quantile() and IQR(). It doesn't, for example, say you can pass an arbitrary vector that will be checked to see if it is numeric. If you have code that passes a factor to IQR(), the bug is in that code. On the other hand, as someone else has since reported, the 'missing values are ignored' statement in ?quantile is wrong (or at least incomplete). -thomas Thomas Lumley Assoc. Professor, Biostatistics tlumley@u.washington.edu University of Washington, Seattle

From: Duncan Murdoch <murdoch@stats.uwo.ca> On 3/30/2009 7:50 AM, Thomas Lumley wrote: > On Mon, 30 Mar 2009 sgiannerini@gmail.com wrote: > >> This report follows the post >> >> http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html >> >> where it is shown that quantile() and IQR() do not work as documented. > > Nothing of the sort is shown! The thread argued that methods for these functions for ordered factors would be useful. > >> In fact they do not check for numeric input even if the documentation says = >> : >> >> ?quantile >> x numeric vectors whose sample quantiles are wanted. Missing >> values are ignored. >> >> ?IQR >> >> x a numeric vector. >> > > The documentation says that you are not allowed to pass anything except a numeric vector to quantile() and IQR(). It doesn't, for example, say you can pass an arbitrary vector that will be checked to see if it is numeric. If you have code that passes a factor to IQR(), the bug is in that code. > > On the other hand, as someone else has since reported, the 'missing values are ignored' statement in ?quantile is wrong (or at least incomplete). I think that statement was wrong, and I fixed it last night, but then didn't get it committed. The commit will make it into 2.9 and R-devel today. Duncan Murdoch

From: Simone Giannerini <sgiannerini@gmail.com> Dear Thomas, On Mon, Mar 30, 2009 at 1:50 PM, Thomas Lumley <tlumley@u.washington.edu> wrote: > On Mon, 30 Mar 2009 sgiannerini@gmail.com wrote: > >> This report follows the post >> >> http://tolstoy.newcastle.edu.au/R/e6/devel/09/03/0760.html >> >> where it is shown that quantile() and IQR() do not work as documented. > > Nothing of the sort is shown! The thread argued that methods for these > functions for ordered factors would be useful. in the original thread I initiated the matters were two (at least in my intention) 1. quantile() and IQR() do not check for numeric input whereas median() has a check (for a factor input). This has nothing to deal with ordered factors 2. the opportunity of having methods for ordered factors for quantile() and the like. If, for some reason, you think that it is ok to have such check for median but not for quantile and IQR then take this as a wishlist. BTW also var() and the like do not check for factor input while mean() has the check. > x <- factor(letters[1:9]) > x [1] a b c d e f g h i Levels: a b c d e f g h i > mean(x) [1] NA Warning message: In mean.default(x) : argument is not numeric or logical: returning NA > var(x) [1] 7.5 Regards Simone > >> In fact they do not check for numeric input even if the documentation says >> = >> : >> >> ?quantile >> x Â Â Â numeric vectors whose sample quantiles are wanted. Missing >> values are ignored. >> >> ?IQR >> >> x Â Â Â a numeric vector. >> > > The documentation says that you are not allowed to pass anything except a > numeric vector to quantile() and IQR(). It doesn't, for example, say you can > pass an arbitrary vector that will be checked to see if it is numeric. If > you have code that passes a factor to IQR(), the bug is in that code. > > On the other hand, as someone else has since reported, the 'missing values > are ignored' statement in ?quantile is wrong (or at least incomplete). > > > Â Â -thomas > > Thomas Lumley Â Â Â Â Â Â Â Â Â Assoc. Professor, Biostatistics > tlumley@u.washington.edu Â Â Â Â University of Washington, Seattle > > > -- ______________________________________________________ Simone Giannerini Dipartimento di Scienze Statistiche "Paolo Fortunati" Universita' di Bologna Via delle belle arti 41 - 40126 Bologna, ITALY Tel: +39 051 2098262 Fax: +39 051 232153 http://www2.stat.unibo.it/giannerini/

NOTES: factors are disallowed in 2.10.0 Note that 'numeric' can be far more general than an atomic numeric vector and this still work.

Audit (from Jitterbug): Tue May 26 21:28:11 2009 ripley changed notes Tue May 26 21:28:11 2009 ripley moved from incoming to Analyses-fixed