#include <statdist.h>
Inheritance diagram for matvec::BinomialDist:

Definition at line 380 of file statdist.h.
Public Methods | |
| BinomialDist (const long n, const double p) | |
| BinomialDist (const BinomialDist &u) | |
| void | display (void) const |
| void | reset (const long n, const double p) |
| void | sample (Vector< double > &x) const |
| void | sample (doubleMatrix &x) const |
| double | sample (void) const |
| Vector< double > | sample (unsigned n) const |
| doubleMatrix | sample (unsigned m, unsigned n) const |
| double | mean (void) const |
| double | variance (void) const |
| double | pdf (const double x) const |
| double | cdf (const double x) const |
| double | pdf (const long k) const |
| double | cdf (const long k) const |
| double | mgf (const double t) const |
| double | inv (const double p) const |
| double | parameter (const int k) const |
| void | parameter (const int k, const double x) |
| virtual const std::string | name (void) const |
| virtual double | nonct (const double cv, const double p) |
Protected Attributes | |
| long | n_value |
| double | p_value |
| std::string | distname |
|
||||||||||||
|
Definition at line 385 of file statdist.h. References matvec::StatDistBase::distname, and reset().
|
|
|
Definition at line 387 of file statdist.h. References matvec::StatDistBase::distname, and reset().
00387 :StatDistBase() 00388 {distname="BinomialDist";reset(u.n_value,u.p_value);} |
|
|
Definition at line 1179 of file statdist.cpp. References matvec::gammln(), n_value, and p_value.
01182 {n!}{(n-x)!x!}p^x(1-p)^{n-x}, \quad x = 0,1,2,\ldots,n
01183 \f]
01184 */
01185 double BinomialDist::pdf(const long k) const
01186 {
01187 if (k > n_value) throw exception("BinomialDist::pdf(): bad arg");
01188 double pr = std::log(p_value)*k + std::log(1.0-p_value)*(n_value - k);
01189 pr += gammln(static_cast<double>(n_value + 1))
01190 - gammln(static_cast<double>(k + 1)) - gammln(static_cast<double>(n_value - k + 1));
01191 if (pr > 0.0) return 1.0;
01192 if (pr < -600.00) return 0.0;
01193 return std::exp(pr);
01194 }
01195
01196 double BinomialDist::cdf(const long k) const
01197 {
|
|
|
Implements matvec::StatDistBase. Definition at line 401 of file statdist.h.
00401 {return cdf(long(x));}
|
|
|
Implements matvec::StatDistBase. Definition at line 390 of file statdist.h. References matvec::StatDistBase::distname, n_value, and p_value.
|
|
|
Implements matvec::StatDistBase. Definition at line 406 of file statdist.h.
00407 {std::cerr << " BinomialDist::inv(): not available\n"; return p;}
|
|
|
Implements matvec::StatDistBase. Definition at line 398 of file statdist.h. References n_value, and p_value.
|
|
|
Implements matvec::StatDistBase. Definition at line 404 of file statdist.h. References n_value, and p_value.
|
|
|
Definition at line 45 of file statdistbase.h. References matvec::StatDistBase::distname.
00045 {return distname;}
|
|
||||||||||||
|
Definition at line 58 of file statdistbase.h.
00058 {std::cerr << "error\n"; return 0.0;}
|
|
||||||||||||
|
Implements matvec::StatDistBase. Definition at line 1246 of file statdist.cpp.
01249 {
01250 double par = 0.0;
01251 if (k==1) {
01252 par = static_cast<double>(n_value);
01253 }
01254 else if (k==2) {
01255 par = p_value;
01256 }
01257 else {
01258 throw exception("BinomialDist::parameter(): bad arg, 1 or 2 is expected");
01259 }
01260 return par;
01261 }
01262
|
|
|
Implements matvec::StatDistBase. Definition at line 1231 of file statdist.cpp.
01235 {
01236 Vector<double> x(n);
01237 sample(x);
01238 return x;
01239 }
01240
01241 doubleMatrix BinomialDist::sample(unsigned m,unsigned n) const
01242 {
01243 doubleMatrix x(m,n);
01244 sample(x);
|
|
|
The random variable X has a binomial distribution if its probability density function (pdf) is defined by
Definition at line 1168 of file statdist.cpp.
|
|
|
Implements matvec::StatDistBase. Definition at line 400 of file statdist.h.
00400 {return pdf(long(x));}
|
|
||||||||||||
|
Definition at line 1157 of file statdist.cpp. References matvec::DiscreteUniformDist::a_value, and matvec::DiscreteUniformDist::b_value. Referenced by BinomialDist().
01157 {
01158 if (a_value <= x) {
01159 b_value = static_cast<long int>(x);
01160 }
01161 else {
01162 throw exception("DiscreUniformDist::parameter(): bad arg2");
|
|
||||||||||||
|
Implements matvec::StatDistBase. Definition at line 1224 of file statdist.cpp. References matvec::ignbin(), n_value, and p_value.
01224 {
01225 int nr = x.num_rows();
01226 int nc = x.num_cols();
01227 double *bot,*top;
01228 for (unsigned i=0; i<nr; i++) {
01229 bot = x[i]; top = &bot[nc];
|
|
|
Implements matvec::StatDistBase. Definition at line 1217 of file statdist.cpp. References matvec::ignbin(), n_value, and p_value.
|
|
|
Implements matvec::StatDistBase. Definition at line 395 of file statdist.h. References matvec::ignbin(), n_value, and p_value.
|
|
|
Implements matvec::StatDistBase. Definition at line 1206 of file statdist.cpp.
|
|
|
Implements matvec::StatDistBase. Definition at line 1199 of file statdist.cpp. References matvec::betain(), matvec::gammln(), n_value, and p_value.
|
|
|
Implements matvec::StatDistBase. Definition at line 399 of file statdist.h. References n_value, and p_value.
|
|
|
|
Definition at line 382 of file statdist.h. Referenced by cdf(), display(), mean(), mgf(), matvec::PoissonDist::reset(), sample(), and variance(). |
|
|
Definition at line 383 of file statdist.h. Referenced by cdf(), display(), mean(), mgf(), sample(), and variance(). |
1.2.16