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 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.
fitdist
function.
makedist
function.
BetaDistribution (a, b)
to create a beta distribution with fixed parameter values a
and b
.
BetaDistribution.fit (x,
alpha, freq, options)
to fit a distribution to data
x
using the same input arguments as the betafit
function.
It is highly recommended to use fitdist
and makedist
functions to create probability distribution objects, instead of the class
constructor or 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, betafit, betalike, betastat
Source Code: BetaDistribution
A positive scalar value characterizing the shape of the beta
distribution. You can access the a
property using dot name
assignment.
## Create a beta distribution with default parameters pd = makedist ("Beta") ## Query parameter 'alpha' (first shape parameter) pd.a ## Set parameter 'alpha' pd.a = 2 ## Use this to initialize or modify the first shape parameter of a beta ## distribution. The parameter 'alpha' must be a positive real scalar. pd = BetaDistribution beta distribution a = 1 b = 1 ans = 1 pd = BetaDistribution beta distribution a = 2 b = 1 |
## 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 |
A positive scalar value characterizing the shape of the beta
distribution. You can access the b
property using dot name
assignment.
## Create a beta distribution with default parameters pd = makedist ("Beta") ## Query parameter 'beta' (second shape parameter) pd.b ## Set parameter 'beta' pd.b = 2 ## Use this to initialize or modify the second shape parameter of a beta ## distribution. The parameter 'beta' must be a positive real scalar. pd = BetaDistribution beta distribution a = 1 b = 1 ans = 1 pd = BetaDistribution beta distribution a = 1 b = 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 |
A character vector specifying the name of the probability distribution object. This property is read-only.
A scalar integer value specifying the number of parameters characterizing the probability distribution. This property is read-only.
A cell array of character vectors with each element containing the name of a distribution parameter. This property is read-only.
A cell array of character vectors with each element containing a short description of a distribution parameter. This property is read-only.
A 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.
A 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.
A 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.
A 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.
A logical scalar value specifying whether a probability distribution is truncated or not. This property is read-only.
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.
"upper"
)
p = cdf (pd, x)
computes the CDF of the
probability distribution object, pd, evaluated at the values in
x.
p = cdf (…,
returns the complement of
the CDF of the probability distribution object, pd, evaluated at
the values in x.
"upper"
)
## Plot various CDFs from the Beta distribution x = 0:0.01:1; pd1 = makedist ("Beta", "a", 0.5, "b", 0.5); pd2 = makedist ("Beta", "a", 2, "b", 2); pd3 = makedist ("Beta", "a", 5, "b", 2); p1 = cdf (pd1, x); p2 = cdf (pd2, x); p3 = cdf (pd3, x); plot (x, p1, "-b", x, p2, "-g", x, p3, "-r") grid on legend ({"a = 0.5, b = 0.5", "a = 2, b = 2", "a = 5, b = 2"}, ... "location", "southeast") title ("Beta CDF") xlabel ("Value") ylabel ("Cumulative probability") ## Use this to compute and visualize the cumulative distribution function ## for different beta distributions, showing how probability accumulates ## over the interval [0, 1]. |
x = icdf (pd, p)
computes the quantile (the
inverse of the CDF) of the probability distribution object, pd,
evaluated at the values in p.
## Plot various iCDFs from the Beta distribution p = 0.001:0.001:0.999; pd1 = makedist ("Beta", "a", 0.5, "b", 0.5); pd2 = makedist ("Beta", "a", 2, "b", 2); pd3 = makedist ("Beta", "a", 5, "b", 2); x1 = icdf (pd1, p); x2 = icdf (pd2, p); x3 = icdf (pd3, p); plot (p, x1, "-b", p, x2, "-g", p, x3, "-r") grid on legend ({"a = 0.5, b = 0.5", "a = 2, b = 2", "a = 5, b = 2"}, ... "location", "northwest") title ("Beta iCDF") xlabel ("Probability") ylabel ("Value") ## This demonstrates the inverse CDF (quantiles) for beta distributions, ## useful for finding values corresponding to given probabilities. |
r = iqr (pd)
computes the interquartile range of the
probability distribution object, pd.
## Compute the interquartile range for a Beta distribution pd = makedist ("Beta", "a", 2, "b", 5) iqr_value = iqr (pd) ## Use this to calculate the interquartile range, which measures the spread ## of the middle 50% of the beta distribution. pd = BetaDistribution beta distribution a = 2 b = 5 iqr_value = 0.2283 |
m = mean (pd)
computes the mean of the probability
distribution object, pd.
## Compute the mean for different Beta distributions pd1 = makedist ("Beta", "a", 1, "b", 1); pd2 = makedist ("Beta", "a", 2, "b", 5); mean1 = mean (pd1) mean2 = mean (pd2) ## This shows how to compute the expected value of beta distributions with ## different shape parameters, representing the average outcome. mean1 = 0.5000 mean2 = 0.2857 |
m = median (pd)
computes the median of the probability
distribution object, pd.
## Compute the median for different Beta distributions pd1 = makedist ("Beta", "a", 1, "b", 1); pd2 = makedist ("Beta", "a", 2, "b", 5); median1 = median (pd1) median2 = median (pd2) ## Use this to find the median value, which splits the beta distribution ## into two equal probability halves. median1 = 0.5000 median2 = 0.2644 |
nlogL = negloglik (pd)
computes the negative loglikelihood
of the probability distribution object, pd.
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 by
Name-Value
pair arguments listed below.
Name | Value | |
---|---|---|
"Alpha" | A scalar value in the range 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.
## Compute confidence intervals for parameters of a fitted Beta distribution pd = makedist ("Beta", "a", 2, "b", 5) rand ("seed", 22); data = random (pd, 1000, 1); pd_fitted = fitdist (data, "Beta") ci = paramci (pd_fitted, "Alpha", 0.05) ## Use this to obtain confidence intervals for the estimated parameters (a, b), ## providing a range of plausible values given the data. pd = BetaDistribution beta distribution a = 2 b = 5 pd_fitted = BetaDistribution beta distribution a = 1.9204 [1.77359, 2.07935] b = 4.89801 [4.47772, 5.35775] ci = 1.7736 4.4777 2.0794 5.3577 |
y = pdf (pd, x)
computes the PDF of the
probability distribution object, pd, evaluated at the values in
x.
## Plot various PDFs from the Beta distribution x = 0:0.01:1; pd1 = makedist ("Beta", "a", 0.5, "b", 0.5); pd2 = makedist ("Beta", "a", 2, "b", 2); pd3 = makedist ("Beta", "a", 5, "b", 2); y1 = pdf (pd1, x); y2 = pdf (pd2, x); y3 = pdf (pd3, x); plot (x, y1, "-b", x, y2, "-g", x, y3, "-r") grid on legend ({"a = 0.5, b = 0.5", "a = 2, b = 2", "a = 5, b = 2"}, ... "location", "north") title ("Beta PDF") xlabel ("Value") ylabel ("Probability Density") ## This visualizes the probability density function for beta distributions, ## showing the likelihood of different values in [0, 1]. |
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.
Name | Value | |
---|---|---|
"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.
## Create a Beta distribution with fixed parameters a = 2 and b = 5, and ## plot its PDF. pd = makedist ("Beta", "a", 2, "b", 5) plot (pd) title ("Fixed Beta distribution with a = 2 and b = 5") pd = BetaDistribution beta distribution a = 2 b = 5 |
## 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_fixed = makedist ("Beta", "a", 2, "b", 4) randg ("seed", 21); data = random (pd_fixed, 100, 1); pd_fitted = fitdist (data, "Beta") plot (pd_fitted, "plottype", "cdf") txt = "Fitted Beta distribution with a = %0.2f and b = %0.2f"; title (sprintf (txt, pd_fitted.a, pd_fitted.b)) legend ({"empirical CDF", "fitted CDF"}, "location", "east") pd_fixed = BetaDistribution beta distribution a = 2 b = 4 pd_fitted = BetaDistribution beta distribution a = 1.58844 [1.2184, 2.07086] b = 3.3298 [2.43615, 4.55126] |
## 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_fixed = makedist ("Beta", "a", 2, "b", 4) randg ("seed", 21); data = random (pd_fixed, 200, 1); pd_fitted = fitdist (data, "Beta") plot (pd_fitted, "plottype", "probability") txt = "Probability plot of a fitted Beta distribution with a = %0.2f and b = %0.2f"; title (sprintf (txt, pd_fitted.a, pd_fitted.b)) legend ({"empirical CDF", "fitted CDF"}, "location", "southeast") pd_fixed = BetaDistribution beta distribution a = 2 b = 4 pd_fitted = BetaDistribution beta distribution a = 1.68235 [1.42401, 1.98756] b = 3.7591 [3.1139, 4.53798] |
"Display"
, display)"Display"
, display)
[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,
also plots the profile likelihood
against the default range of the selected parameter.
"Display"
, "on"
)
[nlogL, param] = proflik (pd, pnum,
setparam)
defines a user-defined range of the selected parameter.
[nlogL, param] = proflik (pd, pnum,
setparam,
also plots the profile
likelihood against the user-defined range of the selected parameter.
"Display"
, "on"
)
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.
## Compute and plot the profile likelihood for the first shape parameter of ## a fitted Beta distribution pd = makedist ("Beta", "a", 2, "b", 5) rand ("seed", 22); data = random (pd, 1000, 1); pd_fitted = fitdist (data, "Beta") [nlogL, param] = proflik (pd_fitted, 1, "Display", "on"); ## Use this to analyze the profile likelihood of the shape parameter (a), ## helping to understand the uncertainty in parameter estimates. pd = BetaDistribution beta distribution a = 2 b = 5 pd_fitted = BetaDistribution beta distribution a = 2.07971 [1.90886, 2.26585] b = 5.07244 [4.64654, 5.53739] |
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.
## Generate random samples from a Beta distribution pd = makedist ("Beta", "a", 2, "b", 5) rand ("seed", 22); samples = random (pd, 500, 1); hist (samples, 20) title ("Histogram of 500 random samples from Beta(a=2, b=5)") xlabel ("Value") ylabel ("Frequency") ## This generates random samples from a beta distribution, useful for ## simulating data within the [0, 1] interval. pd = BetaDistribution beta distribution a = 2 b = 5 |
s = std (pd)
computes the standard deviation of the
probability distribution object, pd.
## Compute the standard deviation for a Beta distribution pd = makedist ("Beta", "a", 2, "b", 5) std_value = std (pd) ## Use this to calculate the standard deviation, which measures the ## variability of the beta distribution. pd = BetaDistribution beta distribution a = 2 b = 5 std_value = 0.1597 |
t = truncate (pd, lower, upper)
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.
## 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] |
v = var (pd)
computes the variance of the
probability distribution object, pd.
## Compute the variance for a Beta distribution pd = makedist ("Beta", "a", 2, "b", 5) var_value = var (pd) ## Use this to calculate the variance, which quantifies the spread of the ## beta distribution. pd = BetaDistribution beta distribution a = 2 b = 5 var_value = 0.025510 |
## Generate a data set of 5000 random samples from a Beta distribution with ## parameters a = 2 and b = 5. Fit a Beta distribution to this data and plot ## a PDF of the fitted distribution superimposed on a histogram of the data. pd_fixed = makedist ("Beta", "a", 2, "b", 5) randg ("seed", 2); data = random (pd_fixed, 5000, 1); pd_fitted = fitdist (data, "Beta") plot (pd_fitted) msg = "Fitted Beta distribution with a = %0.2f and b = %0.2f"; title (sprintf (msg, pd_fitted.a, pd_fitted.b)) pd_fixed = BetaDistribution beta distribution a = 2 b = 5 pd_fitted = BetaDistribution beta distribution a = 2.06688 [1.99231, 2.14425] b = 5.18226 [4.98185, 5.39074] |