% power analysis given cohen's d, n, and a1(one tailed alpha level)
%reference  Keppel, G. & Wickens, T. D.,(2004). Design and analysis: A researcher's handbook. Pearson Prentice-Hall.
%Cohen, J. (1977). Statistical power for the behavioral sciences (revised edition).
%the relations between d (which is defined by t*sqrt(2/n) and is sqrt(2)*dz for within design) and etaSqr for two conditions, 
%F=d^2*(n/2) and
%F=etaSq/(1-etaSq)*dferror

%% given a d
close all;
clear all;

d=0.707;%0.5*sqrt(2);%observedD=observedt*sqrt(2/N), which is sqrt(2)*dz for within design; 
n=(4:1:100)'; % n is the subject number in one condition, so for between design N=2*n


withinOrBetween=1; %withinOrBetween=1 for within, 2 for between
tail=2; % tail=1 for one tail, =2 for two tails

powerAnalysis=collectivePowerAnalysis

[n, df,criticalT, observedT, p2]=powerAnalysis.powerCohensd(d, n,withinOrBetween,tail);
    %search for the closest value raltive to a prior power
%     prior_power=0.99;
%     [c, index] = min(abs(p2-prior_power));
%     Sub_NO(index)

