function F = spm_Fcdf(x,v,w) % Cumulative Distribution Function (CDF) of F (Fisher-Snedecor) distribution % FORMAT F = spm_Fcdf(x,df) % FORMAT F = spm_Fcdf(x,v,w) % % x - F-variate (F has range [0,Inf) ) % df - Degrees of freedom, concatenated along last dimension % Eg. Scalar (or column vector) v & w. Then df=[v,w]; % v - Shape parameter 1 / numerator degrees of freedom (v>0) % w - Shape parameter 2 / denominator degrees of freedom (w>0) % F - CDF of F-distribution with [v,w] degrees of freedom at points x %__________________________________________________________________________ % % spm_Fcdf implements the Cumulative Distribution Function of the F-distribution. % % Definition: %-------------------------------------------------------------------------- % The CDF F(x) of the F distribution with degrees of freedom v & w, % defined for positive integer degrees of freedom v & w, is the % probability that a realisation of an F random variable X has value % less than x F(x)=Pr{X0 & w>0, and for x in [0,Inf) (See Evans et al., Ch16). % % Variate relationships: (Evans et al., Ch16 & 37) %-------------------------------------------------------------------------- % The square of a Student's t variate with w degrees of freedom is % distributed as an F-distribution with [1,w] degrees of freedom. % % For X an F-variate with v,w degrees of freedom, w/(w+v*X^2) has % distributed related to a Beta random variable with shape parameters % w/2 & v/2. % % Algorithm: %-------------------------------------------------------------------------- % Using the relationship with the Beta distribution: The CDF of the % F-distribution with v,w degrees of freedom is related to the % incomplete beta function by: % Pr(X1; if sum(xa)>1 && any(any(diff(as(xa,:)),1)) error('non-scalar args must match in size'), end %-Computation %-------------------------------------------------------------------------- %-Initialise result to zeros F = zeros(rs); %-Only defined for strictly positive v & w. Return NaN if undefined. md = ( ones(size(x)) & v>0 & w>0 ); if any(~md(:)) F(~md) = NaN; warning('Returning NaN for out of range arguments'); end %-Non-zero where defined and x>0 Q = find( md & x>0 ); if isempty(Q), return, end if xa(1), Qx=Q; else Qx=1; end if xa(2), Qv=Q; else Qv=1; end if xa(3), Qw=Q; else Qw=1; end %-Compute F(Q) = 1 - betainc(w(Qw)./(w(Qw) + v(Qv).*x(Qx)),w(Qw)/2,v(Qv)/2);