Bug 14514 - mantelhaen.test (exact=F, alternative = "less") can give 1 - p-value
mantelhaen.test (exact=F, alternative = "less") can give 1 - p-value
Status: CLOSED FIXED
Product: R
Classification: Unclassified
Component: Analyses
R 2.12.1
ix86 (32-bit) Windows 32-bit
: P5 normal
Assigned To: R-core
: 14689 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2011-03-01 00:06 UTC by Sam Buttrey
Modified: 2011-09-29 21:14 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Sam Buttrey 2011-03-01 00:06:15 UTC
Hi. I believe that mantelhaen.test is giving the wrong p-value when I call it with a one-sided alternative and exact=F, and I think I know why. First, the example:

> Nitrous = array(c(32,210,8,26,18,21,3,3,7,75,0,10),c(2,2,3))
#
# Data are from Conover, "Nonparametric Statistics", 3rd Ed, p. 197,
# re-arranged to make a lower-tail test the issue of relevance:  we
# want to see if pregnant nurses exposed to nitrous oxide have higher
# rates of miscarriage, stratifying on the type of nurse.
#
> dimnames(Nitrous) = list(c("Exposed","NotExposed"),
c("FullTerm","Miscarriage"),c("DentalAsst","OperRoomNurse","OutpatientNurse"))
#
# Now consider this:
#
mantelhaen.test (Nitrous, exact=T, alternative="less")$p.value
[1] 0.1958908
# 
mantelhaen.test (Nitrous, exact=F, alternative="less")$p.value
[1] 0.8009925

I believe the problem lies in the lines

        if (!exact) {
            ...
            DELTA <- abs(sum(x[1, 1, ] - s.x[1, ] * s.y[1, ]/n))
            ...
            if (alternative == "two.sided") 
                PVAL <- pchisq(STATISTIC, PARAMETER, lower.tail = FALSE)
            else {
                z <- sign(DELTA) * sqrt(STATISTIC)
               ...
            

By the time we get to the assignment of z, DELTA is already the result of a call to abs(), so its sign is always 1.

I got good results with something like this:
        if (!exact) {
           ...
            DELTA <- sum(x[1, 1, ] - s.x[1, ] * s.y[1, ]/n)
            sign.DELTA <- sign (DELTA)
            DELTA <- abs (DELTA)
            ...
            if (alternative == "two.sided") 
                PVAL <- pchisq(STATISTIC, PARAMETER, lower.tail = FALSE)
            else {
                z <- sign.DELTA * sqrt(STATISTIC)

I hope this is of interest,
Sam Buttrey
Comment 1 Brian Ripley 2011-03-06 18:44:53 UTC
Changed in 2.12.2 patched
Comment 2 Mikko Korpela 2011-09-29 21:14:18 UTC
*** Bug 14689 has been marked as a duplicate of this bug. ***