InStat example:
Corresponding MATLAB:
%% Fisher's exact test on proportions of two outcomes Ns1 = 10; % condition, or status 1 (e.g. control) Ns2 = 10; % condition, or status 2 (e.g. stimulation) % Let's assign arbitrary outcome 2 ("1") as "success" p_suc1 = 0.2; % probability success in status 1 p_suc2 = 0.9; % probability success in status 2 y1 = zeros(1,Ns1); y2 = ones(1,Ns2); x1 = [zeros(1,round( (1-p_suc1)*Ns1 )) ones( 1, round(p_suc1*Ns1) )]; % status 1 outcome x2 = [zeros(1,round( (1-p_suc2)*Ns2 )) ones( 1, round(p_suc2*Ns2) )]; % status 2 outcome p = fexact( [x1 x2]' , [y1 y2]' ) % approximating by Binomial distribution, 100 times % http://www.stat.yale.edu/Courses/1997-98/101/binom.htm count_success1 = binornd(Ns1,p_suc1,1,100); % this draws a count of success count_success2 = binornd(Ns2,p_suc2,1,100); y1 = zeros(1,Ns1); y2 = ones(1,Ns2); for i = 1:100, x1 = [zeros(1,Ns1-count_success1(i)) ones( 1, count_success1(i) )]; % status 1 outcome x2 = [zeros(1,Ns1-count_success2(i)) ones( 1, count_success2(i) )]; % status 1 outcome p(i) = fexact( [x1 x2]' , [y1 y2]' ); end hist(p<0.05);