comparison toolboxes/FullBNT-1.0.7/KPMstats/chisquared_table.m @ 0:e9a9cd732c1e tip

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