comparison toolboxes/FullBNT-1.0.7/KPMstats/chisquared_prob.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 P = chisquared_prob(X2,v)
2 %CHISQUARED_PROB computes the chi-squared probability function.
3 % P = CHISQUARED_PROB( X2, v ) returns P(X2|v), the probability
4 % of observing a chi-squared value <= X2 with v degrees of freedom.
5 % This is the probability that the sum of squares of v unit-variance
6 % normally-distributed random variables is <= X2.
7 % X2 and v may be matrices of the same size size, or either
8 % may be a scalar.
9 %
10 % e.g., CHISQUARED_PROB(5.99,2) returns 0.9500, verifying the
11 % 95% confidence bound for 2 degrees of freedom. This is also
12 % cross-checked in, e.g., Abramowitz & Stegun Table 26.8
13 %
14 % See also CHISQUARED_TABLE
15 %
16 %Peter R. Shaw, WHOI
17
18 % References: Press et al., Numerical Recipes, Cambridge, 1986;
19 % Abramowitz & Stegun, Handbook of Mathematical Functions, Dover, 1972.
20
21 % Peter R. Shaw, Woods Hole Oceanographic Institution
22 % Woods Hole, MA 02543
23 % (508) 457-2000 ext. 2473 pshaw@whoi.edu
24 % March, 1990; fixed Oct 1992 for version 4
25
26 % Computed using the Incomplete Gamma function,
27 % as given by Press et al. (Recipes) eq. (6.2.17)
28
29 % Following nonsense is necessary from Matlab version 3 -> version 4
30 versn_str=version; eval(['versn=' versn_str(1) ';']);
31 if versn<=3, %sigh
32 P = gamma(v/2, X2/2);
33 else
34 P = gammainc(X2/2, v/2);
35 end