Accelerating the pace of engineering and science

# Documentation

## Beta Distribution

### Definition

The beta pdf is

$y=f\left(x|a,b\right)=\frac{1}{B\left(a,b\right)}{x}^{a-1}{\left(1-x\right)}^{b-1}{I}_{\left(0,1\right)}\left(x\right)$

where B( · ) is the Beta function. The indicator function I(0,1)(x) ensures that only values of x in the range (0 1) have nonzero probability.

### Background

The beta distribution describes a family of curves that are unique in that they are nonzero only on the interval (0 1). A more general version of the function assigns parameters to the endpoints of the interval.

The beta cdf is the same as the incomplete beta function.

The beta distribution has a functional relationship with the t distribution. If Y is an observation from Student's t distribution with ν degrees of freedom, then the following transformation generates X, which is beta distributed.

$X=\frac{1}{2}+\frac{1}{2}\frac{Y}{\sqrt{\nu +{Y}^{2}}}$

If Y~t(v), then $X\sim \beta \left(\frac{\nu }{2},\frac{\nu }{2}\right)$

This relationship is used to compute values of the t cdf and inverse function as well as generating t distributed random numbers.

### Parameters

Suppose you are collecting data that has hard lower and upper bounds of zero and one respectively. Parameter estimation is the process of determining the parameters of the beta distribution that fit this data best in some sense.

One popular criterion of goodness is to maximize the likelihood function. The likelihood has the same form as the beta pdf. But for the pdf, the parameters are known constants and the variable is x. The likelihood function reverses the roles of the variables. Here, the sample values (the x's) are already observed. So they are the fixed constants. The variables are the unknown parameters. Maximum likelihood estimation (MLE) involves calculating the values of the parameters that give the highest likelihood given the particular set of data.

The function betafit returns the MLEs and confidence intervals for the parameters of the beta distribution. Here is an example using random numbers from the beta distribution with a = 5 andb = 0.2.

```rng default  % For reproducibility
r = betarnd(5,0.2,100,1);
[phat, pci] = betafit(r)
```
```phat =

7.4911    0.2135

pci =

5.0861    0.1744
11.0334    0.2614

```

The MLE for parameter a is 7.4911, compared to the true value of 5. The 95% confidence interval for a goes from 2.8051 to 6.2610, which does not include the true value. While this is an unlikely result, it does sometimes happen when estimating distribution parameters.

Similarly the MLE for parameter b is 0.2135, compared to the true value of 0.2. The 95% confidence interval for b goes from 0.1771 to 0.2832, which does include the true value. In this made-up example you know the "true value." In experimentation you do not.

### Example

The shape of the beta distribution is quite variable depending on the values of the parameters, as illustrated by the plot below.

```X = 0:.01:1;
y1 = betapdf(X,0.75,0.75);
y2 = betapdf(X,1,1);
y3 = betapdf(X,4,4);

figure
plot(X,y1,'Color','r','LineWidth',2)
hold on
plot(X,y2,'LineStyle','-.','Color','b','LineWidth',2)
plot(X,y3,'LineStyle',':','Color','g','LineWidth',2)
legend({'a = b = 0.75','a = b = 1','a = b = 4'},'Location','NorthEast');
hold off
```

The constant pdf (the flat line) shows that the standard uniform distribution is a special case of the beta distribution, which occurs when a = b = 1.