function F = spm_Bcdf(x,v,w) % Inverse Cumulative Distribution Function (CDF) of Beta distribution % FORMAT F = spm_Bcdf(x,v,w) % % x - Beta variates (Beta has range [0,1]) % v - Shape parameter (v>0) % w - Shape parameter (w>0) % F - CDF of Beta distribution with shape parameters [v,w] at points x %__________________________________________________________________________ % % spm_Bcdf implements the Cumulative Distribution Function for Beta % distributions. % % Definition: %-------------------------------------------------------------------------- % The Beta distribution has two shape parameters, v and w, and is % defined for v>0 & w>0 and for x in [0,1] (See Evans et al., Ch5). % The Cumulative Distribution Function (CDF) F(x) is the probability % that a realisation of a Beta random variable X has value less than % x. F(x)=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 x in [0,1] & strictly positive v & w. % Return NaN if undefined. md = ( x>=0 & x<=1 & v>0 & w>0 ); if any(~md(:)) F(~md) = NaN; warning('Returning NaN for out of range arguments'); end %-Special cases: F=1 when x=1 F(md & x==1) = 1; %-Non-zero where defined & x>0, avoid special cases Q = find( md & x>0 & x<1 ); 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) = betainc(x(Qx),v(Qv),w(Qw));