# Fisher exact test on paired data

Given $40$ cases with lung cancer and $40$ matched controls (without lung cancer) (matching based on age, sex, etc.). To try to find evidence between the effect of smoking on lung cancer, I used Fisher's exact test on the contingency table. This however did not take into account that the controls and cases were matched.

So I wondered if there is a way to use Fisher's exact test that takes into account the matching between the two groups?

## 4 Answers

You need McNemar's test (http://en.wikipedia.org/wiki/McNemar%27s_test , http://www.ncbi.nlm.nih.gov/pmc/articles/PMC3346204/). Following is an example:

1300 pts and 1300 matched controls are studied. The smoking status is tabled as follows:

             Normal
|no  |yes|
Cancer|No  |1000|40 |
|Yes |200 |60 |


Each entry of the table shows information about a CASE-CONTROL PAIR: 1000 means in 1000 case-control pairs, neither was a smoker. 40 is the number of case-control pairs where control was smoker and cancer patient was not, and so on. Following R code can be used to generate this table and do McNemar's Test.

mat = as.table(rbind(c(1000, 40), c( 200, 60) ))
colnames(mat) <- rownames(mat) <- c("Nonsmoker", "Smoker")
names(dimnames(mat)) = c("Cancer", "Normal")
mat
#                  Normal
#              Nonsmoker Smoker
# Cancer
#  Nonsmoker      1000     40
#  Smoker          200     60

mcnemar.test(mat)

#        McNemar's Chi-squared test with continuity correction
#
#data:  mat
#McNemar's chi-squared = 105.34, df = 1, p-value < 2.2e-16


McNemar's test is also used to assess effect of an intervention on a binary outcome variable. The pair of before-after outcome is tabled and tested as above.

Edit: Extending example given by @gung , if smoking status is listed in your dataframe mydf as follows:

pairID  cancer  control
1       1       1
2       1       1
3       1       0
...


McNemars test can be done with following R commands:

> tt = with(mydf, table(cancer, control))
> tt
control
cancer 0 1
0 5 1
1 3 2

> mcnemar.test(tt)

McNemars Chi-squared test with continuity correction

data:  tt
McNemars chi-squared = 0.25, df = 1, p-value = 0.6171

• Which test do you use for multiple controls per case, say 10 controls per case? – eXpander Oct 13 '15 at 12:25
• This would deserve a separate question and discussion. I think pairing each case with mean of its controls can be taken and then McNemar's test can be used. – rnso Oct 14 '15 at 17:03

You are right that Fisher's exact test is inappropriate for your data. You will have to re-form your contingency table. The new table will be for pairs, thus it will appear to have half as many data represented (in your case 40 instead of 80). For example, imagine your data looked like this (each set of paired subjects is in its own row, and 1 indicates a smoker):

cancer  control
1       1
1       1
1       0
1       0
1       0
0       1
0       0
0       0
0       0
0       0
0       0


Then your old contingency table might have been:

       cancer  control
smoker 5       3
non    6       8


Your new contingency table will look like this:

            control
cancer    smoker  non
smoker  2       3
non     1       5


The first contingency table summed to 22 (the number of total subjects in your study), but the second contingency table sums to 11 (the number of matched pairs).

With your data represented this way, what you are interested in is if the marginal proportions are the same. The test for that is McNemar's test. I have explained McNemar's test here and here.

• Note that McNemar test for dichotomous data is equivalent to sign test. So the OP may use sign test (with permutation or Monte Carlo significance testing, if necessary). – ttnphns Apr 22 '15 at 6:55
• @ttnphns, I discuss that in the linked threads where I explain McNemar's test in detail. – gung - Reinstate Monica Apr 22 '15 at 13:49

it should not be necessary to use a paired test. the matching of the populations ascertains that the distribution of covaraites (age, ...) is the same in the two populatoins so it doesn't "distort" the picture.

the test compares the means of the populations so a pairing of individuals is not necessary. this is only required for "repeated" measurements, e.g., comparing menas before and after treatment of the same population.

Yes and no:

probably your case falls under the Pearce (2015) case: the point in the article is that the variables you use to select the control should be controlled for in the study and not in the test. That could be difficult due to the N=80.

Hope this help :)