how to perform a mcnemar test in matlab

hypothesis testing

To perform a McNemar test in MATLAB, you can use the function mcnemar from the MATLAB Statistics and Machine Learning Toolbox.

Before performing the test, you first need to create a contingency table that summarizes the results of two related tests. The contingency table should have the following form:

| | Positive | Negative | |-------------------|----------|----------| | Test 1 Positive | a | b | | Test 1 Negative | c | d |

Here, a is the number of cases where both Test 1 and Test 2 were positive, b is the number of cases where Test 1 was negative and Test 2 was positive, c is the number of cases where Test 1 was positive and Test 2 was negative, and d is the number of cases where both Test 1 and Test 2 were negative.

Once you have the contingency table, you can perform the McNemar test using the mcnemar function. The function takes the contingency table as input and returns the p-value for the test:

main.m
% Create contingency table
a = 10;
b = 6;
c = 3;
d = 11;
tbl = [a, b; c, d];

% Perform McNemar test
p = mcnemar(tbl);
119 chars
10 lines

The mcnemar function assumes a null hypothesis that the two tests are equally effective, which is tested against an alternative hypothesis that the two tests have different effectiveness. If the p-value is less than the significance level (e.g., 0.05), then you reject the null hypothesis and conclude that the two tests have different effectiveness.

Note that the McNemar test requires that the two tests are applied to the same sample of subjects, so the contingency table only includes cases where both tests were performed.

gistlibby LogSnag