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,
Bob Green
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:> dX0 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. >
Peter,
Thanks for your reply. To perform the analysis in R, I used the table 
format suggested in the book by Everitt & Hothorn, whereas in SPSS the 
analysis was performed directly from the 2 variables, rather than using 
count data.
There is still something I don't understand  - I tried to replicate the 
syntax from your e-mail but my computer just kept waiting - what am I still 
doing wrong?
  mctest <- as.table(matrix(c(128,29,331,430), ncol =2, dimnames = 
list(group=c("preMHT","postMHT"),
assault=c("yes","no"))))
 > d <- read.table(stdin())
0: mcnemar.test(as.matrix(d),correct=F)
1:
Thanks again
Bob
At 10:52 PM 26/12/2006 +0100, Peter Dalgaard wrote:>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.
>>
Apparently Analagous Threads
- mcnemar.test odds ratios, CI, etc.
- Can I use "mcnemar.test" for 3*3 tables (or is there a bug in the command?)
- Problem applying McNemar's - Different values in SPSS and R
- Using McNemar's test to detect shifts in response from pre- to post-treatment
- about McNemar