Code covered by the BSD License  

Highlights from
powerAOVII

image thumbnail
from powerAOVII by Antonio Trujillo-Ortiz
Determines the post-hoc statistical power of a performed analysis of variance Model II (random-effec

powerAOVII(F,v1,v2,a)
function [Power] = powerAOVII(F,v1,v2,a)
%  Statistical Power of a Performed ANOVA Test Model II 
%
%   Syntax: function [Power] = powerAOVII(F,v1,v2,a) 
%      
%  For the final computing of power it calls the F cumulative distribution function
%          fcdf(F,v1,v2)
%
%     Inputs:
%          F - observed F-statistic value. 
%         v1 - numerator degrees of freedom (k - 1; k = number of samples). 
%         v2 - denominator degrees of freedom (N - k; N = total number of data).
%          a - significance level. 
%     Output:
%          Power - the output power of the performed ANOVA test Model II.
%          Graphic - Central F-distributions of the ANOVA Model II
%  
%    Example: For a balanced design with k = 4, n = 5 (N = k*n), F = 2.4, and
%             a significance level = 0.05; then v1 = 3 and v2 = 16.
%             Calling on Matlab the function: 
%                powerAOVII(2.4,3,16,0.05)
%             Answer is:
%                ans= 0.2421
%           
%  Created by A. Trujillo-Ortiz and R. Hernandez-Walls
%             Facultad de Ciencias Marinas
%             Universidad Autonoma de Baja California
%             Apdo. Postal 453
%             Ensenada, Baja California
%             Mexico.
%             atrujo@uabc.mx
%
%  Copyright (C) November 2002.
%        $Revised July 2008.
%
%  To cite this file, this would be an appropriate format:
%  Trujillo-Ortiz, A. and R. Hernandez-Walls. (2002). powerAOVII: Determines the 
%    statistical power of a performed analysis of variance Model II (random-effects).
%    A MATLAB file. [WWW document]. URL http://www.mathworks.com/matlabcentral/
%    fileexchange/loadFile.do?objectId=2716
%
%  References:
% 
%  Scheff, H. (1959), The Analysis of Variance. New York: John-Wiley. p. 227.
%  Zar, J.H. (1999), Biostatistical Analysis (2nd ed.).
%              NJ: Prentice-Hall, Englewood Cliffs. pp. 195-196.
% 

if nargin < 4, 
    a = 0.05; 
end 

if ~isscalar(a)
   error('POWERAOVII requires a scalar ALPHA value.');
end

if ~isnumeric(a) || isnan(a) || (a <= 0) || (a >= 1)
   error('POWERAOVII requires 0 < ALPHA < 1.');
end

if nargin < 3, 
    error('Requires at least three input arguments.'); 
end 

p = 1-a;
sl = a;
Fc = finv(p,v1,v2); %Expected F-statistic value.
Fp = v2/(v2-2)*Fc/F; %Observed F-statistic value associated to power.
Power = 1 - fcdf(Fp,v1,v2);
F = finv(1-a,v1,v2);
x = (0.01:0.1:10.01)';x1=Fp;x2=F;
p = fpdf(x,v1,v2);y=(0.0:.001:max(p)+.1);
plot(x,p,'-k')
hold on
D = [x p];
y1 = interp1(D(:,1),D(:,2),x1);
g = find(D(:,1)>x1);
X = D(:,1);
Y = D(:,2);
X = [x1;X(g)];
Y = [y1;Y(g)];
hold on
a = area(X,Y);
set(gcf,'Renderer','OpenGL')
set(a,'FaceColor',[0.75,0.75,0.75])
hold on
x2 = [x2,x2];
y2 = [0,.3];
plot(x2,y2,'-.k')
xlabel('\itF\rm-ratio');
ylabel('Frequency of \itF\rm-ratios');
text(Fp,0.4,['\mid\leftarrow \itF_{1-\beta, ', num2str(v1) ', ',num2str(v2) '}\rm = ',...
    num2str(Fp)],'FontWeight','bold','FontSize',9)
hold on
text(F+.05,0.25,['\leftarrow \itF_{',num2str(sl) ', ',num2str(v1) ', ',num2str(v2) '}\rm = ',...
    num2str(F)],'FontWeight','bold','FontSize',9)
hold on
text(F+F+.32,0.52,['Power = ',num2str(Power)],'FontWeight','bold')
hold on
rectangle('Position',[F+F,.5,.24,0.03],'Curvature',[0,1],'FaceColor',[0.75,0.75,0.75])

title({'Central (-) \itF\rm-distributions of the ANOVA Model II.'}),
hold off

return,

Contact us at files@mathworks.com