COCHRAN Q TEST
H = COCHRANQTEST(X) performs the non-parametric Cochran's Q-test on the hypothesis that the K columns of N-by-K matrix have the same number of successes and failures. H==0 indicates that the null hypothesis cannot be rejected at the 5 significance level. H==1 indicates that the null hypothesis can be rejected at the 5% level.
X should contain dichotomous values (success/fail, left/right, yes/no, true/false, 0/1, etc.), where one value indicates a success and the other value denotes a failure. The K columns correspond to K related observations; the N rows correspond to N distinct cases. Note that the coding of success and failure does not matter. The highest value will be treated as a success. Also note that cases that comprise only successes or failures do not have an effect on the test statistic.
X can be cell array of (two different) strings (e.g., 'YES' and 'NO').
H = COCHRANQTEST(...,ALPHA) performs the test at the significance level (100*ALPHA)%. ALPHA must be a scalar between 0 and 1.
[H,P] = COCHRANQTEST(...) returns the p-value, i.e., the probability of observing the given result, or one more extreme, by chance if the null hypothesis is true. Small values of P cast doubt on the validity of the null hypothesis.
[H,P,STATS] = COCHRANQTEST(...) returns a structure with the following fields:
'Q' -- the value of the test statistic
'df' -- the degrees of freedom of the test
'fail' -- the value regarded as a fail
'pass' -- the value regarded as a success
'Npass' -- the sum of successes for each column
'Ne' -- the number of effective cases (i.e., the number of cases that do show differences on the K observations)
COCHRANQTEST(...) without output arguments prints a string saying whether the null-hypothesis should be rejected at significance level APLHA.
The Cochran Q test is useful for comparing related samples measured on a categorical (nominal) scale. For K=2 this test equals the McNemar test for two related samples.
Version 2.2, okt 2007
Cite As
Jos (10584) (2026). COCHRAN Q TEST (https://www.mathworks.com/matlabcentral/fileexchange/16753-cochran-q-test), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Platform Compatibility
Windows macOS LinuxCategories
- AI and Statistics > Statistics and Machine Learning Toolbox > Probability Distributions and Hypothesis Tests > Hypothesis Tests >
Tags
Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
| Version | Published | Release Notes | |
|---|---|---|---|
| 1.0.0.0 | fixed error in coding pass and fail |
