User Tools

Site Tools


analysis:stat:fisherexacttest

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
analysis:stat:fisherexacttest [2014/12/15 18:09] igorkagananalysis:stat:fisherexacttest [2022/12/29 07:15] (current) – external edit 127.0.0.1
Line 3: Line 3:
 InStat example: InStat example:
  
-{{:analysis:stat:fisherexacttest_instat_example.png|562}}+{{:analysis:stat:fisherexacttest_instat_example.png?562}}
  
 Corresponding MATLAB: Corresponding MATLAB:
  
 <code matlab> <code matlab>
-% 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; % outcome / outcome 2 +Ns2 = 10; % condition, or status 2 (e.g. stimulation) 
-status2_prop 1/9; % outcome 1 / outcome 2+ 
 +% Let's assign arbitrary outcome 2 ("1") as "success" 
 +p_suc1 0.2; % probability success in status 
 +p_suc2 0.9; % probability success in status 2 
 y1 = zeros(1,Ns1);  y1 = zeros(1,Ns1);
-y2 = ones(1,Ns2);+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); 
 </code> </code>
  
analysis/stat/fisherexacttest.1418666992.txt.gz · Last modified: 2022/12/29 07:15 (external edit)