ℹ️ Skipped - page is already crawled
| Filter | Status | Condition | Details |
|---|---|---|---|
| HTTP status | PASS | download_http_code = 200 | HTTP 200 |
| Age cutoff | PASS | download_stamp > now() - 6 MONTH | 0.7 months ago |
| History drop | PASS | isNull(history_drop_reason) | No drop reason |
| Spam/ban | PASS | fh_dont_index != 1 AND ml_spam_score = 0 | ml_spam_score=0 |
| Canonical | FAIL | meta_canonical IS NULL OR = '' OR = src_unparsed | org,boost!www,/doc/libs/latest/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html s443 |
| Property | Value |
|---|---|
| URL | https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html |
| Last Crawled | 2026-03-27 19:22:12 (20 days ago) |
| First Indexed | 2018-05-16 12:29:25 (7 years ago) |
| HTTP Status Code | 200 |
| Meta Title | Beta Distribution |
| Meta Description | null |
| Meta Canonical | org,boost!www,/doc/libs/latest/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html s443 |
| Boilerpipe Text | #include
<
boost
/
math
/
distributions
/
beta
.
hpp
>
namespace
boost
{
namespace
math
{
template
<
class
RealType
=
double
,
class
Policy
=
policies::policy<>
>
class
beta_distribution
;
template
<
class
RealType
,
class
Policy
>
class
beta_distribution
{
public
:
typedef
RealType
value_type
;
typedef
Policy
policy_type
;
beta_distribution
(
RealType
a
,
RealType
b
);
RealType
alpha
()
const
;
RealType
beta
()
const
;
static
RealType
find_alpha
(
RealType
mean
,
RealType
variance
);
static
RealType
find_beta
(
RealType
mean
,
RealType
variance
);
static
RealType
find_alpha
(
RealType
beta
,
RealType
x
,
RealType
probability
);
static
RealType
find_beta
(
RealType
alpha
,
RealType
x
,
RealType
probability
);
};
}}
The class type
beta_distribution
represents a
beta
probability
distribution function
.
The
beta
distribution
is used as a
prior
distribution
for binomial proportions in
Bayesian
analysis
.
See also:
beta
distribution
and
Bayesian
statistics
.
How the beta distribution is used for
Bayesian
analysis of one parameter models
is discussed by Jeff Grynaviski.
The
probability
density function PDF
for the
beta
distribution
defined on the interval [0,1] is given by:
f(x;α,β) = x
α - 1
(1 - x)
β -1
/ B(α, β)
where B(α, β) is the
beta
function
, implemented in this library as
beta
.
Division by the beta function ensures that the pdf is normalized to the
range zero to unity.
The following graph illustrates examples of the pdf for various values
of the shape parameters. Note the α = β = 2 (blue line) is dome-shaped, and
might be approximated by a symmetrical triangular distribution.
If α = β = 1, then it is a __space
uniform
distribution
, equal to unity in the entire interval x = 0 to 1.
If α __space and β __space are < 1, then the pdf is U-shaped. If α != β, then
the shape is asymmetric and could be approximated by a triangle whose apex
is away from the centre (where x = half).
Member
Functions
Constructor
beta_distribution
(
RealType
alpha
,
RealType
beta
);
Constructs a beta distribution with shape parameters
alpha
and
beta
.
Requires alpha,beta > 0,otherwise
domain_error
is called. Note that technically the beta distribution is defined for alpha,beta
>= 0, but it's not clear whether any program can actually make use of
that latitude or how many of the non-member functions can be usefully defined
in that case. Therefore for now, we regard it as an error if alpha or beta
is zero.
For example:
beta_distribution
<>
mybeta
(
2
,
5
);
Constructs a the beta distribution with alpha=2 and beta=5 (shown in yellow
in the graph above).
Parameter
Accessors
RealType
alpha
()
const
;
Returns the parameter
alpha
from which this distribution
was constructed.
RealType
beta
()
const
;
Returns the parameter
beta
from which this distribution
was constructed.
So for example:
beta_distribution
<>
mybeta
(
2
,
5
);
assert
(
mybeta
.
alpha
()
==
2.
);
assert
(
mybeta
.
beta
()
==
5.
);
Parameter
Estimators
Two pairs of parameter estimators are provided.
One estimates either α __space or β __space from presumed-known mean and variance.
The other pair estimates either α __space or β __space from the cdf and x.
It is also possible to estimate α __space and β __space from 'known' mode &
quantile. For example, calculators are provided by the
Pooled
Prevalence Calculator
and
Beta
Buster
but this is not yet implemented here.
static
RealType
find_alpha
(
RealType
mean
,
RealType
variance
);
Returns the unique value of α that corresponds to a beta distribution with
mean
mean
and variance
variance
.
static
RealType
find_beta
(
RealType
mean
,
RealType
variance
);
Returns the unique value of β that corresponds to a beta distribution with
mean
mean
and variance
variance
.
static
RealType
find_alpha
(
RealType
beta
,
RealType
x
,
RealType
probability
);
Returns the value of α that gives:
cdf
(
beta_distribution
<
RealType
>(
alpha
,
beta
),
x
)
==
probability
.
static
RealType
find_beta
(
RealType
alpha
,
RealType
x
,
RealType
probability
);
Returns the value of β that gives:
cdf
(
beta_distribution
<
RealType
>(
alpha
,
beta
),
x
)
==
probability
.
Non-member
Accessor Functions
All the
usual non-member accessor
functions
that are generic to all distributions are supported:
Cumulative Distribution Function
,
Probability Density Function
,
Quantile
,
Hazard Function
,
Cumulative Hazard Function
,
mean
,
median
,
mode
,
variance
,
standard deviation
,
skewness
,
kurtosis
,
kurtosis_excess
,
range
and
support
.
The formulae for calculating these are shown in the table below, and at
Wolfram
Mathworld
.
Applications
The beta distribution can be used to model events constrained to take place
within an interval defined by a minimum and maximum value: so it is used
in project management systems.
It is also widely used in
Bayesian
statistical inference
.
Related
distributions
The beta distribution with both α __space and β = 1 follows a
uniform
distribution
.
The
triangular
is used when less precise information is available.
The
binomial
distribution
is closely related when α __space and β __space are integers.
With integer values of α __space and β __space the distribution B(i, j) is
that of the j-th highest of a sample of i + j + 1 independent random variables
uniformly distributed between 0 and 1. The cumulative probability from
0 to x is thus the probability that the j-th highest value is less than
x. Or it is the probability that at least i of the random variables are
less than x, a probability given by summing over the
Binomial
Distribution
with its p parameter set to x.
Accuracy
This distribution is implemented using the
beta
functions
beta
and
incomplete beta
functions
ibeta
and
ibetac
;
please refer to these functions for information on accuracy.
Implementation
In the following table
a
and
b
are the parameters α and β,
x
is the random variable,
p
is the probability and
q = 1-p
.
Function
Implementation Notes
pdf
f(x;α,β) = x
α - 1
(1 - x)
β -1
/ B(α, β)
Implemented using
ibeta_derivative
(a,
b, x).
cdf
Using the incomplete beta function
ibeta
(a,
b, x)
cdf complement
ibetac
(a,
b, x)
quantile
Using the inverse incomplete beta function
ibeta_inv
(a,
b, p)
quantile from the complement
ibetac_inv
(a,
b, q)
mean
a
/(
a
+
b
)
variance
a
*
b
/
(
a
+
b
)^
2
*
(
a
+
b
+
1
)
mode
(
a
-
1
)
/
(
a
+
b
-
2
)
skewness
2
(
b
-
a
)
sqrt
(
a
+
b
+
1
)/(
a
+
b
+
2
)
*
sqrt
(
a
*
b
)
kurtosis excess
kurtosis
kurtosis
+
3
parameter estimation
alpha
from mean and variance
mean
*
((
(
mean
*
(
1
-
mean
))
/
variance
)-
1
)
beta
from mean and variance
(
1
-
mean
)
*
(((
mean
*
(
1
-
mean
))
/
variance
)-
1
)
The member functions
find_alpha
and
find_beta
from cdf and probability x
and
either
alpha
or
beta
Implemented in terms of the inverse incomplete beta functions
ibeta_inva
,
and
ibeta_invb
respectively.
find_alpha
ibeta_inva
(
beta
,
x
,
probability
)
find_beta
ibeta_invb
(
alpha
,
x
,
probability
)
References
Wikipedia Beta
distribution
NIST
Exploratory Data Analysis
Wolfram
MathWorld |
| Markdown | # [ Boost C++ Libraries](https://www.boost.org/)
"...one of the most highly regarded and expertly designed C++ library projects in the world." — [Herb Sutter](https://herbsutter.com/) and [Andrei Alexandrescu](http://en.wikipedia.org/wiki/Andrei_Alexandrescu), [C++ Coding Standards](https://books.google.com/books/about/C++_Coding_Standards.html?id=mmjVIC6WolgC)
Search...
This is an older version of Boost and was released in 2016. The [current version](https://www.boost.org/doc/libs/latest/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html) is 1.90.0.
[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/bernoulli_dist.html)[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists.html)[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/index.html)[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/binomial_dist.html)
#### [Beta Distribution](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html "Beta Distribution")
```
#include <boost/math/distributions/beta.hpp>
```
```
namespace boost{ namespace math{
template <class RealType = double,
class Policy = policies::policy<> >
class beta_distribution;
// typedef beta_distribution<double> beta;
// Note that this is deliberately NOT provided,
// to avoid a clash with the function name beta.
template <class RealType, class Policy>
class beta_distribution
{
public:
typedef RealType value_type;
typedef Policy policy_type;
// Constructor from two shape parameters, alpha & beta:
beta_distribution(RealType a, RealType b);
// Parameter accessors:
RealType alpha() const;
RealType beta() const;
// Parameter estimators of alpha or beta from mean and variance.
static RealType find_alpha(
RealType mean, // Expected value of mean.
RealType variance); // Expected value of variance.
static RealType find_beta(
RealType mean, // Expected value of mean.
RealType variance); // Expected value of variance.
// Parameter estimators from
// either alpha or beta, and x and probability.
static RealType find_alpha(
RealType beta, // from beta.
RealType x, // x.
RealType probability); // cdf
static RealType find_beta(
RealType alpha, // alpha.
RealType x, // probability x.
RealType probability); // probability cdf.
};
}} // namespaces
```
The class type `beta_distribution` represents a [beta](http://en.wikipedia.org/wiki/Beta_distribution) [probability distribution function](http://en.wikipedia.org/wiki/Probability_distribution).
The [beta distribution](http://mathworld.wolfram.com/BetaDistribution.htm) is used as a [prior distribution](http://en.wikipedia.org/wiki/Prior_distribution) for binomial proportions in [Bayesian analysis](http://mathworld.wolfram.com/BayesianAnalysis.html).
See also: [beta distribution](http://documents.wolfram.com/calculationcenter/v2/Functions/ListsMatrices/Statistics/BetaDistribution.html) and [Bayesian statistics](http://en.wikipedia.org/wiki/Bayesian_statistics).
How the beta distribution is used for [Bayesian analysis of one parameter models](http://home.uchicago.edu/~grynav/bayes/ABSLec5.ppt) is discussed by Jeff Grynaviski.
The [probability density function PDF](http://en.wikipedia.org/wiki/Probability_density_function) for the [beta distribution](http://en.wikipedia.org/wiki/Beta_distribution) defined on the interval \[0,1\] is given by:
f(x;α,β) = xα - 1 (1 - x)β -1 / B(α, β)
where B(α, β) is the [beta function](http://en.wikipedia.org/wiki/Beta_function), implemented in this library as [beta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html "Beta"). Division by the beta function ensures that the pdf is normalized to the range zero to unity.
The following graph illustrates examples of the pdf for various values of the shape parameters. Note the α = β = 2 (blue line) is dome-shaped, and might be approximated by a symmetrical triangular distribution.

If α = β = 1, then it is a \_\_space [uniform distribution](http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29), equal to unity in the entire interval x = 0 to 1. If α \_\_space and β \_\_space are \< 1, then the pdf is U-shaped. If α != β, then the shape is asymmetric and could be approximated by a triangle whose apex is away from the centre (where x = half).
##### [Member Functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.member_functions)
###### [Constructor](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.constructor)
```
beta_distribution(RealType alpha, RealType beta);
```
Constructs a beta distribution with shape parameters *alpha* and *beta*.
Requires alpha,beta \> 0,otherwise [domain\_error](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/error_handling.html#math_toolkit.error_handling.domain_error) is called. Note that technically the beta distribution is defined for alpha,beta \>= 0, but it's not clear whether any program can actually make use of that latitude or how many of the non-member functions can be usefully defined in that case. Therefore for now, we regard it as an error if alpha or beta is zero.
For example:
```
beta_distribution<> mybeta(2, 5);
```
Constructs a the beta distribution with alpha=2 and beta=5 (shown in yellow in the graph above).
###### [Parameter Accessors](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.parameter_accessors)
```
RealType alpha() const;
```
Returns the parameter *alpha* from which this distribution was constructed.
```
RealType beta() const;
```
Returns the parameter *beta* from which this distribution was constructed.
So for example:
```
beta_distribution<> mybeta(2, 5);
assert(mybeta.alpha() == 2.); // mybeta.alpha() returns 2
assert(mybeta.beta() == 5.); // mybeta.beta() returns 5
```
##### [Parameter Estimators](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.parameter_estimators)
Two pairs of parameter estimators are provided.
One estimates either α \_\_space or β \_\_space from presumed-known mean and variance.
The other pair estimates either α \_\_space or β \_\_space from the cdf and x.
It is also possible to estimate α \_\_space and β \_\_space from 'known' mode & quantile. For example, calculators are provided by the [Pooled Prevalence Calculator](http://www.ausvet.com.au/pprev/content.php?page=PPscript) and [Beta Buster](http://www.epi.ucdavis.edu/diagnostictests/betabuster.html) but this is not yet implemented here.
```
static RealType find_alpha(
RealType mean, // Expected value of mean.
RealType variance); // Expected value of variance.
```
Returns the unique value of α that corresponds to a beta distribution with mean *mean* and variance *variance*.
```
static RealType find_beta(
RealType mean, // Expected value of mean.
RealType variance); // Expected value of variance.
```
Returns the unique value of β that corresponds to a beta distribution with mean *mean* and variance *variance*.
```
static RealType find_alpha(
RealType beta, // from beta.
RealType x, // x.
RealType probability); // probability cdf
```
Returns the value of α that gives: `cdf(beta_distribution<RealType>(alpha, beta), x) == probability`.
```
static RealType find_beta(
RealType alpha, // alpha.
RealType x, // probability x.
RealType probability); // probability cdf.
```
Returns the value of β that gives: `cdf(beta_distribution<RealType>(alpha, beta), x) == probability`.
##### [Non-member Accessor Functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.non_member_accessor_functions)
All the [usual non-member accessor functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html "Non-Member Properties") that are generic to all distributions are supported: [Cumulative Distribution Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.cdf), [Probability Density Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.pdf), [Quantile](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.quantile), [Hazard Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.hazard), [Cumulative Hazard Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.chf), [mean](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.mean), [median](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.median), [mode](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.mode), [variance](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.variance), [standard deviation](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.sd), [skewness](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.skewness), [kurtosis](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.kurtosis), [kurtosis\_excess](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess), [range](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.range) and [support](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.support).
The formulae for calculating these are shown in the table below, and at [Wolfram Mathworld](http://mathworld.wolfram.com/BetaDistribution.html).
##### [Applications](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.applications)
The beta distribution can be used to model events constrained to take place within an interval defined by a minimum and maximum value: so it is used in project management systems.
It is also widely used in [Bayesian statistical inference](http://en.wikipedia.org/wiki/Bayesian_inference).
##### [Related distributions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.related_distributions)
The beta distribution with both α \_\_space and β = 1 follows a [uniform distribution](http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29).
The [triangular](http://en.wikipedia.org/wiki/Triangular_distribution) is used when less precise information is available.
The [binomial distribution](http://en.wikipedia.org/wiki/Binomial_distribution) is closely related when α \_\_space and β \_\_space are integers.
With integer values of α \_\_space and β \_\_space the distribution B(i, j) is that of the j-th highest of a sample of i + j + 1 independent random variables uniformly distributed between 0 and 1. The cumulative probability from 0 to x is thus the probability that the j-th highest value is less than x. Or it is the probability that at least i of the random variables are less than x, a probability given by summing over the [Binomial Distribution](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/binomial_dist.html "Binomial Distribution") with its p parameter set to x.
##### [Accuracy](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.accuracy)
This distribution is implemented using the [beta functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html "Beta") [beta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html "Beta") and [incomplete beta functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions") [ibeta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions") and [ibetac](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions"); please refer to these functions for information on accuracy.
##### [Implementation](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.implementation)
In the following table *a* and *b* are the parameters α and β, *x* is the random variable, *p* is the probability and *q = 1-p*.
| Function | Implementation Notes |
|---|---|
| pdf | f(x;α,β) = xα - 1 (1 - x)β -1 / B(α, β) Implemented using [ibeta\_derivative](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_derivative.html "Derivative of the Incomplete Beta Function")(a, b, x). |
| cdf | Using the incomplete beta function [ibeta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions")(a, b, x) |
| cdf complement | [ibetac](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions")(a, b, x) |
| quantile | Using the inverse incomplete beta function [ibeta\_inv](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses")(a, b, p) |
| quantile from the complement | [ibetac\_inv](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses")(a, b, q) |
| mean | `a/(a+b)` |
| variance | |
| mode | |
| skewness | |
| kurtosis excess |  |
| kurtosis | |
| parameter estimation | |
| alpha from mean and variance | |
| beta from mean and variance | |
| The member functions `find_alpha` and `find_beta` from cdf and probability x and **either** `alpha` or `beta` | Implemented in terms of the inverse incomplete beta functions [ibeta\_inva](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses"), and [ibeta\_invb](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses") respectively. |
| `find_alpha` | |
| `find_beta` | |
##### [References](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.references)
[Wikipedia Beta distribution](http://en.wikipedia.org/wiki/Beta_distribution)
[NIST Exploratory Data Analysis](http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm)
[Wolfram MathWorld](http://mathworld.wolfram.com/BetaDistribution.html)
| | |
|---|---|
| | Copyright © 2006-2010, 2012-2014 Nikhar Agrawal, Anton Bikineev, Paul A. Bristow, Marco Guazzone, Christopher Kormanyos, Hubert Holin, Bruno Lalande, John Maddock, Jeremy Murphy, Johan Råde, Gautam Sewani, Benjamin Sobotta, Thijs van den Berg, Daryle Walker and Xiaogang Zhang Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE\_1\_0.txt or copy at <http://www.boost.org/LICENSE_1_0.txt>) |
***
[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/bernoulli_dist.html)[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists.html)[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/index.html)[](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/binomial_dist.html) |
| Readable Markdown | ```
#include <boost/math/distributions/beta.hpp>
```
```
namespace boost{ namespace math{
template <class RealType = double,
class Policy = policies::policy<> >
class beta_distribution;
template <class RealType, class Policy>
class beta_distribution
{
public:
typedef RealType value_type;
typedef Policy policy_type;
beta_distribution(RealType a, RealType b);
RealType alpha() const;
RealType beta() const;
static RealType find_alpha(
RealType mean,
RealType variance);
static RealType find_beta(
RealType mean,
RealType variance);
static RealType find_alpha(
RealType beta,
RealType x,
RealType probability);
static RealType find_beta(
RealType alpha,
RealType x,
RealType probability);
};
}}
```
The class type `beta_distribution` represents a [beta](http://en.wikipedia.org/wiki/Beta_distribution) [probability distribution function](http://en.wikipedia.org/wiki/Probability_distribution).
The [beta distribution](http://mathworld.wolfram.com/BetaDistribution.htm) is used as a [prior distribution](http://en.wikipedia.org/wiki/Prior_distribution) for binomial proportions in [Bayesian analysis](http://mathworld.wolfram.com/BayesianAnalysis.html).
See also: [beta distribution](http://documents.wolfram.com/calculationcenter/v2/Functions/ListsMatrices/Statistics/BetaDistribution.html) and [Bayesian statistics](http://en.wikipedia.org/wiki/Bayesian_statistics).
How the beta distribution is used for [Bayesian analysis of one parameter models](http://home.uchicago.edu/~grynav/bayes/ABSLec5.ppt) is discussed by Jeff Grynaviski.
The [probability density function PDF](http://en.wikipedia.org/wiki/Probability_density_function) for the [beta distribution](http://en.wikipedia.org/wiki/Beta_distribution) defined on the interval \[0,1\] is given by:
f(x;α,β) = xα - 1 (1 - x)β -1 / B(α, β)
where B(α, β) is the [beta function](http://en.wikipedia.org/wiki/Beta_function), implemented in this library as [beta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html "Beta"). Division by the beta function ensures that the pdf is normalized to the range zero to unity.
The following graph illustrates examples of the pdf for various values of the shape parameters. Note the α = β = 2 (blue line) is dome-shaped, and might be approximated by a symmetrical triangular distribution.

If α = β = 1, then it is a \_\_space [uniform distribution](http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29), equal to unity in the entire interval x = 0 to 1. If α \_\_space and β \_\_space are \< 1, then the pdf is U-shaped. If α != β, then the shape is asymmetric and could be approximated by a triangle whose apex is away from the centre (where x = half).
##### [Member Functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.member_functions)
###### [Constructor](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.constructor)
```
beta_distribution(RealType alpha, RealType beta);
```
Constructs a beta distribution with shape parameters *alpha* and *beta*.
Requires alpha,beta \> 0,otherwise [domain\_error](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/error_handling.html#math_toolkit.error_handling.domain_error) is called. Note that technically the beta distribution is defined for alpha,beta \>= 0, but it's not clear whether any program can actually make use of that latitude or how many of the non-member functions can be usefully defined in that case. Therefore for now, we regard it as an error if alpha or beta is zero.
For example:
```
beta_distribution<> mybeta(2, 5);
```
Constructs a the beta distribution with alpha=2 and beta=5 (shown in yellow in the graph above).
###### [Parameter Accessors](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.parameter_accessors)
```
RealType alpha() const;
```
Returns the parameter *alpha* from which this distribution was constructed.
```
RealType beta() const;
```
Returns the parameter *beta* from which this distribution was constructed.
So for example:
```
beta_distribution<> mybeta(2, 5);
assert(mybeta.alpha() == 2.);
assert(mybeta.beta() == 5.);
```
##### [Parameter Estimators](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.parameter_estimators)
Two pairs of parameter estimators are provided.
One estimates either α \_\_space or β \_\_space from presumed-known mean and variance.
The other pair estimates either α \_\_space or β \_\_space from the cdf and x.
It is also possible to estimate α \_\_space and β \_\_space from 'known' mode & quantile. For example, calculators are provided by the [Pooled Prevalence Calculator](http://www.ausvet.com.au/pprev/content.php?page=PPscript) and [Beta Buster](http://www.epi.ucdavis.edu/diagnostictests/betabuster.html) but this is not yet implemented here.
```
static RealType find_alpha(
RealType mean,
RealType variance);
```
Returns the unique value of α that corresponds to a beta distribution with mean *mean* and variance *variance*.
```
static RealType find_beta(
RealType mean,
RealType variance);
```
Returns the unique value of β that corresponds to a beta distribution with mean *mean* and variance *variance*.
```
static RealType find_alpha(
RealType beta,
RealType x,
RealType probability);
```
Returns the value of α that gives: `cdf(beta_distribution<RealType>(alpha, beta), x) == probability`.
```
static RealType find_beta(
RealType alpha,
RealType x,
RealType probability);
```
Returns the value of β that gives: `cdf(beta_distribution<RealType>(alpha, beta), x) == probability`.
##### [Non-member Accessor Functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.non_member_accessor_functions)
All the [usual non-member accessor functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html "Non-Member Properties") that are generic to all distributions are supported: [Cumulative Distribution Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.cdf), [Probability Density Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.pdf), [Quantile](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.quantile), [Hazard Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.hazard), [Cumulative Hazard Function](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.chf), [mean](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.mean), [median](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.median), [mode](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.mode), [variance](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.variance), [standard deviation](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.sd), [skewness](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.skewness), [kurtosis](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.kurtosis), [kurtosis\_excess](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.kurtosis_excess), [range](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.range) and [support](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/nmp.html#math_toolkit.dist_ref.nmp.support).
The formulae for calculating these are shown in the table below, and at [Wolfram Mathworld](http://mathworld.wolfram.com/BetaDistribution.html).
##### [Applications](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.applications)
The beta distribution can be used to model events constrained to take place within an interval defined by a minimum and maximum value: so it is used in project management systems.
It is also widely used in [Bayesian statistical inference](http://en.wikipedia.org/wiki/Bayesian_inference).
##### [Related distributions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.related_distributions)
The beta distribution with both α \_\_space and β = 1 follows a [uniform distribution](http://en.wikipedia.org/wiki/Uniform_distribution_%28continuous%29).
The [triangular](http://en.wikipedia.org/wiki/Triangular_distribution) is used when less precise information is available.
The [binomial distribution](http://en.wikipedia.org/wiki/Binomial_distribution) is closely related when α \_\_space and β \_\_space are integers.
With integer values of α \_\_space and β \_\_space the distribution B(i, j) is that of the j-th highest of a sample of i + j + 1 independent random variables uniformly distributed between 0 and 1. The cumulative probability from 0 to x is thus the probability that the j-th highest value is less than x. Or it is the probability that at least i of the random variables are less than x, a probability given by summing over the [Binomial Distribution](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/binomial_dist.html "Binomial Distribution") with its p parameter set to x.
##### [Accuracy](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.accuracy)
This distribution is implemented using the [beta functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html "Beta") [beta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_function.html "Beta") and [incomplete beta functions](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions") [ibeta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions") and [ibetac](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions"); please refer to these functions for information on accuracy.
##### [Implementation](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.implementation)
In the following table *a* and *b* are the parameters α and β, *x* is the random variable, *p* is the probability and *q = 1-p*.
| Function | Implementation Notes |
|---|---|
| pdf | f(x;α,β) = xα - 1 (1 - x)β -1 / B(α, β) Implemented using [ibeta\_derivative](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/beta_derivative.html "Derivative of the Incomplete Beta Function")(a, b, x). |
| cdf | Using the incomplete beta function [ibeta](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions")(a, b, x) |
| cdf complement | [ibetac](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_function.html "Incomplete Beta Functions")(a, b, x) |
| quantile | Using the inverse incomplete beta function [ibeta\_inv](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses")(a, b, p) |
| quantile from the complement | [ibetac\_inv](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses")(a, b, q) |
| mean | `a/(a+b)` |
| variance | |
| mode | |
| skewness | |
| kurtosis excess |  |
| kurtosis | |
| parameter estimation | |
| alpha from mean and variance | |
| beta from mean and variance | |
| The member functions `find_alpha` and `find_beta` from cdf and probability x and **either** `alpha` or `beta` | Implemented in terms of the inverse incomplete beta functions [ibeta\_inva](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses"), and [ibeta\_invb](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/sf_beta/ibeta_inv_function.html "The Incomplete Beta Function Inverses") respectively. |
| `find_alpha` | |
| `find_beta` | |
##### [References](https://www.boost.org/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html#math_toolkit.dist_ref.dists.beta_dist.references)
[Wikipedia Beta distribution](http://en.wikipedia.org/wiki/Beta_distribution)
[NIST Exploratory Data Analysis](http://www.itl.nist.gov/div898/handbook/eda/section3/eda366h.htm)
[Wolfram MathWorld](http://mathworld.wolfram.com/BetaDistribution.html) |
| Shard | 76 (laksa) |
| Root Hash | 2177253573749532476 |
| Unparsed URL | org,boost!www,/doc/libs/1_63_0/libs/math/doc/html/math_toolkit/dist_ref/dists/beta_dist.html s443 |