Normal negative loglikelihood
also returns the inverse of the Fisher information matrix
aVar] = normlike(___)
aVar, using any of the input argument combinations in
the previous syntaxes. If values in
params are the maximum
likelihood estimates (MLEs) of the parameters,
aVar is an
approximation to the asymptotic covariance matrix.
Negative Loglikelihood of MLEs
Find the MLEs of a data set with censoring by using
normfit, and then find the negative loglikelihood of the MLEs by using
Load the sample data.
The first column of the data contains the lifetime (in hours) of two types of bulbs. The second column contains the binary variable indicating whether the bulb is fluorescent or incandescent. 1 indicates that the bulb is fluorescent, and 0 indicates that the bulb is incandescent. The third column contains the censorship information, where 0 indicates the bulb is observed until failure, and 1 indicates the item (bulb) is censored.
Find the indices for fluorescent bulbs.
idx = find(lightbulb(:,2) == 0);
Find the MLEs of the normal distribution parameters. The second input argument of
normfit specifies the confidence level. Pass in
 to use its default value 0.05. The third input argument specifies the censorship information.
censoring = lightbulb(idx,3) == 1; [muHat,sigmaHat] = normfit(lightbulb(idx,1),,censoring)
muHat = 9.4966e+03
sigmaHat = 3.0640e+03
Find the negative loglikelihood of the MLEs.
nlogL = normlike([muHat,sigmaHat],lightbulb(idx,1),censoring)
nlogL = 376.2305
Convert Unbiased Estimator to MLE
normfit finds the sample mean and the square root of the unbiased estimator of the variance with no censoring. The sample mean is equal to the MLE of the mean parameter, but the square root of the unbiased estimator of the variance is not equal to the MLE of the standard deviation parameter.
Find the normal distribution parameters by using
normfit, convert them into MLEs, and then compare the negative log likelihoods of the estimates by using
Generate 100 normal random numbers from the standard normal distribution.
rng('default') % For reproducibility n = 100; x = normrnd(0,1,[n,1]);
Find the sample mean and the square root of the unbiased estimator of the variance.
[muHat,sigmaHat] = normfit(x)
muHat = 0.1231
sigmaHat = 1.1624
Convert the square root of the unbiased estimator of the variance into the MLE of the standard deviation parameter.
sigmaHat_MLE = sqrt((n-1)/n)*sigmaHat
sigmaHat_MLE = 1.1566
The difference between
sigmaHat_MLE is negligible for large
Alternatively, you can find the MLEs by using the function
phat = mle(x)
phat = 1×2 0.1231 1.1566
phat(2) are the MLEs of the mean and the standard deviation parameter, respectively.
Confirm that the log likelihood of the MLEs (
sigmaHat_MLE) is greater than the log likelihood of the unbiased estimators (
sigmaHat) by using the
logL = -normlike([muHat,sigmaHat],x)
logL = -156.4424
logL_MLE = -normlike([muHat,sigmaHat_MLE],x)
logL_MLE = -156.4399
Confidence Interval of Inverse Normal cdf Value
Find the maximum likelihood estimates (MLEs) of the normal distribution parameters, and then find the confidence interval of the corresponding inverse cdf value.
Generate 1000 normal random numbers from the normal distribution with mean 5 and standard deviation 2.
rng('default') % For reproducibility n = 1000; % Number of samples x = normrnd(5,2,[n,1]);
Find the MLEs for the distribution parameters (mean and standard deviation) by using
phat = mle(x)
phat = 1×2 4.9347 1.9969
muHat = phat(1); sigmaHat = phat(2);
Estimate the covariance of the distribution parameters by using
normlike. The function
normlike returns an approximation to the asymptotic covariance matrix if you pass the MLEs and the samples used to estimate the MLEs.
[~,pCov] = normlike([muHat,sigmaHat],x)
pCov = 2×2 0.0040 -0.0000 -0.0000 0.0020
Find the inverse cdf value at 0.5 and its 99% confidence interval.
[x,xLo,xUp] = norminv(0.5,muHat,sigmaHat,pCov,0.01)
x = 4.9347
xLo = 4.7721
xUp = 5.0974
x is the inverse cdf value using the normal distribution with the parameters
sigmaHat. The interval
[xLo,xUp] is the 99% confidence interval of the inverse cdf value evaluated at 0.5, considering the uncertainty of
pCov. The 99% confidence interval means the probability that
[xLo,xUp] contains the true inverse cdf value is 0.99.
params — Normal distribution parameters
vector of two numeric values
Normal distribution parameters consisting of the mean and standard
deviation, specified as a vector of two numeric values.
to the mean and standard deviation of the normal distribution, respectively.
params(2) must be positive.
normlike is a function specific to normal distribution.
Statistics and Machine Learning Toolbox™ also offers the generic functions
proflik and the Distribution Fitter app, which support various
mlecovreturns 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',@normpdf)returns the asymptotic covariance matrix of the MLEs for the normal distribution.
NormalDistributionprobability distribution object by fitting the distribution to data using the
fitdistfunction or the Distribution Fitter app. The object property
ParameterCovariancestores 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
 Evans, M., N. Hastings, and B. Peacock. Statistical Distributions. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc., 1993.
 Lawless, J. F. Statistical Models and Methods for Lifetime Data. Hoboken, NJ: Wiley-Interscience, 1982.
 Meeker, W. Q., and L. A. Escobar. Statistical Methods for Reliability Data. Hoboken, NJ: John Wiley & Sons, Inc., 1998.
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
This function fully supports GPU arrays. For more information, see Run MATLAB Functions on a GPU (Parallel Computing Toolbox).