STK++ 0.9.13
STK_Law_NegativeBinomial.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 * created on: 23 janv. 2013
28 * Author: iovleff, S..._Dot_I..._At_stkpp_Dot_org (see copyright for ...)
29 **/
30
35#ifndef STK_LAW_NEGATIVEBINOMIAL_H
36#define STK_LAW_NEGATIVEBINOMIAL_H
37
38#include "STK_Law_IUnivLaw.h"
39
40namespace STK
41{
42
43namespace Law
44{
45
68class NegativeBinomial: public IUnivLaw<Integer>
69{
70 public:
75 inline NegativeBinomial( int size =1, Real const& prob =0.5)
76 : Base(_T("Negative Binomial")), size_(size), prob_(prob) {}
77
79 inline virtual ~NegativeBinomial() {}
81 inline Real const& prob() const { return prob_;}
83 inline int size() const { return size_;}
97
99 virtual Integer rand() const;
106 virtual Real cdf(Real const& t) const;
112 virtual Real pdf(Integer const& x) const;
118 virtual Real lpdf(Integer const& x) const;
124 virtual Integer icdf(Real const& p) const;
125
129 static Integer rand( int size, Real const& prob);
136 static Real pdf(Integer x, int size, Real const& prob);
143 static Real lpdf(Integer x, int size, Real const& prob);
150 static Real cdf(Real const& t, int size, Real const& prob);
157 static Integer icdf(Real const& p, int size, Real const& prob);
158
159#ifdef IS_RTKPP_LIB
161 virtual Real lcdf( Real const& t) const;
163 virtual Real cdfc( Real const& t) const;
165 virtual Real lcdfc( Real const& t) const;
166#endif
167
168 protected:
170 int size_;
173};
174
175#ifdef IS_RTKPP_LIB
176
177inline int NegativeBinomial::rand() const
178{
179#ifdef _OPENMP
180//#pragma omp critical
181#endif
182GetRNGstate(); int s = Rf_rnbinom(size_, prob_); PutRNGstate(); return s;
183}
184
185inline Real NegativeBinomial::pdf(Integer const& x) const { return Rf_dnbinom((double)x, size_, prob_, false);}
186inline Real NegativeBinomial::lpdf(Integer const& x) const { return Rf_dnbinom((double)x, size_, prob_, true);}
187inline Real NegativeBinomial::cdf(Real const& t) const { return Rf_pnbinom(t, size_, prob_, true, false);}
188inline Real NegativeBinomial::lcdf(Real const& t) const { return Rf_pnbinom(t, size_, prob_, true, true);}
189inline Real NegativeBinomial::cdfc(Real const& t) const { return Rf_pnbinom(t, size_, prob_, false, false);}
190inline Real NegativeBinomial::lcdfc(Real const& t) const { return Rf_pnbinom(t, size_, prob_, false, true);}
191inline int NegativeBinomial::icdf(Real const& p) const { return (int)Rf_qnbinom(p, size_, prob_, true, false);}
192
193inline int NegativeBinomial::rand(int size, Real const& prob)
194{
195#ifdef _OPENMP
196//#pragma omp critical
197#endif
198GetRNGstate(); int s = Rf_rnbinom(size, prob); PutRNGstate(); return s;
199}
200
201inline Real NegativeBinomial::pdf(Integer x, int size, Real const& prob)
202{ return Rf_dnbinom((double)x, size, prob, false);}
203inline Real NegativeBinomial::lpdf(Integer x, int size, Real const& prob)
204{ return Rf_dnbinom((double)x, size, prob, true);}
205inline Real NegativeBinomial::cdf(Real const& t, int size, Real const& prob)
206{ return Rf_pnbinom(t, size, prob , true, false);}
207inline int NegativeBinomial::icdf(Real const& p, int size, Real const& prob)
208{ return (int)::Rf_qnbinom(p, size, prob , true, false);}
209
210#endif
211
212} // namespace Law
213
214} // namespace STK
215
216#endif /* STK_LAW_NEGATIVEBINOMIAL_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...
NegativeBinomial probability law.
virtual Real cdf(Real const &t) const
compute the cumulative distribution function Give the probability that a NegativeBinomial random vari...
NegativeBinomial(int size=1, Real const &prob=0.5)
constructor
virtual Real lpdf(Integer const &x) const
compute the log probability distribution function Give the value of the log-pdf at the point x.
virtual Real pdf(Integer const &x) const
compute the probability distribution function (density) Give the value of the pdf at the point x.
virtual Integer icdf(Real const &p) const
inverse cumulative distribution function The quantile is defined as the smallest value x such that F...
Real prob_
probability of success in a Bernoulli trial
The MultidimRegression class allows to regress a multidimensional output variable among a multivariat...
double Real
STK fundamental type of Real values.
int Integer
STK fundamental type of integer values.
The namespace STK is the main domain space of the Statistical ToolKit project.