Source code of t 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 t distribution function.

A word of caution

These function are just temporary work and may contain bugs.

distfun_tpdf.sci

// Copyright (C) 2012 - Prateek Papriwal
//
// 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_tpdf(varargin)
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_tpdf",rhs,2)
    apifun_checklhs("distfun_tpdf",lhs,0:1)
    
    x=varargin(1)
    v=varargin(2)
    //
    // Check type
    apifun_checktype("distfun_tpdf",x,"x",1,"constant")
    apifun_checktype("distfun_tpdf",v,"v",2,"constant")
    //
    // Check content
    apifun_checkgreq("distfun_tpdf",v,"v",2,1)
    apifun_checkflint("distfun_tpdf",v,"v",2)
    
    tmp = 1 ./ 2
    
    [x,v,tmp] = apifun_expandvar(x,v,tmp)
    
    if (x == []) then
        y = []
        return
    end
    
    y = (exp(-(v+1) .* log(1+x .^ 2 ./ v ) ./ 2) ./ (sqrt (v) .* beta(v ./ 2 , tmp)))
    
endfunction

distfun_tcdf.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_tcdf(varargin)
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_tcdf",rhs,2:3)
    apifun_checklhs("distfun_tcdf",lhs,0:1)
    
    x = varargin(1)
    v = varargin(2)
    lowertail = apifun_argindefault(varargin,3,%t)
    //
    // Check type
    apifun_checktype("distfun_tcdf",x,"x",1,"constant")
    apifun_checktype("distfun_tcdf",v,"v",2,"constant")
    apifun_checktype("distfun_tcdf",lowertail,"lowertail",3,"boolean")
    
    apifun_checkscalar("distfun_tcdf",lowertail,"lowertail",3)
    //
    // Check content
    apifun_checkgreq("distfun_tcdf",v,"v",2,1)
    
    apifun_checkflint("distfun_tcdf",v,"v",2)
    
    [x,v] = apifun_expandvar(x,v)
    
    if (x == []) then
        p = []
        return
    end
    
    if (lowertail) then
        p = distfun_cdft(x,v)
    else
        [ignored,p] = distfun_cdft(x,v)
    end
    
endfunction

distfun_tinv.sci

// Copyright (C) 2012 - Prateek Papriwal
//
// 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_tinv(varargin)
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_tinv",rhs,2:3)
    apifun_checklhs("distfun_tinv",lhs,0:1)
    
    p = varargin(1)
    v = varargin(2)
    lowertail = apifun_argindefault(varargin,3,%t)
    //
    // Check type
    apifun_checktype("distfun_tinv",p,"p",1,"constant")
    apifun_checktype("distfun_tinv",v,"v",2,"constant")
    apifun_checktype("distfun_tinv",lowertail,"lowertail",3,"boolean")
    
    apifun_checkscalar("distfun_tinv",lowertail,"lowertail",3)
    //
    // Check content
    apifun_checkgreq("distfun_tinv",v,"v",2,1)
    
    apifun_checkflint("distfun_tinv",v,"v",2)
    
    [p,v] = apifun_expandvar(p,v)
    
    if (p == []) then
        x = []
        return
    end
    
    path = distfun_getpath()
    internallib = lib(fullfile(path,"macros","internals"))
    q = distfun_p2q(p)
    
    
    if (lowertail) then
        x = distfun_invcdft(v,p,q)
    else
        x = distfun_invcdft(v,q,p)
    end
endfunction

distfun_trnd.sci

// Copyright (C) 2012 - Prateek Papriwal
//
// 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_trnd(varargin)
    path = distfun_getpath()
    internallib = lib(fullfile(path,"macros","internals"))

    [lhs,rhs] = argn()

    apifun_checkrhs("distfun_trnd",rhs,1:3)
    apifun_checklhs("distfun_trnd",lhs,0:1)
    
    v = varargin(1)
        
    //
    // Check type
    apifun_checktype("distfun_trnd",v,"v",1,"constant")
    
    // Check content 
    
    apifun_checkgreq("distfun_trnd",v,"v",1,1)
    
    apifun_checkflint("distfun_trnd",v,"v",1)
    
    
    if ( rhs == 2 ) then
        v = varargin(2)
    end
    if ( rhs == 3 ) then
        m = varargin(2)
        n = varargin(3)
    end
    //
    // Check v,m,n
    distfun_checkvmn ( "distfun_trnd" , 2 , varargin(2:$) )
    
    [v] = apifun_expandfromsize ( 1 , varargin(1:$) )
    
    if(v == []) then
        R = []
        return
    end

    m = size(v,"r")
    n = size(v,"c")
    
    u = distfun_unifrnd(0,1,m,n)
    R = distfun_tinv(u,v)
    
endfunction

distfun_tstat.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_tstat(varargin)
    [lhs,rhs] = argn()
    apifun_checkrhs("distfun_tstat",rhs,1)
    apifun_checklhs("distfun_tstat",lhs,1:2)
    
    v = varargin(1)
    
    //
    // Check type
    apifun_checktype("distfun_tstat",v,"v",1,"constant")
    
    // Check content 
    
    apifun_checkgreq("distfun_tstat",v,"v",1,1)
    
    apifun_checkflint("distfun_tstat",v,"v",1)
    
    [v] = apifun_expandvar(v)
    
    M=ones(v)*%nan
    i=find(v>1)
    Z=zeros(V)
    M(i)=Z(i)
    
    V=ones(v)*%nan
    i=find( v > 1 & v<=2 )
    I=ones(v)*%inf
    V(i)=I(i)
    i=find( v > 2 )
    V(i) = v(i) ./ (v(i)-2)
    
endfunction

public: Contributor-stats-GSOC2012/tdist_src (last edited 2012-08-29 09:39:04 by michael.baudin@contrib.scilab.org)