Solved – McNemar’s test for $3 \times 2$ data

mcnemar-testrrepeated measures

I adopt a within-group experiment, such that the same participant uses 3 devices to perform a task, which has a result "pass" or fail.
My data looks like this:

        Pass  Fail
deviceA   21    13
deviceB   15    20
deviceC   9     25

My questions are:

  1. Is McNemar's test appropriate for this data?
  2. In R, when I run mcnemar.test(data), I got the following error:

    "'x' must be square with at least two rows and columns"
    

How can I run this $3 \times 2$ data for R's mcnemar.test?

Best Answer

So, you have a 3-level factor "device", which is a repeated-measures factor. The response data are binary: 1 (pass) and 0 (fail).

respondent  deviceA  deviceB  deviceC
1              0        1        0
2              1        1        0
3              1        1        0
4              0        0        1
...

You want to test if the factor affects the result, i.e. if the 3 devices differ significantly. Null hypothesis: no differences between the 3 devices in the population; alternative hypothesis: there is some difference, at least between some 2 of the 3 devices.

Use Friedman's test (= Friedman's nonparametric "analysis-of-variance"). When the data values are all binary, this test is then also known as Cochran's Q test.

Please note that the frequency table corresponding to your analysis is size 2x2x2, not 2x2 as McNemar's test implies (or kxk, for McNemar-Bowker), nor 3x2 as you thought. Cochran's Q test is the extension of McNemar's test from 2-way table to multi-way table.

Related Question