Contenido principal

nbinfit

Negative binomial parameter estimates

    Description

    phat = nbinfit(data) returns the maximum likelihood estimates (MLEs) for the parameters of the negative binomial distribution using the sample data data.

    Note

    The variance of a negative binomial distribution is greater than its mean. If the sample variance of the data in data is less than its sample mean, nbinfit cannot compute MLEs. In this case, use the poissfit function instead.

    [phat,pci] = nbinfit(data,alpha) returns MLEs and 100(1-alpha)% confidence intervals. If you do not specify alpha, nbinfit returns 95% confidence intervals.

    example

    [___] = nbinfit(___,options) specifies options for the function's iterative algorithm using any of the input and output argument combinations in the previous syntaxes.

    example

    Examples

    collapse all

    Generate a vector of random numbers from the negative binomial distribution by using the nbinrnd function.

    data = nbinrnd(3,0.1,20,1);

    Calculate the maximum likelihood estimates and 95% confidence intervals for the distribution parameters.

    [phat,pci] = nbinfit(data)
    phat = 1×2
    
        4.1366    0.1475
    
    
    pci = 2×2
    
        1.1659    0.0526
        7.1073    0.2425
    
    

    phat contains the estimates for the parameters that correspond to the number of successes and the probability of success. Each column of pci contains the confidence interval bounds for the parameter in the same column of phat.

    Calculate 99% confidence intervals for the distribution parameters.

    [phat2,pci2] = nbinfit(data,0.01)
    phat2 = 1×2
    
        4.1366    0.1475
    
    
    pci2 = 2×2
    
        0.2324    0.0227
        8.0407    0.2724
    
    

    The output shows that the 99% confidence interval for each parameter contains its 95% confidence interval.

    Generate a vector of random numbers from the negative binomial distribution by using the nbinrnd function. Specify options for the iterative algorithm by using the statset function.

    data = nbinrnd(6,0.01,1000,1);

    Create a new options structure that specifies to display the algorithm information for every iteration.

    options=statset(Display="iter");

    Calculate the parameter estimates using options. Specify a significance level of 0.01.

    phat2 = nbinfit(data,0.01,options)
     
     Iteration   Func-count         f(x)         Procedure
         0            1     -3.20134e+06         
         1            2     -3.20134e+06         initial simplex
         2            4     -3.20134e+06         contract inside
         3            6     -3.20134e+06         contract inside
         4            8     -3.20134e+06         contract inside
         5           10     -3.20134e+06         contract inside
         6           12     -3.20134e+06         contract inside
         7           14     -3.20134e+06         contract inside
         8           16     -3.20134e+06         contract inside
         9           18     -3.20134e+06         contract inside
        10           20     -3.20134e+06         contract inside
        11           22     -3.20134e+06         contract inside
        12           24     -3.20134e+06         contract inside
        13           26     -3.20134e+06         contract inside
        14           28     -3.20134e+06         contract inside
        15           30     -3.20134e+06         contract inside
        16           32     -3.20134e+06         contract inside
        17           34     -3.20134e+06         contract inside
        18           36     -3.20134e+06         contract inside
        19           39     -3.20134e+06         shrink
        20           41     -3.20134e+06         contract inside
     
    Optimization terminated:
     the current x satisfies the termination criteria using OPTIONS.TolX of 1.000000e-06 
     and F(X) satisfies the convergence criteria using OPTIONS.TolFun of 1.000000e-06 
    
    phat2 = 1×2
    
        6.1828    0.0104
    
    

    The first three columns of the output display the iteration number, cumulative number of objective function evaluations, and objective function, respectively. The final column identifies the step of the Nelder-Mead simplex method used in the iteration.

    Input Arguments

    collapse all

    Sample data, specified as a vector of nonnegative integers.

    Data Types: double

    Significance level for the estimates, specified as a scalar value in the range (0,1). The confidence level of the confidence intervals is 100(1-alpha)%. The default value for alpha is 0.05, which returns 95% confidence intervals for the estimates.

    Example: 0.01

    Data Types: single | double

    Optimization options, specified as a structure. The value of options determines the control parameters for the iterative algorithm used by nbinfit to compute MLEs for censored data.

    Create options by using the function statset or by creating a structure array that contains the fields and values in the following table.

    Field NameValueDefault Value
    Display

    Amount of information displayed by the algorithm:

    • "off" — Displays no information

    • "final" — Displays the final output

    • "notify" — Displays output only if the function does not converge

    • "iter" — Displays iterative output

    'off'
    MaxFunEvals

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

    400
    MaxIter

    Maximum number of iterations allowed, specified as a positive integer

    200
    TolBnd

    Lower bound of the standard deviation parameter estimate, specified as a positive scalar.

    The bounds for the mean and standard deviation parameter estimates are [–Inf,Inf] and [TolBnd,Inf], respectively.

    1e-6
    TolFun

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

    1e-6
    TolX

    Termination tolerance for the parameters, specified as a positive scalar

    1e-6
    OutputFcn

    Specify one or more user-defined functions that an optimization function calls at each iteration, either as a function handle or as a cell array of function handles. For more information, see Optimization Solver Output Functions.

    []

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

    Example: statset(Display="final",MaxIter=1000) specifies to display the final output of the iterative algorithm results, and to use 1000 as the maximum number of iterations allowed.

    Data Types: struct

    Output Arguments

    collapse all

    Parameter estimates, returned as a numeric row vector. The first element of phat is the estimate for the number of successes r, and the second element is the estimate for the probability of success p. For more information, see Negative Binomial Distribution.

    Confidence intervals for the parameter estimates, returned as a 2-by-2 numeric matrix. The first column corresponds to the estimates for the number of successes r, and the second column corresponds to the probability of success p. The first and second rows show the lower and upper confidence limits, respectively.

    You can specify the significance level for the confidence intervals by using the alpha input argument.

    Extended Capabilities

    expand all

    Version History

    Introduced before R2006a