Main Content


Gamma negative log-likelihood


nlogL = gamlike(params,data)
[nlogL,AVAR] = gamlike(params,data)


nlogL = gamlike(params,data) returns the negative of the gamma log-likelihood of the parameters, params, given data. params(1)=A, shape parameters, and params(2)=B, scale parameters. The parameters in params must all be positive

[nlogL,AVAR] = gamlike(params,data) also returns AVAR, which is the asymptotic variance-covariance matrix of the parameter estimates when the values in params are the maximum likelihood estimates. AVAR is the inverse of Fisher's information matrix. The diagonal elements of AVAR are the asymptotic variances of their respective parameters.

[...] = gamlike(params,data,censoring) accepts a Boolean vector of the same size as data that is 1 for observations that are right-censored and 0 for observations that are observed exactly.

[...] = gamfit(params,data,censoring,freq) accepts a frequency vector of the same size as data. freq typically contains integer frequencies for the corresponding elements in data, but may contain any non-negative values.

gamlike is a utility function for maximum likelihood estimation of the gamma distribution. Since gamlike returns the negative gamma log-likelihood function, minimizing gamlike using fminsearch is the same as maximizing the likelihood.


Compute the negative log-likelihood of parameter estimates computed by the gamfit function:

a = 2; b = 3;
r = gamrnd(a,b,100,1);

[nlogL,AVAR] = gamlike(gamfit(r),r)
nlogL =
  0.0788  -0.1104
 -0.1104  0.1955

Extended Capabilities

Version History

Introduced before R2006a