# DAG wiki

### Site Tools

analysis:stat:fisherexacttest

# Differences

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

 analysis:stat:fisherexacttest [2014/12/16 11:15]igorkagan analysis:stat:fisherexacttest [2014/12/16 12:27] (current)igorkagan Both sides previous revision Previous revision 2014/12/16 12:27 igorkagan 2014/12/16 11:15 igorkagan 2014/12/15 18:10 igorkagan 2014/12/15 18:09 igorkagan 2014/12/15 18:07 igorkagan 2014/12/15 18:03 igorkagan 2014/12/15 18:03 igorkagan 2014/12/15 18:02 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 17:56 igorkagan created 2014/12/16 12:27 igorkagan 2014/12/16 11:15 igorkagan 2014/12/15 18:10 igorkagan 2014/12/15 18:09 igorkagan 2014/12/15 18:07 igorkagan 2014/12/15 18:03 igorkagan 2014/12/15 18:03 igorkagan 2014/12/15 18:02 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 18:01 igorkagan 2014/12/15 17:56 igorkagan created Line 8: Line 8: - %% Fisher'​s exact test + - Ns1 = 10; % status 1 (e.g. control) + %% Fisher'​s exact test on proportions of two outcomes - Ns2 = 10; % status 2 (e.g. stimulation) + Ns1 = 10; % condition, or status 1 (e.g. control) - status1_prop ​= 8/2; % proportion outcome ​1 / outcome 2, binomial proportion ​ + Ns2 = 10; % condition, or status 2 (e.g. stimulation) - status2_prop ​= 1/9; % proportion outcome 1 / outcome ​2, binomial proportion ​ + + % 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);​ y1 = zeros(1,​Ns1);​ - y2 = ones(1,​Ns2);​ % let's assign outcome 2 as "​success"​ (arbitrary) + y2 = ones(1,​Ns2);​ - x1 = [zeros(1,​round(  ​status1_prop*Ns1 / (1 + status1_prop) )) ones( 1,​round( ​ Ns1 - status1_prop*Ns1 / (1 + status1_prop)  ​))]; % status 1 outcome + x1 = [zeros(1,​round( ​ (1-p_suc1)*Ns1 )) ones( 1, round(p_suc1*Ns1) )]; % status 1 outcome - x2 = [zeros(1,​round(  ​status2_prop*Ns2 / (1 + status2_prop) )) ones( 1,​round( ​ Ns2 - status2_prop*Ns2 / (1 + status2_prop)  ​))]; % status 2 outcome ​ + x2 = [zeros(1,​round( ​ (1-p_suc2)*Ns2 )) ones( 1, round(p_suc2*Ns2) )]; % status 2 outcome ​ - p = fexact( [x1 x2]', [y1 y2]' ) + 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);​