[Contents] [TitleIndex] [WordIndex

Source code of f macros

Introduction

This is a report by Prateek Papriwal for the GSOC 2012 on the project "Distribution functions". This page gathers source code for the f distribution function.

A word of caution

These function are just temporary work and may contain bugs.

distfun_fpdf.sci

// Copyright (C) 2012 - Prateek Papriwal
// Copyright (C) 2012 - Michael Baudin
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt

function y = distfun_fpdf(varargin)
    // Examples
    // distfun_fpdf(3,4,5) // 0.06817955
    // distfun_fpdf(3,2.5,1.5) // 0.0623281
    // distfun_fpdf(1.e2,1.e10,1.e-10) // 5.000D-13
    // distfun_fpdf(1.e2,1.e200,1.e-200) // 5e-203: TODO : fix this!
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_fpdf",rhs,3)
    apifun_checklhs("distfun_fpdf",lhs,0:1)
    
    x = varargin(1)
    v1 = varargin(2)
    v2=varargin(3)
    //
    // Check type
    apifun_checktype("distfun_fpdf",x,"x",1,"constant")
    apifun_checktype("distfun_fpdf",v1,"v1",2,"constant")
    apifun_checktype("distfun_fpdf",v2,"v2",3,"constant")
    //
    // Check content
    apifun_checkgreq("distfun_fpdf",x,"x",1,0)
    tiniest=number_properties("tiniest")
    apifun_checkgreq("distfun_fpdf",v1,"v1",2,tiniest)
    apifun_checkgreq("distfun_fpdf",v2,"v2",3,tiniest)
    
    [x,v1,v2] = apifun_expandvar(x,v1,v2)
    
    if (x == []) then
        y = []
        return
    end
    
    halfv1=v1./2
    r=v1./v2
    tmp=r.*x
    ynumerator=exp((halfv1-1).*log(tmp)-((v1+v2)./2).*log(1+tmp)).*r
    ydenominator=beta(halfv1,v2./2)
    y=ynumerator./ydenominator
endfunction

distfun_fcdf.sci

// Copyright (C) 2012 - Prateek Papriwal
// Copyright (C) 2012 - Michael Baudin
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt

function p = distfun_fcdf(varargin)
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_fcdf",rhs,3:4)
    apifun_checklhs("distfun_fcdf",lhs,0:1)
    
    x = varargin(1)
    v1 = varargin(2)
    v2=varargin(3)
    lowertail = apifun_argindefault(varargin,4,%t)
    //
    // Check type
    apifun_checktype("distfun_fcdf",x,"x",1,"constant")
    apifun_checktype("distfun_fcdf",v1,"v1",2,"constant")
    apifun_checktype("distfun_fcdf",v2,"v2",3,"constant")
    apifun_checktype("distfun_fcdf",lowertail,"lowertail",4,"boolean")
    
    apifun_checkscalar("distfun_fcdf",lowertail,"lowertail",4)
    //
    // Check content
    apifun_checkgreq("distfun_fcdf",x,"x",1,0)
    tiniest=number_properties("tiniest")
    apifun_checkgreq("distfun_fcdf",v1,"v1",2,tiniest)
    apifun_checkgreq("distfun_fcdf",v2,"v2",3,tiniest)
    
    [x,v1,v2] = apifun_expandvar(x,v1,v2)
    
    if (x == []) then
        p = []
        return
    end
    
    if (lowertail) then
        p = distfun_cdff(x,v1,v2)
    else
        [ignored,p] = distfun_cdff(x,v1,v2)
    end
    
endfunction

distfun_finv.sci

// Copyright (C) 2012 - Prateek Papriwal
// Copyright (C) 2012 - Michael Baudin
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
//

function x = distfun_finv(varargin)
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_finv",rhs,3:4)
    apifun_checklhs("distfun_finv",lhs,0:1)
    
    p = varargin(1)
    v1 = varargin(2)
    v2=varargin(3)
    lowertail = apifun_argindefault(varargin,4,%t)
    //
    // Check type
    apifun_checktype("distfun_finv",p,"p",1,"constant")
    apifun_checktype("distfun_finv",v1,"v1",2,"constant")
    apifun_checktype("distfun_finv",v2,"v2",3,"constant")
    apifun_checktype("distfun_finv",lowertail,"lowertail",4,"boolean")
    
    apifun_checkscalar("distfun_finv",lowertail,"lowertail",4)
    //
    // Check content
    apifun_checkgreq("distfun_finv",p,"p",1,0)
    tiniest=number_properties("tiniest")
    apifun_checkgreq("distfun_finv",v1,"v1",2,tiniest)
    apifun_checkgreq("distfun_finv",v2,"v2",3,tiniest)
    
    [p,v1,v2] = apifun_expandvar(p,v1,v2)
    
    if (p == []) then
        x = []
        return
    end
    
    path = distfun_getpath()
    internallib = lib(fullfile(path,"macros","internals"))
    q = distfun_p2q(p)
    
    if (lowertail) then
        x = distfun_invcdff(v1,v2,p,q)
    else
        x = distfun_invcdff(v1,v2,q,p)
    end
endfunction

distfun_frnd.sci

// Copyright (C) 2012 - Prateek Papriwal
// Copyright (C) 2012 - Michael Baudin
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt

function R = distfun_frnd(varargin)
    path = distfun_getpath()
    internallib = lib(fullfile(path,"macros","internals"))

    [lhs,rhs] = argn()

    apifun_checkrhs("distfun_frnd",rhs,2:4)
    apifun_checklhs("distfun_frnd",lhs,0:1)
    
    v1 = varargin(1)
    v2=varargin(2)
    
    //
    // Check type
    apifun_checktype("distfun_frnd",v1,"v1",1,"constant")
    apifun_checktype("distfun_frnd",v2,"v2",2,"constant")
    
    // Check content 
    tiniest=number_properties("tiniest")
    apifun_checkgreq("distfun_frnd",v1,"v1",1,tiniest)
    apifun_checkgreq("distfun_frnd",v2,"v2",2,tiniest)
    
    if ( rhs == 3 ) then
        v = varargin(3)
    end
    if ( rhs == 4 ) then
        m = varargin(3)
        n = varargin(4)
    end
    //
    // Check v,m,n
    distfun_checkvmn ( "distfun_frnd" , 3 , varargin(3:$) )
    
    [v1,v2] = apifun_expandfromsize ( 2 , varargin(1:$) )

    if(v1 == []) then
        R = []
        return
    end

    m = size(v1,"r")
    n = size(v2,"c")

    R = distfun_grandf(m,n,v1,v2)

endfunction

distfun_fstat.sci

// Copyright (C) 2012 - Prateek Papriwal
// Copyright (C) 2012 - Michael Baudin
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt

function [M,V]  = distfun_fstat(varargin)
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_fstat",rhs,2)
    apifun_checklhs("distfun_fstat",lhs,1:2)
    
    v1 = varargin(1)
    v2 = varargin(2)
    
    //
    // Check type
    apifun_checktype("distfun_fstat",v1,"v1",1,"constant")
    apifun_checktype("distfun_fstat",v2,"v2",2,"constant")
    
    // Check content 
    tiniest=number_properties("tiniest")
    apifun_checkgreq("distfun_fstat",v1,"v1",1,tiniest)
    apifun_checkgreq("distfun_fstat",v2,"v2",2,tiniest)
    
    [v1,v2] = apifun_expandvar(v1,v2)
    
    M=ones(v1)*%nan
    i=find(v2>2)
    M(i)=v2(i)./(v2(i)-2)
    
    V=ones(v1)*%nan
    i=find(v2>4)
    V(i)=(2.*v2(i).^2.*(v1(i)+v2(i)-2))./(v1(i).*(v2(i)-2).^2.*(v2(i)-4))
endfunction

2022-09-08 09:26