Bug 14689 - Problem with the mantelhaen.test() function in one-sided tests
Summary: Problem with the mantelhaen.test() function in one-sided tests
Status: CLOSED DUPLICATE of bug 14514
Alias: None
Product: R
Classification: Unclassified
Component: Analyses (show other bugs)
Version: R 2.12.2
Hardware: ix86 (32-bit) Windows 32-bit
: P5 critical
Assignee: R-core
Depends on:
Reported: 2011-09-28 13:01 UTC by Gael M
Modified: 2015-12-14 13:45 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Gael M 2011-09-28 13:01:54 UTC

I cannot understand a result given by the mantelhaen.test() in one-sided tests.
You will find below the code that gives the strange result.
I do not have this for the fisher.test() function.

Thanks in advance for the comment.


Gael M.

## Creation of the table obs3

tempo <- list(c("Non", "Oui"), c("Oui", "Non"), c("Jaune", "Jaune.rouge", "Rouge")) 
names(tempo) <- c("Verse", "Attaque", "Couleur")
obs3 <- as.table(array(c(13, 12, 7, 16, 12, 2, 3, 5, 11, 4, 11, 3), dim = c(2, 2, 3), dimnames=tempo))

## Lower-tailed test : the common odds ratio is 2.315991 and the p-value  0.9765

mantelhaen.test(obs3, exact=FALSE, correct=FALSE, alternative="less")

## Computation of the Z statistic and p value

n1.z <- margin.table(obs3[1,,],2)
n.1z <- margin.table(obs3[,1,],2)
n.2z<- margin.table(obs3[,2,],2)
nz <- margin.table(obs3,3)
t11z <- n1.z*n.1z/nz
n12z<-obs3[1, 2,]
n22z<-obs3[2, 2,]
n1.z<- margin.table(obs3[1,,],2)
n2.z<- margin.table(obs3[2,,],2)

Zcalc<-sum(n11z - t11z) / (sum(n1.z * n2.z * n.1z * n.2z / (nz^2 * (nz-1))))^0.5

## The Z statistic is identical to mantelhaen.test()


## The p-value is identical to mantelhaen.test()


## The common odds ratio is identical to mantelhaen.test()


## Now I switch lines values in each 2 x 2 table


## I restart the same code after addmargins(obs3), it is still a lower-tailed test

## Results : the common odds ratio is now 0.4317805 but the p-value remains 0.9765 with mantelhaen.test(). Manualy, I found a p-value = 0.02353283 which seems to me ok when I have 0.4317805 as a common odds ratio and when I test "true common odds ratio is less than 1"
Comment 1 Mikko Korpela 2011-09-29 21:14:18 UTC
I believe this has been fixed in R 2.12.2 patched. See bug 14514.

*** This bug has been marked as a duplicate of bug 14514 ***