Click or drag to resize
Accord.NET (logo)

BetaDistribution Class

Beta Distribution (of the first kind).
Inheritance Hierarchy
SystemObject
  Accord.Statistics.DistributionsDistributionBase
    Accord.Statistics.Distributions.UnivariateUnivariateContinuousDistribution
      Accord.Statistics.Distributions.UnivariateBetaDistribution

Namespace:  Accord.Statistics.Distributions.Univariate
Assembly:  Accord.Statistics (in Accord.Statistics.dll) Version: 3.8.0
Syntax
[SerializableAttribute]
public class BetaDistribution : UnivariateContinuousDistribution, 
	IFormattable, IFittableDistribution<double, BetaOptions>, IFittable<double, BetaOptions>, 
	IFittable<double>, IFittableDistribution<double>, IDistribution<double>, 
	IDistribution, ICloneable, ISampleableDistribution<double>, IRandomNumberGenerator<double>
Request Example View Source

The BetaDistribution type exposes the following members.

Constructors
  NameDescription
Public methodBetaDistribution
Creates a new Beta distribution.
Public methodBetaDistribution(Int32, Int32)
Creates a new Beta distribution.
Public methodBetaDistribution(Double, Double)
Creates a new Beta distribution.
Top
Properties
  NameDescription
Public propertyAlpha
Gets the shape parameter α (alpha)
Public propertyBeta
Gets the shape parameter β (beta).
Public propertyEntropy
Gets the entropy for this distribution.
(Overrides UnivariateContinuousDistributionEntropy.)
Public propertyMean
Gets the mean for this distribution.
(Overrides UnivariateContinuousDistributionMean.)
Public propertyMedian
Gets the median for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertyMode
Gets the mode for this distribution.
(Overrides UnivariateContinuousDistributionMode.)
Public propertyQuartiles
Gets the Quartiles for this distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertyStandardDeviation
Gets the Standard Deviation (the square root of the variance) for the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public propertySuccesses
Gets the number of successes r.
Public propertySupport
Gets the support interval for this distribution.
(Overrides UnivariateContinuousDistributionSupport.)
Public propertyTrials
Gets the number of trials n.
Public propertyVariance
Gets the variance for this distribution.
(Overrides UnivariateContinuousDistributionVariance.)
Top
Methods
  NameDescription
Public methodClone
Creates a new object that is a copy of the current instance.
(Overrides DistributionBaseClone.)
Public methodComplementaryDistributionFunction
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point x. This function is also known as the Survival function.
(Inherited from UnivariateContinuousDistribution.)
Public methodCumulativeHazardFunction
Gets the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodDistributionFunction(Double)
Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodDistributionFunction(Double, Double)
Gets the cumulative distribution function (cdf) for this distribution in the semi-closed interval (a; b] given as P(a < X ≤ b).
(Inherited from UnivariateContinuousDistribution.)
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Public methodStatic memberEstimate(Double)
Estimates a new Beta distribution from a set of observations.
Public methodStatic memberEstimate(Double, BetaOptions)
Estimates a new Beta distribution from a set of observations.
Public methodStatic memberEstimate(Double, Double)
Estimates a new Beta distribution from a set of weighted observations.
Public methodStatic memberEstimate(Double, Double, BetaOptions)
Estimates a new Beta distribution from a set of weighted observations.
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodCode exampleFit(Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, Double)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodCode exampleFit(Double, Int32)
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)
Public methodFit(Double, Double, BetaOptions)
Fits the underlying distribution to a given set of observations.
Public methodFit(Double, Double, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateContinuousDistributionFit(Double, Double, IFittingOptions).)
Public methodFit(Double, Int32, BetaOptions)
Fits the underlying distribution to a given set of observations.
Public methodFit(Double, Int32, IFittingOptions)
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateContinuousDistributionFit(Double, Int32, IFittingOptions).)
Public methodGenerate
Generates a random observation from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Random)
Generates a random observation from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Random).)
Public methodGenerate(Int32)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Double)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Random)
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)
Public methodGenerate(Int32, Double, Random)
Generates a random vector of observations from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Int32, Double, Random).)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetRange
Gets the distribution range within a given percentile.
(Inherited from UnivariateContinuousDistribution.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Public methodStatic memberGradient(Double, Double, Double)
Computes the Gradient of the Log-Likelihood function for estimating Beta distributions.
Public methodStatic memberGradient(Double, Double, Double, Double, Double, Double)
Computes the Gradient of the Log-Likelihood function for estimating Beta distributions.
Public methodHazardFunction
Gets the hazard function, also known as the failure rate or the conditional failure density function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Protected methodInnerComplementaryDistributionFunction
Gets the complementary cumulative distribution function (ccdf) for this distribution evaluated at point x. This function is also known as the Survival function.
(Inherited from UnivariateContinuousDistribution.)
Protected methodInnerDistributionFunction
Gets the cumulative distribution function (cdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerDistributionFunction(Double).)
Protected methodInnerInverseDistributionFunction
Gets the inverse of the cumulative distribution function (icdf) for this distribution evaluated at probability p. This function is also known as the Quantile function.
(Overrides UnivariateContinuousDistributionInnerInverseDistributionFunction(Double).)
Protected methodInnerLogProbabilityDensityFunction
Gets the log-probability density function (pdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerLogProbabilityDensityFunction(Double).)
Protected methodInnerProbabilityDensityFunction
Gets the probability density function (pdf) for this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionInnerProbabilityDensityFunction(Double).)
Public methodInverseDistributionFunction
Gets the inverse of the cumulative distribution function (icdf) for this distribution evaluated at probability p. This function is also known as the Quantile function.
(Inherited from UnivariateContinuousDistribution.)
Public methodLogCumulativeHazardFunction
Gets the log of the cumulative hazard function for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberLogLikelihood(Double, Double, Double)
Computes the Log-Likelihood function for estimating Beta distributions.
Public methodStatic memberLogLikelihood(Double, Double, Double, Double, Double)
Computes the Log-Likelihood function for estimating Beta distributions.
Public methodLogProbabilityDensityFunction
Gets the log-probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodProbabilityDensityFunction
Gets the probability density function (pdf) for this distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)
Public methodQuantileDensityFunction
Gets the first derivative of the inverse distribution function (icdf) for this distribution evaluated at probability p.
(Inherited from UnivariateContinuousDistribution.)
Public methodStatic memberRandom(Double, Double)
Generates a random observation from the Beta distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Int32)
Generates a random vector of observations from the Beta distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Random)
Generates a random observation from the Beta distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Int32, Double)
Generates a random vector of observations from the Beta distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Int32, Random)
Generates a random vector of observations from the Beta distribution with the given parameters.
Public methodStatic memberRandom(Double, Double, Int32, Double, Random)
Generates a random vector of observations from the Beta distribution with the given parameters.
Public methodToString
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(IFormatProvider)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String)
Returns a String that represents this instance.
(Inherited from DistributionBase.)
Public methodToString(String, IFormatProvider)
Returns a String that represents this instance.
(Overrides DistributionBaseToString(String, IFormatProvider).)
Top
Extension Methods
  NameDescription
Public Extension MethodHasMethod
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)
Public Extension MethodIsEqual
Compares two objects for equality, performing an elementwise comparison if the elements are vectors or matrices.
(Defined by Matrix.)
Public Extension MethodTo(Type)Overloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Public Extension MethodToTOverloaded.
Converts an object into another type, irrespective of whether the conversion can be done at compile time or not. This can be used to convert generic types to numeric types during runtime.
(Defined by ExtensionMethods.)
Top
Remarks

The beta distribution is a family of continuous probability distributions defined on the interval (0, 1) parameterized by two positive shape parameters, typically denoted by α and β. The beta distribution can be suited to the statistical modeling of proportions in applications where values of proportions equal to 0 or 1 do not occur. One theoretical case where the beta distribution arises is as the distribution of the ratio formed by one random variable having a Gamma distribution divided by the sum of it and another independent random variable also having a Gamma distribution with the same scale parameter (but possibly different shape parameter).

References:

Examples

Note: More advanced examples, including distribution estimation and random number generation are also available at the GeneralizedBetaDistribution page.

The following example shows how to instantiate and use a Beta distribution given its alpha and beta parameters:

double alpha = 0.42;
double beta = 1.57;

// Create a new Beta distribution with α = 0.42 and β = 1.57
BetaDistribution distribution = new BetaDistribution(alpha, beta);

// Common measures
double mean   = distribution.Mean;      // 0.21105527638190955
double median = distribution.Median;    // 0.11577711097114812
double var    = distribution.Variance;  // 0.055689279830523512

// Cumulative distribution functions
double cdf    = distribution.DistributionFunction(x: 0.27);          // 0.69358638272337991
double ccdf   = distribution.ComplementaryDistributionFunction(x: 0.27); // 0.30641361727662009
double icdf   = distribution.InverseDistributionFunction(p: cdf);        // 0.26999999068687469

// Probability density functions
double pdf    = distribution.ProbabilityDensityFunction(x: 0.27);    // 0.94644031936694828
double lpdf   = distribution.LogProbabilityDensityFunction(x: 0.27); // -0.055047364344046057

// Hazard (failure rate) functions
double hf     = distribution.HazardFunction(x: 0.27);           // 3.0887671630877072
double chf    = distribution.CumulativeHazardFunction(x: 0.27); // 1.1828193992944409

// String representation
string str = distribution.ToString(); // B(x; α = 0.42, β = 1.57)

The following example shows to create a Beta distribution given a discrete number of trials and the number of successes within those trials. It also shows how to compute the 2.5 and 97.5 percentiles of the distribution:

int trials = 100;
int successes = 78;

BetaDistribution distribution = new BetaDistribution(successes, trials);

double mean   = distribution.Mean; // 0.77450980392156865
double median = distribution.Median; // 0.77630912598534851

double p025   = distribution.InverseDistributionFunction(p: 0.025); // 0.68899653915764347
double p975   = distribution.InverseDistributionFunction(p: 0.975); // 0.84983461640764513

The next example shows how to generate 1000 new samples from a Beta distribution:

// Using the distribution's parameters
double[] samples = GeneralizedBetaDistribution
  .Random(alpha: 2, beta: 3, min: 0, max: 1, samples: 1000);

// Using an existing distribution
var b = new GeneralizedBetaDistribution(alpha: 1, beta: 2);
double[] new_samples = b.Generate(1000);

And finally, how to estimate the parameters of a Beta distribution from a set of observations, using either the Method-of-moments or the Maximum Likelihood Estimate.

// Draw 100000 observations from a Beta with α = 2, β = 3:
double[] samples = GeneralizedBetaDistribution
    .Random(alpha: 2, beta: 3, samples: 100000);

// Estimate a distribution from the data
var B = BetaDistribution.Estimate(samples);

// Explicitly using Method-of-moments estimation
var mm = BetaDistribution.Estimate(samples,
    new BetaOptions { Method = BetaEstimationMethod.Moments });

// Explicitly using Maximum Likelihood estimation
var mle = BetaDistribution.Estimate(samples,
    new BetaOptions { Method = BetaEstimationMethod.MaximumLikelihood });
See Also