BetaDistribution Class 
Namespace: Accord.Statistics.Distributions.Univariate
[SerializableAttribute] public class BetaDistribution : UnivariateContinuousDistribution, IFormattable, IFittableDistribution<double, BetaOptions>, IFittable<double, BetaOptions>, IFittable<double>, IFittableDistribution<double>, IDistribution<double>, IDistribution, ICloneable, ISampleableDistribution<double>, IRandomNumberGenerator<double>
The BetaDistribution type exposes the following members.
Name  Description  

BetaDistribution 
Creates a new Beta distribution.
 
BetaDistribution(Int32, Int32) 
Creates a new Beta distribution.
 
BetaDistribution(Double, Double) 
Creates a new Beta distribution.

Name  Description  

Alpha 
Gets the shape parameter α (alpha)
 
Beta 
Gets the shape parameter β (beta).
 
Entropy 
Gets the entropy for this distribution.
(Overrides UnivariateContinuousDistributionEntropy.)  
Mean 
Gets the mean for this distribution.
(Overrides UnivariateContinuousDistributionMean.)  
Median 
Gets the median for this distribution.
(Inherited from UnivariateContinuousDistribution.)  
Mode 
Gets the mode for this distribution.
(Overrides UnivariateContinuousDistributionMode.)  
Quartiles 
Gets the Quartiles for this distribution.
(Inherited from UnivariateContinuousDistribution.)  
StandardDeviation 
Gets the Standard Deviation (the square root of
the variance) for the current distribution.
(Inherited from UnivariateContinuousDistribution.)  
Successes 
Gets the number of successes r.
 
Support 
Gets the support interval for this distribution.
(Overrides UnivariateContinuousDistributionSupport.)  
Trials 
Gets the number of trials n.
 
Variance 
Gets the variance for this distribution.
(Overrides UnivariateContinuousDistributionVariance.) 
Name  Description  

Clone 
Creates a new object that is a copy of the current instance.
(Overrides DistributionBaseClone.)  
ComplementaryDistributionFunction 
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.)  
CumulativeHazardFunction 
Gets the cumulative hazard function for this
distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)  
DistributionFunction(Double) 
Gets the cumulative distribution function (cdf) for
this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionDistributionFunction(Double).)  
DistributionFunction(Double, Double) 
Gets the cumulative distribution function (cdf) for this
distribution in the semiclosed interval (a; b] given as
P(a < X ≤ b).
(Inherited from UnivariateContinuousDistribution.)  
Equals  Determines whether the specified object is equal to the current object. (Inherited from Object.)  
Estimate(Double) 
Estimates a new Beta distribution from a set of observations.
 
Estimate(Double, BetaOptions) 
Estimates a new Beta distribution from a set of observations.
 
Estimate(Double, Double) 
Estimates a new Beta distribution from a set of weighted observations.
 
Estimate(Double, Double, BetaOptions) 
Estimates a new Beta distribution from a set of weighted observations.
 
Finalize  Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)  
Fit(Double) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, IFittingOptions) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, Double) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, Int32) 
Fits the underlying distribution to a given set of observations.
(Inherited from UnivariateContinuousDistribution.)  
Fit(Double, Double, BetaOptions) 
Fits the underlying distribution to a given set of observations.
 
Fit(Double, Double, IFittingOptions) 
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateContinuousDistributionFit(Double, Double, IFittingOptions).)  
Fit(Double, Int32, BetaOptions) 
Fits the underlying distribution to a given set of observations.
 
Fit(Double, Int32, IFittingOptions) 
Fits the underlying distribution to a given set of observations.
(Overrides UnivariateContinuousDistributionFit(Double, Int32, IFittingOptions).)  
Generate 
Generates a random observation from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate.)  
Generate(Int32) 
Generates a random vector of observations from the current distribution.
(Inherited from UnivariateContinuousDistribution.)  
Generate(Int32, Double) 
Generates a random vector of observations from the current distribution.
(Overrides UnivariateContinuousDistributionGenerate(Int32, Double).)  
GetHashCode  Serves as the default hash function. (Inherited from Object.)  
GetRange 
Gets the distribution range within a given percentile.
(Inherited from UnivariateContinuousDistribution.)  
GetType  Gets the Type of the current instance. (Inherited from Object.)  
Gradient(Double, Double, Double) 
Computes the Gradient of the LogLikelihood function for estimating Beta distributions.
 
Gradient(Double, Double, Double, Double, Double, Double) 
Computes the Gradient of the LogLikelihood function for estimating Beta distributions.
 
HazardFunction 
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.)  
InverseDistributionFunction 
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 UnivariateContinuousDistributionInverseDistributionFunction(Double).)  
LogCumulativeHazardFunction 
Gets the log of the cumulative hazard function for this
distribution evaluated at point x.
(Inherited from UnivariateContinuousDistribution.)  
LogLikelihood(Double, Double, Double) 
Computes the LogLikelihood function for estimating Beta distributions.
 
LogLikelihood(Double, Double, Double, Double, Double) 
Computes the LogLikelihood function for estimating Beta distributions.
 
LogProbabilityDensityFunction 
Gets the logprobability density function (pdf) for
this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionLogProbabilityDensityFunction(Double).)  
MemberwiseClone  Creates a shallow copy of the current Object. (Inherited from Object.)  
ProbabilityDensityFunction 
Gets the probability density function (pdf) for
this distribution evaluated at point x.
(Overrides UnivariateContinuousDistributionProbabilityDensityFunction(Double).)  
QuantileDensityFunction 
Gets the first derivative of the
inverse distribution function (icdf) for this distribution evaluated
at probability p.
(Inherited from UnivariateContinuousDistribution.)  
Random(Double, Double) 
Generates a random observation from the
Beta distribution with the given parameters.
 
Random(Double, Double, Int32) 
Generates a random vector of observations from the
Beta distribution with the given parameters.
 
Random(Double, Double, Int32, Double) 
Generates a random vector of observations from the
Beta distribution with the given parameters.
 
ToString 
Returns a String that represents this instance.
(Inherited from DistributionBase.)  
ToString(IFormatProvider) 
Returns a String that represents this instance.
(Inherited from DistributionBase.)  
ToString(String) 
Returns a String that represents this instance.
(Inherited from DistributionBase.)  
ToString(String, IFormatProvider) 
Returns a String that represents this instance.
(Overrides DistributionBaseToString(String, IFormatProvider).) 
Name  Description  

HasMethod 
Checks whether an object implements a method with the given name.
(Defined by ExtensionMethods.)  
ToT  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.)  
ToT  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 Matrix.) 
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:
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 Methodofmoments 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 Methodofmoments 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 });