Fisher's exact test with R×C contingency table
Version 1.0.0 (4.97 KB) by
qqffssxx
This function is based on Monte Carlo simulation, it support contingency tables larger than 2 * 2.
The function 'fishertest' provided by MATLAB only supports contingency table of size 2 × 2, and although there have been many other scholarly published functions on File_Exchange to compute larger matrices, the results are somewhat problematic.
This function is based on Monte Carlo simulation, it support contingency tables larger than 2 * 2.
% Input variable: x
% x is the contingency table. You can use function 'crosstab' to generate the contingency table.
% num : the number of Monte Carlo simulations to be performed, default is 100000.
% Output variable: p
% p:p-values
% Source of subfunction 'rcont2': https://people.math.sc.edu/Burkardt/m_src/asa144/asa144.html
% for example
% x = [ 11 11
% 0 6
% 11 17];
% p = fisher_test_R_C(x)
% p = 0.0977;
% Because of the randomness in the algorithm, the result may be different each time.
% You can increase the value of 'num' to make the result more robust.
Reference:
- James Boyett,Algorithm AS 144: Random R x C Tables with Given Row and Column Totals,Applied Statistics,Volume 28, Number 3, 1979, pages 329-332.
https://people.math.sc.edu/Burkardt/m_src/asa144/asa144.html
Cite As
qqffssxx (2024). Fisher's exact test with R×C contingency table (https://www.mathworks.com/matlabcentral/fileexchange/126355-fisher-s-exact-test-with-rxc-contingency-table), MATLAB Central File Exchange. Retrieved .
MATLAB Release Compatibility
Created with
R2022b
Compatible with R2010a and later releases
Platform Compatibility
Windows macOS LinuxTags
Acknowledgements
Inspired by: Fisher's exact test with n x m contingency table
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!Discover Live Editor
Create scripts with code, output, and formatted text in a single executable document.
Version | Published | Release Notes | |
---|---|---|---|
1.0.0 |