User Tools

Site Tools


analysis:stat:fisherexacttest

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
analysis:stat:fisherexacttest [2014/12/15 17:56] – created igorkagananalysis:stat:fisherexacttest [2022/12/29 07:15] (current) – external edit 127.0.0.1
Line 1: Line 1:
 ====== Fisher's exact test ====== ====== Fisher's exact test ======
 +
 +InStat example:
 +
 +{{:analysis:stat:fisherexacttest_instat_example.png?562}}
 +
 +Corresponding MATLAB:
 +
 +<code 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);
 +
 +</code>
  
analysis/stat/fisherexacttest.1418666218.txt.gz · Last modified: 2022/12/29 07:15 (external edit)