[Rd] ansari.test.default: bug in call to uniroot?

Stephen Weigand weigand.stephen at gmail.com
Thu Mar 29 22:36:10 CEST 2007


A recent message on ansari.test() prompted me to play with the examples. This
doesn't work for me in R version 2.4.1

R> ansari.test(rnorm(100), rnorm(100, 0, 2), conf.int = TRUE)

Error in uniroot(ab, srange, tol = 1e-04, zq = qnorm(alpha/2, lower = FALSE)) :
	object "ab" not found

It looks like there's a small typo in ccia() inside
ansari.test.default() in which 'ab' is
passed to uniroot rather than 'ab2'. The definition of ccia below was
just copied
from https://svn.r-project.org/R/trunk/src/library/stats/R/ansari.test.R

ccia <- function(alpha) {
     ## Check if the statistic exceeds both quantiles
     ## first.
     statu <- ab2(srange[1], zq=qnorm(alpha/2))
     statl <- ab2(srange[2], zq=qnorm(alpha/2, lower=FALSE))
     if (statu > 0 || statl < 0) {
         warning("samples differ in location: cannot compute
confidence set, returning NA")
         return(c(NA, NA))
     }
     u <- uniroot(ab2, srange, tol=1e-4,
                  zq=qnorm(alpha/2))$root
     l <- uniroot(ab, srange, tol=1e-4,
                  zq=qnorm(alpha/2, lower=FALSE))$root
     ## The process of the statistics does not need to be
     ## monotone: sort is ok here.
     sort(c(u, l))
 }

Stephen
Rochester, MN USA



More information about the R-devel mailing list