function x = spm_invFcdf(F,v,w) % Inverse Cumulative Distribution (CDF) of F (Fisher-Snedecor) distribution % FORMAT x = spm_invFcdf(F,df) % FORMAT x = spm_invFcdf(F,v,w) % % F - CDF (lower tail p-value) % 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) % x - F-variate (F has range [0,Inf) ) %__________________________________________________________________________ % % spm_Fcdf implements the inverse Cumulative Distribution Function % for 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 % distribution related to a Beta random variable with shape parameters % w/2 & v/2, as described below. % % Algorithm: %-------------------------------------------------------------------------- % Using the routine spm_invBcdf for the Beta distribution, with % appropriate parameters: 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 x = zeros(rs); %-Only defined for F in [0,1] & strictly positive v & w. % Return NaN if undefined. md = ( F>=0 & F<=1 & v>0 & w>0 ); if any(~md(:)) x(~md) = NaN; warning('Returning NaN for out of range arguments'); end %-Special cases: x=0 when F=0, x=Inf when F=1 x(md & F==1) = Inf; %-Compute where defined & not special case Q = find( md & F>0 & F<1 ); if isempty(Q), return, end if xa(1), QF=Q; else QF=1; end if xa(2), Qv=Q; else Qv=1; end if xa(3), Qw=Q; else Qw=1; end %-Compute bQ = spm_invBcdf(1-F(QF),w(Qw)/2,v(Qv)/2); x(Q) = (w(Qw)./bQ -w(Qw))./v(Qv);