1## Copyright (C) 2007 Lukasz Komsta, http://www.komsta.net/ 2## 3## This program is free software; you can redistribute it and/or modify 4## it under the terms of the GNU General Public License as published by 5## the Free Software Foundation; either version 2 of the License, or 6## (at your option) any later version. 7## 8## This program is distributed in the hope that it will be useful, 9## but WITHOUT ANY WARRANTY; without even the implied warranty of 10## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11## GNU General Public License for more details. 12## 13## You should have received a copy of the GNU General Public License 14## along with this program; If not, see <http://www.gnu.org/licenses/>. 15 16## Test for outlying or inlying variance 17## 18## Description: 19## 20## This test is useful to check if largest variance in several groups 21## of data is "outlying" and this group should be rejected. 22## Alternatively, if one group has very small variance, we can test 23## for "inlying" variance. 24## 25## Usage: 26## 27## [pval,C] = cochrantest(x,inlying,n) 28## 29## Arguments: 30## 31## x: A vector of variances or matrix of observations. 32## 33## n: If object is a vector, n should be another vector, giving 34## number of data in each corresponding group. If object is a 35## matrix, n should be omitted. 36## 37## inlying: Test smallest variance instead of largest. 38## 39## Details: 40## 41## The corresponding p-value is calculated using 'cochrancdf' function. 42## 43## Value: 44## 45## C: the value of Cochran-statistic. 46## 47## p.value: the p-value for the test. 48## 49## 50## Author(s): 51## 52## Lukasz Komsta, ported from R package "outliers". 53## See R News, 6(2):10-13, May 2006 54## 55## References: 56## 57## Snedecor, G.W., Cochran, W.G. (1980). Statistical Methods (seventh 58## edition). Iowa State University Press, Ames, Iowa. 59## 60## 61## 62 63function [pval,C] = cochrantest(x,inlying,n) 64 65 if nargin<3 66 n=NA; 67 end 68 if nargin<2 69 inlying=0; 70 end 71 72 if ismatrix(x) & ~isvector(x) 73 n = rows(x); 74 x = var(x,2); 75 else 76 n = mean(n); 77 end 78 79 k = length(x); 80 81 if inlying 82 C = min(min(x))/sum(sum(x)); 83 pval = cochrancdf(C,n,k); 84 else 85 C = max(max(x))/sum(sum(x)); 86 pval = 1 - cochrancdf(C,n,k); 87 end 88 89end 90 91