# [R] Problem applying McNemar's - Different values in SPSS and R

Marc Schwartz marc_schwartz at me.com
Tue Dec 28 18:30:59 CET 2010

```On Dec 28, 2010, at 11:05 AM, Manoj Aravind wrote:

> Hi friends,
> I get different values for McNemar's test in R and SPSS. Which one should i
> rely on when the p values differ.
> I came across this problem when i started learning R and seriously give up
> on SPSS or any other proprietary software.
>
> Output in SPSS follows
>
> *Crosstab*
>
>
>               hsc
>
> Total
>
>     ABN
>
> NE
>
> ABN
>
> tvs
>
> ABN
>
> Count
>
> 40
>
> 3
>
> 43
>
>     Row %
>
> 93.0%
>
> 7.0%
>
> 100.0%
>
>     COL%
>
> 78.4%
>
> 30.0%
>
> 70.5%
>
>  NE
>
> Count
>
> 11
>
> 7
>
> 18
>
>     Row %
>
> 61.1%
>
> 38.9%
>
> 100.0%
>
>     COL%
>
> 21.6%
>
> 70.0%
>
> 29.5%
>
> Total
>
> Count
>
> 51
>
> 10
>
> 61
>
>  Row %
>
> 83.6%
>
> 16.4%
>
> 100.0%
>
>  COL%
>
> 100.0%
>
> 100.0%
>
> 100.0%
>
>
>
> * Chi-Square Tests*
>
>
>      Value
>
> Exact Sig. (2-sided)
>
> McNemar Test
>
>  .057(a)
>
> N of Valid Cases
>
> 61
>
>   a Binomial distribution used.
>
> Output from R is as follows....
>
>> tvshsc<-
>
> + matrix(c(40,11,3,7),
>
> + nrow=2,
>
> + dimnames=list("TVS"=c("ABN","NE"),
>
> + "HSC"=c("ABN","NE")))
>
>> tvshsc
>
>     HSC
>
> TVS   ABN NE
>
>  ABN  40  3
>
>  NE   11  7
>
>> mcnemar.test(tvshsc)
>
>
> McNemar's Chi-squared test with continuity correction
>
>
> data:  tvshsc
>
> McNemar's chi-squared = 3.5, df = 1, p-value = 0.06137
>
> Regards
>
> Dr. B Manoj Aravind

The SPSS test appears to be an exact test, whereas the default R function does not perform an exact test, so you are not comparing Apples to Apples...

Try this using the 'exact2x2' CRAN package:

> require(exact2x2)

> mcnemar.exact(matrix(c(40, 11, 3, 7), 2, 2))

Exact McNemar test (with central confidence intervals)

data:  matrix(c(40, 11, 3, 7), 2, 2)
b = 3, c = 11, p-value = 0.05737
alternative hypothesis: true odds ratio is not equal to 1
95 percent confidence interval:
0.04885492 1.03241985
sample estimates:
odds ratio
0.2727273

HTH,

Marc Schwartz

```