Main Content

statset

Create statistics options structure

    Description

    statset() displays all fields of a statistics options structure and their possible values.

    example

    statset(statfun) displays the fields and default values used by the function or object specified by statfun.

    statset(___) returns a statistics options structure using any of the previous input argument combinations.

    example

    statset(Name=Value) specifies the field values of the options structure using one or more name-value arguments. For example, you can specify the maximum number of objective function evaluations and the weight function for robust fitting.

    example

    statset(oldopts,newopts) returns a copy of newopts with the empty fields changed to the values in oldopts.

    statset(oldopts,Name=Value) returns a copy of oldopts with field values changed to those specified by the name-value arguments.

    example

    Examples

    collapse all

    Display all fields of a statistics options structure and their possible values.

    statset()
                    Display: [ {off} | final | iter ]
                MaxFunEvals: [ positive integer ]
                    MaxIter: [ positive integer ]
                     TolBnd: [ positive scalar ]
                     TolFun: [ positive scalar ]
                 TolTypeFun: ['abs' |'rel']
                       TolX: [ positive scalar ]
                   TolTypeX: ['abs' |'rel']
                    GradObj: [ {off} | on ]
                   Jacobian: [ {off} | on ]
                  DerivStep: [ positive scalar or vector ]
                FunValCheck: [ off | {on} ]
               RobustWgtFun: [ {[]} | bisquare | andrews | cauchy | fair | huber | logistic | talwar | welsch | function handle ]
                       Tune: [ positive scalar ]
                UseParallel: [ {false} | true ]
              UseSubstreams: [ {false} | true ]
                    Streams: [ {} | RandStream or cell array ]
                  OutputFcn: [ {[]} | function handle or cell array ]
    

    The output shows the fields and their possible values. You can use the output as a reference when creating a statistics options structure.

    Create an options structure containing the default options for the fitglm function.

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

    The output shows that the default options for fitglm include values for the display, maximum number of iterations, and parameter termination tolerance. You can pass options to other functions that accept statistics options structures.

    Create a custom options structure by using name-value arguments to specify individual field values.

    options = statset(FunValCheck="on",TolX=1e-8)
    options = struct with fields:
              Display: []
          MaxFunEvals: []
              MaxIter: []
               TolBnd: []
               TolFun: []
           TolTypeFun: []
                 TolX: 1.0000e-08
             TolTypeX: []
              GradObj: []
             Jacobian: []
            DerivStep: []
          FunValCheck: 'on'
               Robust: []
         RobustWgtFun: []
               WgtFun: []
                 Tune: []
          UseParallel: []
        UseSubstreams: []
              Streams: {}
            OutputFcn: []
    
    

    You can pass options to an eligible statistics function to set the parameter termination tolerance to 1e-8 and check for invalid values.

    Create a statistics options structure that contains the default options for the function nbinfit. Then modify the structure by specifying field values using name-value arguments.

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

    oldopts is a statistics options structure that contains the default values for the nbinfit function. Note that the default value for TolX is 1e-6.

    Create a copy of oldopts and specify 1e-8 for TolX.

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

    The output shows that the fields in opts have the same values as the fields in oldopts, with the exception of TolX.

    Input Arguments

    collapse all

    Statistics function, specified as a character vector or string scalar, as follows:

    Example: "bootci"

    Data Types: char | string

    Old options, specified as a statistics options structure.

    Data Types: struct

    New options, specified as a statistics options structure.

    Data Types: string

    Name-Value Arguments

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: statset(MaxFunEvals=200,TolBnd=1e-6,TolX=1e-6) specifies the maximum number of objective function evaluations as 200, and specifies both the parameter bound tolerance and parameter termination tolerance as 1e-6.

    Relative difference for finite difference calculations, specified as a positive scalar or a vector of positive scalars. If DerivStep is a vector of positive scalars, it must be the same size as the vector of parameters estimated by the function using the options structure.

    Example: DerivStep=0.1

    Data Types: single | double

    Option to display algorithm information, specified as one of the following:

    • "off" — Display no information.

    • "final" — Display the final output.

    • "iter" — Display iterative output to the command window for some functions, and display the final output otherwise.

    Example: Display="iter"

    Data Types: char | string

    Flag to check for invalid values returned by the objective function, specified as "off" or "on". Examples of invalid values include NaN and Inf.

    Example: FunValCheck="on"

    Data Types: char | string

    Flag to return a gradient vector as an additional output of the objective function, specified as "off" or "on".

    Example: GradObj="on"

    Data Types: char | string

    Flag to return a Jacobian as an additional output of the objective function, specified as "off" or "on".

    Example: Jacobian="on"

    Data Types: char | string

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

    Example: MaxFunEvals=200

    Data Types: single | double

    Maximum number of iterations, specified as a positive integer.

    Example: MaxIter=100

    Data Types: single | double

    Output function, specified as a function handle or cell array of function handles.

    Example: OutputFcn=@myfun

    Data Types: cell | function_handle

    Weight function for robust fitting, specified as a character vector or string scalar for one of the following function names.

    Weight FunctionEquationDefault Tuning Constant
    "andrews"w = (abs(r)<pi) .* sin(r) ./ r1.339
    "bisquare" (default)w = (abs(r)<1) .* (1 - r.^2).^24.685
    "cauchy"w = 1 ./ (1 + r.^2)2.385
    "fair"w = 1 ./ (1 + abs(r))1.400
    "huber"w = 1 ./ max(1, abs(r))1.345
    "logistic"w = tanh(r) ./ r1.205
    "talwar"w = 1 * (abs(r)<1)2.795
    "welsch"w = exp(-(r.^2))2.985

    Example: RobustWgtFun="logistic"

    Data Types: char | string

    Random number stream, specified as a RandStream object or cell array of RandStream objects.

    If UseSubstreams is true, then Streams cannot be a cell array of RandStream objects. If UseSubstreams is false and UseParallel is true, then Streams must be empty or have the same length as the number of processors in the calculation. The number of processors is a scalar or is equal to the size of the parallel pool (if one is open).

    Parameter bound tolerance, specified as a positive scalar.

    Example: TolBnd=1e-6

    Data Types: single | double

    Objective function termination tolerance, specified as a positive scalar.

    Example: TolFun=1.5

    Data Types: single | double

    Type of objective function termination tolerance, specified as "abs" or "rel". When TolTypeFun is "abs", TolFun is an absolute tolerance. When TolTypeFun is "rel", TolFun is a relative tolerance.

    Example: TolTypeFun="rel"

    Data Types: char | string

    Parameter termination tolerance, specified as a positive scalar.

    Example: TolX=1e-6

    Data Types: single | double

    Type of parameter termination tolerance, specified as "abs" or "rel". When TolTypeX is "abs", TolX is an absolute tolerance. When TolTypeX is "rel", TolX is a relative tolerance.

    Example: TolTypeX="rel"

    Data Types: char | string

    Tuning constant for robust fitting, specified as a positive scalar. The default value of Tune depends on the weight function specified by RobustWgtFun.

    Example: Tune=1.5

    Data Types: single | double

    Flag to use parallel computing functionality (requires Parallel Computing Toolbox™), specified as a numeric or logical 0 (false) or 1 (true). To use parallel computing when UseParallel is true, Parallel Computing Toolbox must be installed and a parallel pool must be open.

    Example: UseParallel=true

    Data Types: logical

    Flag for the random number generator to use substreams, specified as a numeric or logical 0 (false) or 1 (true).

    When UseSubstreams is true, functions using the options output use the Substream property of the RandStream object. You can specify the RandStream object by using the Streams name-value argument.

    Using substreams helps to generate reproducible random number streams in parallel and serial mode computations. For more information, see Reproducibility in Parallel Statistical Computations.

    Example: UseSubstreams=true

    Data Types: logical

    Version History

    Introduced before R2006a

    See Also