download contincy.m
Language: Matlab
LOC: 20
Project Info
MatLinks/Chorus(matlinks)
Server: SourceForge
Type: cvs
...chest\copyleft\gpl\stixbox\
   bincoef.m
   cat2tbl.m
   ciboot.m
   ciquant.m
   cmpmod.m
   Contents.m
   contincy.m
   corr.m
   covboot.m
   covjack.m
   cvar.m
   datas1.m
   datas10.m
   datas11.m
   datas2.m
   datas3.m
   datas4.m
   datas5.m
   datas6.m
   datas7.m
   datas8.m
   datas9.m
   dbeta.m
   dbinom.m
   dchisq.m
   df.m
   dgamma.m
   dgumbel.m
   dhypg.m
   dlognorm.m
   dnorm.m
   dt.m
   dweib.m
   egumbel.m
   getdata.m
   histo.m
   identif5.m
   identify.m
   kaplamai.m
   ldiscrim.m
   linreg.m
   lodds.m
   loddsinv.m
   logitfit.m
   lsfit.m
   lsselect.m
   normmix.m
   octvinit.m
   pairs.m
   pbeta.m
   pbinom.m
   pchisq.m
   pf.m
   pgamma.m
   pgumbel.m
   phypg.m
   plognorm.m
   plotdens.m
   plotempd.m
   plotsym.m
   pnorm.m
   pt.m
   pweib.m
   qbeta.m
   qbinom.m
   qchisq.m
   qf.m
   qgamma.m
   qgumbel.m
   qhypg.m
   qlognorm.m
   qnorm.m
   qqgamma.m
   qqgumbel.m
   qqnorm.m
   qqplot.m
   qqweib.m
   qt.m
   quantile.m
   qweib.m
   ranktrf.m
   rbeta.m
   rbinom.m
   rboot.m
   rchisq.m
   Readme.m
   rf.m
   rgamma.m
   rgumbel.m
   rhypg.m
   rlognorm.m
   rnorm.m
   rt.m
   rweib.m
   spearman.m
   stdboot.m
   stdize.m
   stdjack.m
   stixdemo.m
   test1b.m
   test1n.m
   test1r.m
   test2n.m
   test2r.m

function [p, t] = contincy(observed, method)
%CONTINCY  Compute the p-value for contigency table row/col independence.
%
%	   p = contincy(observed, method)
%
%	   The table  observed  is a count, the  method  is
%
%	   'chi2': Pearson chi2-distance 
%	   'logL': Log likelihood quote distance
%
%	   with default method 'chi2'. The p-value is computed through 
%	   approximation with chi-2 distribution under the null hypothesis
%	   for both methods.
%
%          See also CAT2TBL

%       GPL Copyright (c) Anders Holtsberg, 1999

if nargin < 2
   method = 'chi2';
end

if any(any(observed~=round(observed) | observed<0))
   error('CONTINCY expects counts, that is nonnegative integers')
end

rowsum = sum(observed')';
colsum = sum(observed);
n = sum(rowsum);
expected = rowsum * colsum ./ n;

if strcmp(method, 'chi2')
   t = sum(sum((expected-observed).^2 ./ expected));
elseif strcmp(method, 'logL')
   I = find(observed>0);
   t = 2 * sum(observed(I) .* (log(observed(I)./expected(I))));
else
   error('unknown method')
end

p = 1 - pchisq(t, (length(rowsum)-1) * (length(colsum)-1));

About Koders | Resources | Downloads | Support | Black Duck | Submit Project | Terms of Service | DMCA | Privacy Policy | Site Map| Contact Us