Home > FMAToolbox > General > FisherTest.m

FisherTest

PURPOSE ^

FisherTest - Test if two groups of samples have equal variances.

SYNOPSIS ^

function [h,p,f] = FisherTest(samples1,samples2,alpha)

DESCRIPTION ^

FisherTest - Test if two groups of samples have equal variances.

 Fisher's test is used to test if two groups of samples have equal variances.

  USAGE

    [h,p,f] = FisherTest(samples1,samples2,alpha)

    samples1       first group
    samples2       second group
    alpha          optional significance level (default = 0.05)

  OUTPUT

    h    test result (1 = reject null hypothesis, 0 = accept)
    p    p value
    f    test statistics

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [h,p,f] = FisherTest(samples1,samples2,alpha)
0002 
0003 %FisherTest - Test if two groups of samples have equal variances.
0004 %
0005 % Fisher's test is used to test if two groups of samples have equal variances.
0006 %
0007 %  USAGE
0008 %
0009 %    [h,p,f] = FisherTest(samples1,samples2,alpha)
0010 %
0011 %    samples1       first group
0012 %    samples2       second group
0013 %    alpha          optional significance level (default = 0.05)
0014 %
0015 %  OUTPUT
0016 %
0017 %    h    test result (1 = reject null hypothesis, 0 = accept)
0018 %    p    p value
0019 %    f    test statistics
0020 
0021 % Copyright (C) 2004-2011 by Michaƫl Zugaro
0022 %
0023 % This program is free software; you can redistribute it and/or modify
0024 % it under the terms of the GNU General Public License as published by
0025 % the Free Software Foundation; either version 3 of the License, or
0026 % (at your option) any later version.
0027 
0028 if isempty(samples1) | isempty(samples2),
0029     h = 0;
0030     p = 0;
0031     f = 0;
0032     return
0033 end
0034 
0035 % Significance level
0036 if nargin < 3,
0037     alpha = 0.05;
0038 end
0039 
0040 % Compute test
0041 n1 = prod(size(samples1));
0042 x1 = reshape(samples1,n1,1);
0043 n2 = prod(size(samples2));
0044 x2 = reshape(samples2,n2,1);
0045 var1 = var(x1);
0046 var2 = var(x2);
0047 f = var1/var2;
0048 df1 = n1-1;
0049 df2 = n2-1;
0050 if f > 1,
0051    p = 2*betainc(df2/(df2+df1*f),df2/2,df1/2);
0052 else
0053    f = 1/f ;
0054    p = 2*betainc(df1/(df1+df2*f),df1/2,df2/2);
0055 end
0056 if p > 1,
0057    p = 2-p;
0058 end
0059 
0060 h = p < alpha;
0061 
0062 if h,
0063     message = '+++ Variances are significantly different';
0064 else
0065     message = '--- Variances are not significantly different';
0066 end
0067 message = ['F test: ' message ' (p='  num2str(p) ', F=' num2str(f) ', df1=' int2str(df1) ...
0068     ', df2=' int2str(df2) ')'];
0069 disp(message);

Generated on Fri 16-Mar-2018 13:00:20 by m2html © 2005