STK++ 0.9.13
STK_Law_ChiSquared.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: ChiSquared probability distribution.
28 * Author: Serge Iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_CHISQUARED_H
36#define STK_LAW_CHISQUARED_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
62class ChiSquared: public IUnivLaw<Real>
63{
64 public:
69 inline ChiSquared( int df = 1): Base(_T("Chi-squared")), df_(df)
72 inline virtual ~ChiSquared(){}
74 inline int df() const { return df_;}
76 inline void setDf( int df)
77 {
78 if (df<=0) STKDOMAIN_ERROR_1ARG(ChiSquared::setShape,df,shape must be > 0);
79 df_ = df;
80 }
82 virtual Real rand() const;
86 virtual Real pdf(Real const& x) const;
90 virtual Real lpdf(Real const& x) const;
94 virtual Real cdf(Real const& t) const;
98 virtual Real icdf(Real const& p) const;
99
103 static Real rand( int df);
108 static Real pdf(Real const& x, int df);
113 static Real lpdf(Real const& x, int df);
118 static Real cdf(Real const& t, int df);
123 static Real icdf(Real const& p, int df);
124
125#ifdef IS_RTKPP_LIB
127 virtual Real lcdf( Real const& t) const;
129 virtual Real cdfc( Real const& t) const;
131 virtual Real lcdfc( Real const& t) const;
132#endif
133
134 protected:
136 int df_;
137};
138
139#ifdef IS_RTKPP_LIB
140
141/* @return a pseudo ChiSquared random variate. */
142inline Real ChiSquared::rand() const
143{
144#ifdef _OPENMP
145//#pragma omp critical
146#endif
147 GetRNGstate(); Real s = Rf_rchisq(df_); PutRNGstate(); return s;
148}
149
150inline Real ChiSquared::pdf(const Real& x) const { return Rf_dchisq(x, df_, false);}
151inline Real ChiSquared::lpdf(const Real& x) const { return Rf_dchisq(x, df_, true);}
152inline Real ChiSquared::cdf(const Real& t) const { return Rf_pchisq(t, df_, true, false);}
153inline Real ChiSquared::lcdf(const Real& t) const { return Rf_pchisq(t, df_, true, true);}
154inline Real ChiSquared::cdfc(const Real& t) const { return Rf_pchisq(t, df_, false, false);}
155inline Real ChiSquared::lcdfc(const Real& t) const { return Rf_pchisq(t, df_, false, true);}
156inline Real ChiSquared::icdf(const Real& p) const { return Rf_qchisq(p, df_, true, false);}
157
158inline Real ChiSquared::rand(int df)
159{
160#ifdef _OPENMP
161//#pragma omp critical
162#endif
163GetRNGstate(); Real s = Rf_rchisq(df); PutRNGstate(); return s;
164}
165
166inline Real ChiSquared::pdf(const Real& x, int df) { return Rf_dchisq(x, df, false);}
167inline Real ChiSquared::lpdf(const Real& x, int df) { return Rf_dchisq(x, df, true);}
168inline Real ChiSquared::cdf(const Real& t, int df) { return Rf_pchisq(t, df, true, false);}
169inline Real ChiSquared::icdf(const Real& p, int df) { return Rf_qchisq(p, df, true, false);}
170
171#endif
172
173} // namespace Law
174
175} // namespace STK
176
177#endif /*STK_LAW_CHISQUARED_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.
ChiSquared distribution law.
virtual Real rand() const
virtual Real icdf(Real const &p) const
virtual Real lpdf(Real const &x) const
virtual Real pdf(Real const &x) const
virtual ~ChiSquared()
destructor
int df_
degree of freedom
ChiSquared(int df=1)
Default constructor.
virtual Real cdf(Real const &t) const
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...
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.