Peter Ruckdeschel
2007-Jun-28 21:05 UTC
[Rd] inaccuracy in qbinom with partial argument matching
Hi, I found the following strange effect with qbinom & partial argument matching p0 <- pbinom(0, size = 3, prob = 0.25) qbinom(p0, size = 3, prob = 0.25) ## 0 o.k. qbinom(p0-0.05, size = 3, prob = 0.25) ## 0 o.k. ## positional matching: qbinom(p0, 3, 0.25) ## 0 o.k. ## partial argument matching: qbinom(p0 , s = 3, p = 0.25) ## 1 ??? qbinom(p0-0.05, s = 3, p = 0.25) ## 1 ??? qbinom(p0-0.06, s = 3, p = 0.25) ## 0 o.K. Unfortunately I have no I idea how to fix this. I guess however that this will happen for other cases as well, but I have not pursued this further. Best, Peter platform i386-pc-mingw32 arch i386 os mingw32 system i386, mingw32 status major 2 minor 5.0 year 2007 month 04 day 23 svn rev 41293 language R version.string R version 2.5.0 (2007-04-23)
Prof Brian Ripley
2007-Jun-29 06:03 UTC
[Rd] inaccuracy in qbinom with partial argument matching
On Thu, 28 Jun 2007, Peter Ruckdeschel wrote:> Hi, > > I found the following strange effect with > qbinom & partial argument matching > > p0 <- pbinom(0, size = 3, prob = 0.25) > qbinom(p0, size = 3, prob = 0.25) ## 0 o.k. > qbinom(p0-0.05, size = 3, prob = 0.25) ## 0 o.k. > > ## positional matching: > qbinom(p0, 3, 0.25) ## 0 o.k. > > ## partial argument matching: > qbinom(p0 , s = 3, p = 0.25) ## 1 ??? > qbinom(p0-0.05, s = 3, p = 0.25) ## 1 ??? > qbinom(p0-0.06, s = 3, p = 0.25) ## 0 o.K. > > Unfortunately I have no I idea how to fix this.You use a call that specifies your intentions accurately. This is not 'partial argument matching': 'p' is an exact match to the first argument of> args(qbinom)function (p, size, prob, lower.tail = TRUE, log.p = FALSE) and that is how argument matching in R is documented to work. The 'inaccuracy' is in the diagnosis: please see the FAQ. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Peter Ruckdeschel
2007-Jun-29 10:06 UTC
[Rd] inaccuracy in qbinom with partial argument matching
Petr Savicky wrote:> Brian Ripley wrote: >> I wrote: >> > ## partial argument matching: >> > qbinom(p0 , s = 3, p = 0.25) ## 1 ??? >> > qbinom(p0-0.05, s = 3, p = 0.25) ## 1 ??? >> > qbinom(p0-0.06, s = 3, p = 0.25) ## 0 o.K. >> > >> > Unfortunately I have no I idea how to fix this. >> >> You use a call that specifies your intentions accurately. This is not >> 'partial argument matching': 'p' is an exact match to the first argument >> of >> >> > args(qbinom) >> function (p, size, prob, lower.tail = TRUE, log.p = FALSE) >> >> and that is how argument matching in R is documented to work. >> >> The 'inaccuracy' is in the diagnosis: please see the FAQ. > > Let me add an explanation, why > qbinom(p0 , s = 3, p = 0.25) > does not produce an error message about missing "prob" argument: > Since "size" and "p" arguments are given, p0 is used for > the third argument and not for the first. > > Although the behavior is logical, it may not be immediately clear. > I do not see this case explicitly in FAQ or R-intro.pdf 10.3.To close this thread: First thanks to Brian and Petr for their explanation ---and to Petr for defending me. But I think, Brian was right, it was my fault not to see that qbinom's first argument 'p' was matched against my abbreviated 'prob' argument 0.25, which is ---I think--- the reason for Brian's "please see the FAQ"... Although not itself an FAQ nor in the R-intro manual, argument matching is completely & clearly described in http://cran.r-project.org/doc/manuals/R-lang.html#Argument-matching In fact my code is a badly chosen example: I am working on automatically generated q-, (and r,d,p)- functions, so left continuity of q<>-fct.'s is an issue. Unfortunately numbers p0 and .25 are so close together that they gave results only differing by 1 when interchanged, so I was led to the conclusion that it was a left-continuity-issue of qbinom with partial matched arguments which it was obviously not ---sorry for bothering you. As a conclusion which may be worth noting for other occasions as well: Be careful with partial argument matching ! Best, Peter