From weigand.stephen at gmail.com  Thu Mar 29 22:36:10 2007
From: weigand.stephen at gmail.com (Stephen Weigand)
Date: Thu, 29 Mar 2007 15:36:10 -0500
Subject: [Rd] ansari.test.default: bug in call to uniroot?
Message-ID: <bc47d3330703291336p58257253ufc43920d782e2dca@mail.gmail.com>

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



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