Esta página aún no se ha traducido para esta versión. Puede ver la versión más reciente de esta página en inglés.

normfit

Normal parameter estimates

Sintaxis

[muHat,sigmaHat] = normfit(x)
[muHat,sigmaHat,muCI,sigmaCI] = normfit(x)
[muHat,sigmaHat,muCI,sigmaCI] = normfit(x,alpha)
[___] = normfit(x,alpha,censoring)
[___] = normfit(x,alpha,censoring,freq)
[___] = normfit(x,alpha,censoring,freq,options)

Descripción

ejemplo

[muHat,sigmaHat] = normfit(x) returns estimates of normal distribution parameters (the mean muHat and standard deviation sigmaHat), given the sample data in x. muHat is the sample mean, and sigmaHat is the square root of the unbiased estimator of the variance.

[muHat,sigmaHat,muCI,sigmaCI] = normfit(x) also returns 95% confidence intervals for the parameter estimates on the mean and standard deviation in the arrays muCI and sigmaCI, respectively.

ejemplo

[muHat,sigmaHat,muCI,sigmaCI] = normfit(x,alpha) specifies the confidence level for the confidence intervals to be 100(1–alpha)%.

ejemplo

[___] = normfit(x,alpha,censoring) specifies whether each value in x is right-censored or not. Use the logical vector censoring in which 1 indicates observations that are right-censored and 0 indicates observations that are fully observed. With censoring, muHat and sigmaHat are the maximum likelihood estimates (MLEs).

[___] = normfit(x,alpha,censoring,freq) specifies the frequency or weights of observation.

ejemplo

[___] = normfit(x,alpha,censoring,freq,options) specifies optimization options for the iterative algorithm normfit to use to compute MLEs with censoring. Create options by using the function statset.

You can pass in [] for alpha, censoring, and freq to use their default values.

Ejemplos

contraer todo

Generate 1000 normal random numbers from the normal distribution with mean 3 and standard deviation 5.

rng('default') % For reproducibility
x = normrnd(3,5,[1000,1]);

Find the parameter estimates and the 99% confidence intervals.

[muHat,sigmaHat,muCI,sigmaCI] = normfit(x,0.01)
muHat = 2.8368
sigmaHat = 4.9948
muCI = 2×1

    2.4292
    3.2445

sigmaCI = 2×1

    4.7218
    5.2989

muHat is the sample mean, and sigmaHat is the square root of the unbiased estimator of the variance. muCI and sigmaCI are the 99% confidence intervals of the mean and standard deviation parameters. The first row is the lower bound, and the second row is the upper bound.

Find the MLEs of a data set with censoring by using normfit. Use statset to specify the iterative algorithm options that normfit uses to compute MLEs for censored data, and find the MLEs again.

Load the sample data.

load lightbulb

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);

Assume that the lifetime follows the normal distribution, and 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;
[muHat1,sigmaHat1] = normfit(lightbulb(idx,1),[],censoring)
muHat1 = 9.4966e+03
sigmaHat1 = 3.0640e+03

Display the default algorithm parameters that the function normfit uses to estimate the normal distribution parameters.

statset('normfit')
ans = struct with fields:
          Display: 'off'
      MaxFunEvals: 200
          MaxIter: 100
           TolBnd: 1.0000e-06
           TolFun: 1.0000e-08
       TolTypeFun: []
             TolX: 1.0000e-08
         TolTypeX: []
          GradObj: []
         Jacobian: []
        DerivStep: []
      FunValCheck: []
           Robust: []
     RobustWgtFun: []
           WgtFun: []
             Tune: []
      UseParallel: []
    UseSubstreams: []
          Streams: {}
        OutputFcn: []

Save the options under a different name. Change how the results will be displayed and the termination tolerance for the objective function, Display and TolFun.

options = statset('normfit');
options.Display = 'final';
options.TolFun = 1e-10;

Alternatively, you can specify algorithm parameters by using the name-value pair arguments of the function statset.

options = statset('Display','final','TolFun',1e-10);

Find the MLEs with the new algorithm parameters.

[muHat2,sigmaHat2] = normfit(lightbulb(idx,1),[],censoring,[],options)
Successful convergence: Norm of gradient less than OPTIONS.TolFun
muHat2 = 9.4966e+03
sigmaHat2 = 3.0640e+03

normfit displays a report on the final iteration.

The function 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 normlike.

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 and sigmaHat_MLE is negligible for large n.

Alternatively, you can find the MLEs by using the function mle.

phat = mle(x)
phat = 1×2

    0.1231    1.1566

phat(1) and phat(2) are the MLEs of the mean and the standard deviation parameter, respectively.

Confirm that the log likelihood of the MLEs (muHat and sigmaHat_MLE) is greater than the log likelihood of the unbiased estimators (muHat and sigmaHat) by using the normlike function.

logL = -normlike([muHat,sigmaHat],x)
logL = -156.4424
logL_MLE = -normlike([muHat,sigmaHat_MLE],x)
logL_MLE = -156.4399

Find the maximum likelihood estimates (MLEs) of the normal distribution parameters, and then find the confidence interval of the corresponding 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);

Estimate the distribution parameters mean and standard deviation by using normfit.

[muHat,sigmaHat] = normfit(x)
muHat = 4.9347
sigmaHat = 1.9979

With no censoring, muHat is the sample mean and sigmaHat is the square root of the unbiased estimator of the variance. muHat is equal to the MLE of the mean parameter, but sigmaHat is not equal to the MLE of the standard deviation parameter. Transform sigmaHat into the MLE.

sigmaHat = sqrt((n-1)/n)*sigmaHat
sigmaHat = 1.9969

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 cdf value at zero and its 95% confidence interval.

[p,pLo,pUp] = normcdf(0,muHat,sigmaHat,pCov)
p = 0.0067
pLo = 0.0047
pUp = 0.0095

p is the cdf value using the normal distribution with the parameters muHat and sigmaHat. The interval [pLo,pUp] is the 95% confidence interval of the cdf evaluated at 0, considering the uncertainty of muHat and sigmaHat using pCov. The 95% confidence interval means that the probability that [pLo,pUp] contains the true cdf value is 0.95.

Argumentos de entrada

contraer todo

Sample data, specified as a vector or matrix.

If you specify censoring or freq, x must be a vector.

Tipos de datos: single | double

Confidence level for the confidence interval, specified as a scalar or vector where each element is in the range (0,1). The confidence level is 100(1–alpha)%. alpha is the probability that the confidence interval does not contain the true value.

If alpha is a vector of size m, then muCI and sigmaCI are matrices of size 2-by-m. The first and second rows correspond to the lower and upper bounds of the confidence intervals, respectively.

Ejemplo: 0.01

Tipos de datos: single | double

Indicator for the censoring of each value in x, specified as a logical vector of the same size as x. Use 1 for observations that are right-censored and 0 for observations that are fully observed.

The default is an array of 0s, meaning that all observations are fully observed.

Tipos de datos: logical

Frequency or weights of observations, specified as a nonnegative vector that is the same size as x. The freq input argument typically contains nonnegative integer counts for the corresponding elements in x, but can contain any nonnegative values.

To obtain the weighted MLEs for the mean and standard deviation for a data set with censoring, specify weights of observations, normalized to the number of observations in x.

The default is an array of 1s, meaning one observation per element of x.

Tipos de datos: single | double

Optimization options, specified as a structure. options determines the control parameters for the iterative algorithm that normfit uses to compute MLEs for censored data.

Create options by using the function statset or by creating a structure array containing the fields and values described in this table.

Field NameValueDefault value
Display

Amount of information displayed by the algorithm.

  • 'off' — Displays no information.

  • 'final' — Displays the final output.

'off'
MaxFunEvals

Maximum number of objective function evaluations allowed, specified as a positive integer.

200
MaxIter

Maximum number of iterations allowed. Positive integer.

100
TolBnd

Lower bound of sigmaHat, specified as a positive scalar.

The bounds for muHat and sigmaHat are [-Inf,Inf] and [TolBnd,Inf], respectively.

1e-6
TolFun

Termination tolerance for the objective function value, specified as a positive scalar.

1e-8
TolX

Termination tolerance for the parameters, specified as a positive scalar.

1e-8

You can also enter statset('normfit') in the Command Window to see the names and default values of the fields that normfit accepts in the options structure.

Ejemplo: statset('Display','final','MaxIter',1000) specifies to display the final information of the iterative algorithm results, and changes the maximum number of iterations allowed to 1000.

Tipos de datos: struct

Output Arguments

contraer todo

Estimate of the mean parameter of the normal distribution, returned as a scalar or vector.

  • With no censoring, muHat is the sample mean.

  • With censoring, muHat is the MLE. To compute the weighted MLE, specify the weights of observations by using freq.

Estimate of the standard deviation parameter of the normal distribution, returned as a scalar or vector.

  • With no censoring, sigmaHat is the square root of the unbiased estimator of the variance. To compute the MLE with no censoring, use the mle function.

  • With censoring, sigmaHat is the MLE. To compute the weighted MLE, specify the weights of observations by using freq.

Confidence interval for the mean parameter of the normal distribution, returned as a 2-by-1 column vector or 2-by-m matrix containing the lower and upper bounds of the 100(1–alpha)% confidence interval. m is the number of values in alpha.

Confidence interval for the standard deviation parameter of the normal distribution, returned as a 2-by-1 column vector or 2-by-m matrix containing the lower and upper bounds of the 100(1–alpha)% confidence interval. m is the number of values in alpha.

Algoritmos

To compute the confidence intervals, normfit uses the exact method for uncensored data and the Wald method for censored data. The exact method provides exact coverage for uncensored samples based on t and chi-square distributions.

Alternative Functionality

normfit is a function specific to normal distribution. Statistics and Machine Learning Toolbox™ also offers the generic functions mle, fitdist, and paramci and the Distribution Fitter app, which support various probability distributions.

  • mle returns MLEs and the confidence intervals of MLEs for the parameters of various probability distributions. You can specify the probability distribution name or custom density function.

  • Create a NormalDistribution probability distribution object by fitting the distribution to data using the fitdist function or the Distribution Fitter app. The object properties mu and sigma store the parameter estimates. To obtain the confidence intervals for the parameter estimates, pass the object to paramci.

Referencias

[1] Evans, M., N. Hastings, and B. Peacock. Statistical Distributions. 2nd ed. Hoboken, NJ: John Wiley & Sons, Inc., 1993.

[2] Lawless, J. F. Statistical Models and Methods for Lifetime Data. Hoboken, NJ: Wiley-Interscience, 1982.

[3] Meeker, W. Q., and L. A. Escobar. Statistical Methods for Reliability Data. Hoboken, NJ: John Wiley & Sons, Inc., 1998.

Capacidades ampliadas

Introducido antes de R2006a