⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 custom_fcdf.m

📁 toolbox of BVQX, This is the access between BV and matlab. It will help you to analysis data from BV
💻 M
字号:
function F = custom_fcdf(x,v,w)
% custom_fcdf  - CDF of F (Fisher-Snedecor) distribution
%
% FORMAT:       p = custom_fcdf(x, v, w)
%
% Input fields:
%
%       x           F-variate (F has range [0,Inf) )
%       v           parameter 1 / numerator d.f. (v > 0)
%       w           parameter 2 / denominator d.f. (w > 0)
%
% Output fields:
%
%       p           CDF of F distribution with [v,w] d.f. at points x
%
% Note: this function has been copied from the SPM2 package published
%       by the Wellcome Department, go here for details:
%       http://www.fil.ion.ucl.ac.uk/spm/

% 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{X<x} for X~F(v,w). The F-distribution is defined
% for v>0 & 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(X<x) = 1 - betainc(w/(w+v*x^2),w/2,v/2)
% See Abramowitz & Stegun, 26.6.2; Press et al., Sec6.4 for
% definitions of the incomplete beta function. The relationship is
% easily verified by substituting for w/(w+v*x^2) in the integral of the
% incomplete beta function.
%
% MatLab's implementation of the incomplete beta function is used.
%
%
% References:
%-----------------------------------------------------------------------
% Evans M, Hastings N, Peacock B (1993)
%       "Statistical Distributions"
%        2nd Ed. Wiley, New York
%
% Abramowitz M, Stegun IA, (1964)
%       "Handbook of Mathematical Functions"
%        US Government Printing Office
%
% Press WH, Teukolsky SA, Vetterling AT, Flannery BP (1992)
%       "Numerical Recipes in C"
%        Cambridge
%
%_______________________________________________________________________
% @(#)spm_Fcdf.m	2.2 Andrew Holmes 99/04/26

% Version:  v0.6d
% Build:    7021616
% Date:     Feb-16 2007, 4:16 PM CET
% Author:   Andrew Holmes, SPM2
% URL/Info: http://www.fil.ion.ucl.ac.uk/spm/

% argument check
if nargin < 3 || ...
   ~isa(x, 'double') || ...
   ~isa(v, 'double') || ...
   ~isa(w, 'double') || ...
    isempty(v) || ...
    isempty(w) || ...
    any(isnan(x(:)) | x(:) < 0) || ...
    any(isinf(v(:)) | isnan(v(:)) | v(:) <= 0) || ...
    any(isinf(w(:)) | isnan(w(:)) | w(:) <= 0)
    error( ...
        'BVQXtools:BadArgument', ...
        'Missing or invalid argument given.' ...
    );
end
if isempty(x)
    F = [];
    return;
end
osize = size(x);
if numel(x) == 1
    if numel(v) > 1
        osize = size(v);
    elseif numel(w) > 1
        osize = size(w);
    end
end
onum = prod(osize);
x = x(:);
v = v(:);
w = w(:);
if onum > 1
    if numel(x) == 1
        x = repmat(x, [onum, 1]);
    end
    if numel(v) == 1
        v = repmat(v, [onum, 1]);
    end
    if numel(w) == 1
        w = repmat(w, [onum, 1]);
    end
end
if numel(x) ~= onum || ...
    numel(v) ~= onum || ...
    numel(w) ~= onum
    error( ...
        'BVQXtools:SizeMismatch', ...
        'Invalid number of elements in x, v, or w.' ...
    );
end

% calculate F
F = reshape(1 - betainc(w ./ (w + v .* x), w ./ 2, v ./ 2), osize);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -