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:
- Is McNemar's test appropriate for this data?
-
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).
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
, not2x2
as McNemar's test implies (orkxk
, for McNemar-Bowker), nor3x2
as you thought. Cochran's Q test is the extension of McNemar's test from 2-way table to multi-way table.