annotate toolboxes/FullBNT-1.0.7/KPMstats/chisquared_table.m @ 0:cc4b1211e677 tip

initial commit to HG from Changeset: 646 (e263d8a21543) added further path and more save "camirversion.m"
author Daniel Wolff
date Fri, 19 Aug 2016 13:07:06 +0200
parents
children
rev   line source
Daniel@0 1 function X2 = chisquared_table(P,v)
Daniel@0 2 %CHISQUARED_TABLE computes the "percentage points" of the
Daniel@0 3 %chi-squared distribution, as in Abramowitz & Stegun Table 26.8
Daniel@0 4 % X2 = CHISQUARED_TABLE( P, v ) returns the value of chi-squared
Daniel@0 5 % corresponding to v degrees of freedom and probability P.
Daniel@0 6 % P is the probability that the sum of squares of v unit-variance
Daniel@0 7 % normally-distributed random variables is <= X2.
Daniel@0 8 % P and v may be matrices of the same size size, or either
Daniel@0 9 % may be a scalar.
Daniel@0 10 %
Daniel@0 11 % e.g., to find the 95% confidence interval for 2 degrees
Daniel@0 12 % of freedom, use CHISQUARED_TABLE( .95, 2 ), yielding 5.99,
Daniel@0 13 % in agreement with Abramowitz & Stegun's Table 26.8
Daniel@0 14 %
Daniel@0 15 % This result can be checked through the function
Daniel@0 16 % CHISQUARED_PROB( 5.99, 2 ), yielding 0.9500
Daniel@0 17 %
Daniel@0 18 % The familiar 1.96-sigma confidence bounds enclosing 95% of
Daniel@0 19 % a 1-D gaussian is found through
Daniel@0 20 % sqrt( CHISQUARED_TABLE( .95, 1 )), yielding 1.96
Daniel@0 21 %
Daniel@0 22 % See also CHISQUARED_PROB
Daniel@0 23 %
Daniel@0 24 %Peter R. Shaw, WHOI
Daniel@0 25 %Leslie Rosenfeld, MBARI
Daniel@0 26
Daniel@0 27 % References: Press et al., Numerical Recipes, Cambridge, 1986;
Daniel@0 28 % Abramowitz & Stegun, Handbook of Mathematical Functions, Dover, 1972.
Daniel@0 29
Daniel@0 30 % Peter R. Shaw, Woods Hole Oceanographic Institution
Daniel@0 31 % Woods Hole, MA 02543 pshaw@whoi.edu
Daniel@0 32 % Leslie Rosenfeld, MBARI
Daniel@0 33 % Last revision: Peter Shaw, Oct 1992: fsolve with version 4
Daniel@0 34
Daniel@0 35 % ** Calls function CHIAUX **
Daniel@0 36 % Computed using the Incomplete Gamma function,
Daniel@0 37 % as given by Press et al. (Recipes) eq. (6.2.17)
Daniel@0 38
Daniel@0 39 [mP,nP]=size(P);
Daniel@0 40 [mv,nv]=size(v);
Daniel@0 41 if mP~=mv | nP~=nv,
Daniel@0 42 if mP==1 & nP==1,
Daniel@0 43 P=P*ones(mv,nv);
Daniel@0 44 elseif mv==1 & nv==1,
Daniel@0 45 v=v*ones(mP,nP);
Daniel@0 46 else
Daniel@0 47 error('P and v must be the same size')
Daniel@0 48 end
Daniel@0 49 end
Daniel@0 50 [m,n]=size(P); X2 = zeros(m,n);
Daniel@0 51 for i=1:m,
Daniel@0 52 for j=1:n,
Daniel@0 53 if v(i,j)<=10,
Daniel@0 54 x0=P(i,j)*v(i,j);
Daniel@0 55 else
Daniel@0 56 x0=v(i,j);
Daniel@0 57 end
Daniel@0 58 % Note: "old" and "new" calls to fsolve may or may not follow
Daniel@0 59 % Matlab version 3.5 -> version 4 (so I'm keeping the old call around...)
Daniel@0 60 % X2(i,j) = fsolve('chiaux',x0,zeros(16,1),[v(i,j),P(i,j)]); %(old call)
Daniel@0 61 X2(i,j) = fsolve('chiaux',x0,zeros(16,1),[],[v(i,j),P(i,j)]);
Daniel@0 62 end
Daniel@0 63 end