주요 콘텐츠

betalike

Beta negative loglikelihood

Description

nlogL = betalike(params,x) returns the beta negative loglikelihood of the distribution parameters (params) given the sample data (x). params(1) and params(2) correspond to the beta a and b parameters, respectively.

betalike is a utility function for maximum likelihood estimation of the beta distribution. The likelihood assumes that all the elements in the data sample are mutually independent. Because betalike returns the negative beta loglikelihood function, minimizing betalike using fminsearch is the same as maximizing the likelihood.

[nlogL,aVar] = betalike(params,x) also returns the inverse of the Fisher information matrix aVar. If the values in params are the maximum likelihood estimates (MLEs) of the parameters, the diagonal elements of aVar are their asymptotic variances. aVar is based on the observed Fisher information, not the expected information.

example

Examples

collapse all

Find the maximum likelihood estimates (MLEs) of a random data set drawn from the beta distribution by using the mle function, and then find the negative loglikelihood of the MLEs by using the betalike function.

Generate 1000 random numbers from the beta distribution with the parameters 4 and 2.

rng(0,"twister") % For reproducibility
n = 1000; % Number of samples
x = betarnd(4,2,[n,1]);

Find the MLEs for the distribution parameters (a and b).

pHat = mle(x,Distribution="Beta")
pHat = 1×2

    4.0412    2.0499

Compute the negative loglikelihood of the MLEs and the inverse of Fisher's information matrix.

[nlogL,aVar] = betalike(pHat,x)
nlogL = 
-363.7162
aVar = 2×2

    0.0339    0.0137
    0.0137    0.0077

Because pHat contains MLE values, the betalike function returns their asymptotic variances in the diagonal elements of aVar.

Input Arguments

collapse all

Beta distribution parameters, specified as a vector of two positive scalar values. params(1) and params(2) are the beta a and b parameter values, respectively.

Data Types: single | double

Sample data, specified as a numeric vector.

The elements of x must lie in the open interval (0,1), where the beta distribution is defined. However, you might need to fit a beta distribution to data that includes exact zeros or ones. For such data, the beta likelihood function is unbounded, and standard maximum likelihood estimation is not possible. In this case, betalike computes a modified likelihood that incorporates the zeros or ones by treating them as values that are left-censored at sqrt(realmin) and right-censored at 1eps/2, respectively.

Data Types: single | double

Output Arguments

collapse all

Negative loglikelihood value of the distribution parameters (params) given the sample data (x), returned as a numeric scalar.

Inverse of the Fisher information matrix, returned as a 2-by-2 numeric matrix. aVar is based on the observed Fisher information given the observed data (x), not the expected information.

If values in params are the MLEs of the parameters, aVar is an approximation to the asymptotic variance-covariance matrix (also known as the asymptotic covariance matrix). To find the MLEs, use mle.

Alternative Functionality

betalike is a function specific to the beta distribution. Statistics and Machine Learning Toolbox™ also offers the generic functions mlecov, fitdist, negloglik, and proflik and the Distribution Fitter app, which support various probability distributions.

  • mlecov returns the asymptotic covariance matrix of the MLEs of the parameters for a distribution specified by a custom probability density function. For example, mlecov(params,x,"pdf",@betapdf) returns the asymptotic covariance matrix of the MLEs for the beta distribution.

  • Create a BetaDistribution probability distribution object by fitting the distribution to data using the fitdist function or the Distribution Fitter app. The object property ParameterCovariance stores the covariance matrix of the parameter estimates. To obtain the negative loglikelihood of the parameter estimates and the profile of the likelihood function, pass the object to negloglik and proflik, respectively.

Extended Capabilities

expand all

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced before R2006a