[R] McNemar test in R & SPSS

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Dec 26 22:52:56 CET 2006


Bob Green wrote:
> Hello,
>
> I am hoping someone can clarify why I might obtain a quite different value 
> in R & SPSS  for a McNemar test I ran.
>
> Firstly, here is the R syntax & output
>
>
> R OUTPUT
>
>  > mctest <- as.table(matrix(c(128,29,331,430),
> + ncol =2, dimnames = list(group=c("preMHT","postMHT"),
> + assault=c("yes","no"))))
>
>  > mctest
>                assault
> group       yes  no
>    preMHT  128 331
>    postMHT  29 430
>
>  >  mcnemar.test(mctest,correct=F)
>
>          McNemar's Chi-squared test
>
> data:  mctest
> McNemar's chi-squared = 253.3444, df = 1, p-value < 2.2e-16
>
>
> SPSS OUTPUT
>
> The same data was inputted in SPSS. Regarding the first table SPSS 
> generated - it lists the number of cases in each combination of categories. 
> The diagonal contains the number of cases with the same response on both 
> variables, while the off diagonal contains cases that have different 
> responses on the 2 variables. The overall chisquare value is much lower 
> than the value obtained using R, though still significant.
>
>
> pre02 & post02
>
> pre02   post02
>
>          0       1
> 0       311     20
> 1       119     9
>
>
> Test Statistics(b)
>
>   pre02 & post02
>
> N               459
> Chi-Square(a)   69.094
> Asymp. Sig.     .000
>
> a  Continuity Corrected
> b  McNemar Test
>
>
> Any assistance is much appreciated,
>   
Well, you can't expect R to give the correct result if you feed it the 
wrong matrix, can you?

> d <- read.table(stdin())

0:          0       1

1: 0       311     20

2: 1       119     9

3: 

> d

   X0 X1

0 311 20

1 119  9

> mcnemar.test(as.matrix(d),correct=F)

        McNemar's Chi-squared test

data:  as.matrix(d) 

McNemar's chi-squared = 70.5108, df = 1, p-value < 2.2e-16

> mcnemar.test(as.matrix(d),correct=T)

        McNemar's Chi-squared test with continuity correction

data:  as.matrix(d) 

McNemar's chi-squared = 69.0935, df = 1, p-value < 2.2e-16



> Bob Green
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list