Categories &

Functions List

Class Definition: BetaDistribution

statistics: BetaDistribution

Beta probability distribution object.

A BetaDistribution object consists of parameters, a model description, and sample data for a beta probability distribution.

The beta distribution is a family of continuous probability distributions defined on the interval [0, 1] in terms of two positive parameters, denoted by alpha (a) and beta (b), that appear as exponents of the variable and its complement to 1, respectively, and control the shape of the distribution.

There are several ways to create a BetaDistribution object.

  • Fit a distribution to data using the fitdist function.
  • Create a distribution with specified parameter values using the makedist function.
  • Use the constructor BetaDistribution (a, b) to create a beta distribution with specified parameter values.
  • Use the static method BetaDistribution.fit (x, censor, freq, options) to a distribution to data x.

It is highly recommended to use fitdist and makedist functions to create probability distribution objects, instead of the constructor and the aforementioned static method.

Further information about the Beta distribution can be found at https://en.wikipedia.org/wiki/Beta_distribution

See also: fitdist, makedist, betacdf, betainv, betapdf, betarnd, lognfit, betalike, betastat

Source Code: BetaDistribution

Properties

First shape parameter

A positive scalar value characterizing the shape of the beta distribution. You can access the a property using dot name assignment.

Example: 1

 

 ## Create a beta distribution with default parameters
 pd = makedist ("beta")

 ## Query parameter 'alpha'
 pd.a

 ## Set parameter 'alpha'
 pd.a = 2

pd =
  BetaDistribution

  beta distribution
        a = 1
        b = 1

ans = 1
pd =
  BetaDistribution

  beta distribution
        a = 2
        b = 1

                    

Example: 2

 

 ## Create a beta distribution object by calling its constructor
 pd = BetaDistribution (2, 3)

 ## Query parameter 'alpha'
 pd.a

pd =
  BetaDistribution

  beta distribution
        a = 2
        b = 3

ans = 2
                    

Second shape parameter

A positive scalar value characterizing the shape of the beta distribution. You can access the a property using dot name assignment.

Example: 1

 

 ## Create a beta distribution with default parameters
 pd = makedist ("beta")

 ## Query parameter 'beta'
 pd.b

 ## Set parameter 'beta'
 pd.b = 2

pd =
  BetaDistribution

  beta distribution
        a = 1
        b = 1

ans = 1
pd =
  BetaDistribution

  beta distribution
        a = 1
        b = 2

                    

Example: 2

 

 ## Create a beta distribution object by calling its constructor
 pd = BetaDistribution (2, 3)

 ## Query parameter 'beta'
 pd.b

pd =
  BetaDistribution

  beta distribution
        a = 2
        b = 3

ans = 3
                    

Probability distribution name

A character vector specifying the name of the probability distribution object. This property is read-only.

Number of parameters

A scalar integer value specifying the number of parameters characterizing the probability distribution. This property is read-only.

Names of parameters

A 2×1 cell array of character vectors with each element containing the name of a distribution parameter. This property is read-only.

Description of parameters

A 2×1 cell array of character vectors with each element containing a short description of a distribution parameter. This property is read-only.

Distribution parameter values

A 2×1 numeric vector containing the values of the distribution parameters. This property is read-only. You can change the distribution parameters by assigning new values to the a and b properties.

Covariance matrix of the parameter estimates

A 2×2 numeric matrix containing the variance-covariance of the parameter estimates. Diagonal elements contain the variance of each estimated parameter and non-diagonal elements contain the covariance between the parameter estimates. The covariance matrix is only meaningful when the distribution was fitted to data. If the distribution object was created with fixed parameters, or a parameter of a fitted distribution is modified, then all elements of the variance-covariance are zero. This property is read-only.

Example: 1

 

 ## Generate a data set of 5000 random samples from a Beta distribution with
 ## parameters a = 2 and b = 4.  Fit a Beta distribution to this data and plot
 ## a PDF of the fitted distribution superimposed on a histogram of the data

 pd = makedist ("Beta", "a", 2, "b", 4)
 randg ("seed", 21);
 data = random (pd, 5000, 1);
 pd = fitdist (data, "Beta")
 plot (pd)
 title (sprintf ("Fitted Beta distribution with a = %0.2f and b = %0.2f", ...
                 pd.a, pd.b))
 pd.ParameterCovariance

pd =
  BetaDistribution

  beta distribution
        a = 2
        b = 4

pd =
  BetaDistribution

  beta distribution
        a = 1.97369   [1.90215, 2.04792]
        b = 3.91487   [3.76164, 4.07435]

ans =

   1.3822e-03   2.4731e-03
   2.4731e-03   6.3606e-03

                    
plotted figure

Flag for fixed parameters

A 1×2 logical vector specifying which parameters are fixed and which are estimated. true values correspond to fixed parameters, false values correspond to parameter estimates. This property is read-only.

Truncation interval

A 1×2 numeric vector specifying the truncation interval for the probability distribution. First element contains the lower boundary, second element contains the upper boundary. This property is read-only. You can only truncate a probability distribution with the truncate method.

Flag for truncated probability distribution

A logical scalar value specifying whether a probability distribution is truncated or not. This property is read-only.

Data used for fitting a probability distribution

A scalar structure containing the following fields:

  • data : a numeric vector containing the data used for distribution fitting.
  • cens : an empty array, since BetaDistribution does not allow censoring.
  • frequency : a numeric vector of non-negative integer values containing the frequency information corresponding to the elements of the data used for distribution fitting. If no frequency vector was used for distribution fitting, then this field defaults to an empty array.

Methods

BetaDistribution: p = cdf (pd, x)
BetaDistribution: p = cdf (pd, x, "upper")

Compute the cumulative distribution function (CDF).

p = cdf (pd, x) computes the CDF of the probability distribution object, pd, evaluated at the values in x.

p = cdf (…, "upper") returns the complement of the CDF of the probability distribution object, pd, evaluated at the values in x.

BetaDistribution: p = icdf (pd, p)

Compute the inverse cumulative distribution function (iCDF).

p = icdf (pd, x) computes the quantile (the inverse of the CDF) of the probability distribution object, pd, evaluated at the values in x.

BetaDistribution: r = iqr (pd)

Compute the interquartile range of a probability distribution.

r = iqr (pd) computes the interquartile range of the probability distribution object, pd.

BetaDistribution: m = mean (pd)

Compute the mean of a probability distribution.

m = mean (pd) computes the mean of the probability distribution object, pd.

BetaDistribution: m = median (pd)

Compute the median of a probability distribution.

m = median (pd) computes the median of the probability distribution object, pd.

BetaDistribution: nlogL = negloglik (pd)

Compute the negative loglikelihood of a probability distribution.

m = negloglik (pd) computes the negative loglikelihood of the probability distribution object, pd.

BetaDistribution: ci = paramci (pd)
BetaDistribution: ci = paramci (pd, Name, Value)

Compute the confidence intervals for probability distribution parameters.

ci = paramci (pd) computes the lower and upper boundaries of the 95% confidence interval for each parameter of the probability distribution object, pd.

ci = paramci (pd, Name, Value) computes the confidence intervals with additional options specified specified by Name-Value pair arguments listed below.

NameValue
"Alpha"A scalar value in the range (0,1) specifying the significance level for the confidence interval. The default value 0.05 corresponds to a 95% confidence interval.
"Parameter"A character vector or a cell array of character vectors specifying the parameter names for which to compute confidence intervals. By default, paramci computes confidence intervals for all distribution parameters.

paramci is meaningful only when pd is fitted to data, otherwise an empty array, [], is returned.

BetaDistribution: y = pdf (pd, x)

Compute the probability distribution function (PDF).

y = pdf (pd, x) computes the PDF of the probability distribution object, pd, evaluated at the values in x.

BetaDistribution: plot (pd)
BetaDistribution: plot (pd, Name, Value)
BetaDistribution: h = plot (…)

Plot a probability distribution object.

plot (pd plots a probability density function (PDF) of the probability distribution object pd. If pd contains data, which have been fitted by fitdist, the PDF is superimposed over a histogram of the data.

plot (pd, Name, Value) specifies additional options with the Name-Value pair arguments listed below.

NameValue
"PlotType"A character vector specifying the plot type. "pdf" plots the probability density function (PDF). When pd is fit to data, the PDF is superimposed on a histogram of the data. "cdf" plots the cumulative density function (CDF). When pd is fit to data, the CDF is superimposed over an empirical CDF. "probability" plots a probability plot using a CDF of the data and a CDF of the fitted probability distribution. This option is available only when pd is fitted to data.
"Discrete"A logical scalar to specify whether to plot the PDF or CDF of a discrete distribution object as a line plot or a stem plot, by specifying false or true, respectively. By default, it is true for discrete distributions and false for continuous distributions. When pd is a continuous distribution object, option is ignored.
"Parent"An axes graphics object for plot. If not specified, the plot function plots into the current axes or creates a new axes object if one does not exist.

h = plot (…) returns a graphics handle to the plotted objects.

Example: 1

 

 ## Generate a data set of 100 random samples from a Beta distribution with
 ## parameters a = 2 and b = 4.  Fit a Beta distribution to this data and plot
 ## its CDF superimposed over an empirical CDF of the data

 pd = makedist ("Beta", "a", 2, "b", 4)
 randg ("seed", 21);
 data = random (pd, 100, 1);
 pd = fitdist (data, "Beta")
 plot (pd, "plottype", "cdf")
 title (sprintf ("Fitted Beta distribution with a = %0.2f and b = %0.2f", ...
                 pd.a, pd.b))
 legend ({"empirical CDF", "fitted CDF"}, "location", "east")

pd =
  BetaDistribution

  beta distribution
        a = 2
        b = 4

pd =
  BetaDistribution

  beta distribution
        a = 1.58844   [1.2184, 2.07086]
        b =  3.3298   [2.43615, 4.55126]

                    
plotted figure

Example: 2

 

 ## Generate a data set of 200 random samples from a Beta distribution with
 ## parameters a = 2 and b = 4.  Display a probability plot for the Beta
 ## distribution fit to the data.

 pd = makedist ("Beta", "a", 2, "b", 4)
 randg ("seed", 21);
 data = random (pd, 200, 1);
 pd = fitdist (data, "Beta")
 plot (pd, "plottype", "probability")
 title (sprintf ("Probability plot of a fitted Beta distribution with a = %0.2f and b = %0.2f", ...
                 pd.a, pd.b))
 legend ({"empirical CDF", "fitted CDF"}, "location", "southeast")

pd =
  BetaDistribution

  beta distribution
        a = 2
        b = 4

pd =
  BetaDistribution

  beta distribution
        a = 1.68235   [1.42401, 1.98756]
        b =  3.7591   [3.1139, 4.53798]

                    
plotted figure

BetaDistribution: [nlogL, param] = proflik (pd, pnum)
BetaDistribution: [nlogL, param] = proflik (pd, pnum, "Display", display)
BetaDistribution: [nlogL, param] = proflik (pd, pnum, setparam)
BetaDistribution: [nlogL, param] = proflik (pd, pnum, setparam, "Display", display)

Profile likelihood function for a probability distribution object.

[nlogL, param] = proflik (pd, pnum) returns a vector nlogL of negative loglikelihood values and a vector param of corresponding parameter values for the parameter in the position indicated by pnum. By default, proflik uses the lower and upper bounds of the 95% confidence interval and computes 100 equispaced values for the selected parameter. pd must be fitted to data.

[nlogL, param] = proflik (pd, pnum, "Display", "on") also plots the profile likelihood against the default range of the selected parameter.

[nlogL, param] = proflik (pd, pnum, setparam) defines a user-defined range of the selected parameter.

[nlogL, param] = proflik (pd, pnum, setparam, "Display", "on") also plots the profile likelihood against the user-defined range of the selected parameter.

For the beta distribution, pnum = 1 selects the parameter a and pnum = 2 selects the parameter b.

When opted to display the profile likelihood plot, proflik also plots the baseline loglikelihood computed at the lower bound of the 95% confidence interval and estimated maximum likelihood. The latter might not be observable if it is outside of the used-defined range of parameter values.

BetaDistribution: y = random (pd)
BetaDistribution: y = random (pd, rows)
BetaDistribution: y = random (pd, rows, cols, …)
BetaDistribution: y = random (pd, [sz])

Generate random arrays from the probability distribution object.

r = random (pd) returns a random number from the distribution object pd.

When called with a single size argument, betarnd returns a square matrix with the dimension specified. When called with more than one scalar argument, the first two arguments are taken as the number of rows and columns and any further arguments specify additional matrix dimensions. The size may also be specified with a row vector of dimensions, sz.

BetaDistribution: s = std (pd)

Compute the standard deviation of a probability distribution.

s = std (pd) computes the standard deviation of the probability distribution object, pd.

BetaDistribution: t = truncate (pd, lower, upper)

Truncate a probability distribution.

t = truncate (pd) returns a probability distribution t, which is the probability distribution pd truncated to the specified interval with lower limit, lower, and upper limit, upper. If pd is fitted to data with fitdist, the returned probability distribution t is not fitted, does not contain any data or estimated values, and it is as it has been created with the makedist function, but it includes the truncation interval.

Example: 1

 

 ## Plot the PDF of a Beta distribution, with parameters a = 2 and b = 4,
 ## truncated at [0.1, 0.8] intervals.  Generate 10000 random samples from
 ## this truncated distribution and superimpose a histogram with 100 bins
 ## scaled accordingly

 pd = makedist ("Beta", "a", 2, "b", 4)
 t = truncate (pd, 0.1, 0.8)
 randg ("seed", 21);
 data = random (t, 10000, 1);
 plot (t)
 title ("Beta distribution (a = 2, b = 4) truncated at [0.1, 0.8]")
 hold on
 hist (data, 100, 140)
 hold off

pd =
  BetaDistribution

  beta distribution
        a = 2
        b = 4

t =
  BetaDistribution

  beta distribution
        a = 2
        b = 4
  Truncated to the interval [0.1, 0.8]

                    
plotted figure

BetaDistribution: v = var (pd)

Compute the variance of a probability distribution.

v = var (pd) computes the standard deviation of the probability distribution object, pd.