STK++ 0.9.13
STK_Law_Student.h
Go to the documentation of this file.
1/*--------------------------------------------------------------------*/
2/* Copyright (C) 2004-2016 Serge Iovleff, Université Lille 1, Inria
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as
6 published by the Free Software Foundation; either version 2 of the
7 License, or (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this program; if not, write to the
16 Free Software Foundation, Inc.,
17 59 Temple Place,
18 Suite 330,
19 Boston, MA 02111-1307
20 USA
21
22 Contact : S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
23*/
24
25/*
26 * Project: stkpp::STatistiK::Law
27 * Purpose: Student probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_STUDENT_H
36#define STK_LAW_STUDENT_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
72class Student: public IUnivLaw<Real>
73{
74 public:
79 inline Student( int df = 1.): Base(_T("Student")), df_(df) {}
81 inline virtual ~Student() {}
83 inline int df() const { return df_;}
85 inline void setDf( int df)
86 {
87 if (df<=0) STKDOMAIN_ERROR_1ARG(Student::setShape,df,shape must be > 0);
88 df_ = df;
89 }
91 virtual Real rand() const;
95 virtual Real pdf(Real const& x) const;
99 virtual Real lpdf(Real const& x) const;
103 virtual Real cdf(Real const& t) const;
107 virtual Real icdf(Real const& p) const;
108
112 static Real rand( int df);
117 static Real pdf(Real const& x, int df);
122 static Real lpdf(Real const& x, int df);
127 static Real cdf(Real const& t, int df);
132 static Real icdf(Real const& p, int df);
133
134#ifdef IS_RTKPP_LIB
136 virtual Real lcdf( Real const& t) const;
138 virtual Real cdfc( Real const& t) const;
140 virtual Real lcdfc( Real const& t) const;
141#endif
142
143 protected:
145 int df_;
146};
147
148#ifdef IS_RTKPP_LIB
149
150inline Real Student::rand() const
151{
152#ifdef _OPENMP
153//#pragma omp critical
154#endif
155GetRNGstate(); Real s = Rf_rt(df_); PutRNGstate(); return s;
156}
157
158inline Real Student::pdf(Real const& x) const { return Rf_dt(x, df_, false);}
159inline Real Student::lpdf(Real const& x) const { return Rf_dt(x, df_, true);}
160inline Real Student::cdf(Real const& t) const { return Rf_pt(t, df_, true, false);}
161inline Real Student::lcdf(Real const& t) const { return Rf_pt(t, df_, true, true);}
162inline Real Student::cdfc(Real const& t) const { return Rf_pt(t, df_, false, false);}
163inline Real Student::lcdfc(Real const& t) const { return Rf_pt(t, df_, false, true);}
164inline Real Student::icdf(Real const& p) const { return Rf_qt(p, df_, true, false);}
165
166inline Real Student::rand( int df)
167{
168#ifdef _OPENMP
169//#pragma omp critical
170#endif
171GetRNGstate(); Real s = Rf_rt(df); PutRNGstate(); return s;
172}
173
174inline Real Student::pdf(Real const& x, int df) { return Rf_dt(x, df, false);}
175inline Real Student::lpdf(Real const& x, int df) { return Rf_dt(x, df, true);}
176inline Real Student::cdf(Real const& t, int df) { return Rf_pt(t, df, true, false);}
177inline Real Student::icdf(Real const& p, int df) { return Rf_qt(p, df, true, false);}
178
179#endif
180
181} // namespace Law
182
183} // namespace STK
184
185#endif /*STK_LAW_STUDENT_H*/
In this file we define the interface base class IUnivLaw for all probabilities laws.
#define STKDOMAIN_ERROR_1ARG(Where, Arg, Error)
Definition STK_Macros.h:165
#define _T(x)
Let x unmodified.
Interface base class for all the univariate distributions.
virtual Real cdfc(Real const &t) const
calculate the complement of cumulative distribution function, called in statistics the survival funct...
virtual Real lcdfc(Real const &t) const
calculate the log-complement of cumulative distribution function Give the log-probability that a rand...
virtual Real lcdf(Real const &t) const
compute the lower tail log-cumulative distribution function Give the log-probability that a random va...
Student distribution law.
IUnivLaw< Real > Base
virtual ~Student()
destructor
int df_
degree of freedom
virtual Real rand() const
Student(int df=1.)
Default constructor.
virtual Real icdf(Real const &p) const
virtual Real pdf(Real const &x) const
virtual Real cdf(Real const &t) const
virtual Real lpdf(Real const &x) const
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.
The namespace STK is the main domain space of the Statistical ToolKit project.