Last modified: December 2023

AHELP for CIAO 4.16 Sherpa


Context: confidence


Estimate parameter confidence intervals using the confidence method.



Alias: conf

id - int or str, optional
parameter - sherpa.models.parameter.Parameter, optional
model - sherpa.models.model.Model, optional


The `conf` command computes confidence interval bounds for the specified model parameters in the dataset. A given parameter's value is varied along a grid of values while the values of all the other thawed parameters are allowed to float to new best-fit values. The `get_conf` and `set_conf_opt` commands can be used to configure the error analysis; an example being changing the 'sigma' field to 1.6 (i.e. 90%) from its default value of 1 . The output from the routine is displayed on screen, and the `get_conf_results` routine can be used to retrieve the results.


Example 1

Evaluate confidence intervals for all thawed parameters in all data sets with an associated source model. The results are then stored in the variable res .

>>> conf()
>>> res = get_conf_results()

Example 2

Only evaluate the parameters associated with data set 2:

>>> conf(2)

Example 3

Only evaluate the intervals for the pos.xpos and pos.ypos parameters:

>>> conf(pos.xpos, pos.ypos)

Example 4

Change the limits to be 1.6 sigma (90%) rather than the default 1 sigma.

>>> set_conf_opt('sigma', 1.6)
>>> conf()

Example 5

Only evaluate the clus.kt parameter for the data sets with identifiers "obs1", "obs5", and "obs6". This will still use the 1.6 sigma setting from the previous run.

>>> conf("obs1", "obs5", "obs6", clus.kt)

Example 6

Only use two cores when evaluating the errors for the parameters used in the model for data set 3:

>>> set_conf_opt('numcores', 2)
>>> conf(3)

Example 7

Estimate the errors for all the thawed parameters from the line model and the clus.kt parameter for datasets 1, 3, and 4:

>>> conf(1, 3, 4, line, clus.kt)


The parameters for this function are:

Parameter Definition
id The data set, or sets, that provides the data. If not given then all data sets with an associated model are used simultaneously.
parameter The default is to calculate the confidence limits on all thawed parameters of the model, or models, for all the data sets. The evaluation can be restricted by listing the parameters to use. Note that each parameter should be given as a separate argument, rather than as a list. For example conf(g1.ampl, g1.sigma) .
model Select all the thawed parameters in the model.


The function does not follow the normal Python standards for parameter use, since it is designed for easy interactive use. When called with multiple ids or parameters values, the order is unimportant, since any argument that is not defined as a model parameter is assumed to be a data id.

The `conf` function is different to `covar` , in that in that all other thawed parameters are allowed to float to new best-fit values, instead of being fixed to the initial best-fit values as they are in `covar` . While `conf` is more general (e.g. allowing the user to examine the parameter space away from the best-fit point), it is in the strictest sense no more accurate than `covar` for determining confidence intervals.

The `conf` function is a replacement for the `proj` function, which uses a different algorithm to estimate parameter confidence limits.

An estimated confidence interval is accurate if and only if:

One may determine if these conditions hold, for example, by plotting the fit statistic as a function of each parameter's values (the curve should approximate a parabola) and by examining contour plots of the fit statistics made by varying the values of two parameters at a time (the contours should be elliptical, and parameter space boundaries should be no closer than approximately 3 sigma from the best-fit point). The `int_proj` and `reg_proj` commands may be used for this.

If either of the conditions given above does not hold, then the output from `conf` may be meaningless except to give an idea of the scale of the confidence intervals. To accurately determine the confidence intervals, one would have to reparameterize the model, use Monte Carlo simulations, or Bayesian methods.

As the calculation can be computer intensive, the default behavior is to use all available CPU cores to speed up the analysis. This can be changed be varying the numcores option - or setting parallel to False - either with `set_conf_opt` or `get_conf` .

As `conf` estimates intervals for each parameter independently, the relationship between sigma and the change in statistic value delta_S can be particularly simple: sigma = the square root of delta_S for statistics sampled from the chi-square distribution and for the Cash statistic, and is approximately equal to the square root of (2 * delta_S) for fits based on the general log-likelihood. The default setting is to calculate the one-sigma interval, which can be changed with the sigma option to `set_conf_opt` or `get_conf` .

The limit calculated by `conf` is basically a 1-dimensional root in the translated coordinate system (translated by the value of the statistic at the minimum plus sigma^2). The Taylor series expansion of the multi-dimensional function at the minimum is:

f(x + dx) ~ f(x) + grad( f(x) )^T dx + dx^T Hessian( f(x) ) dx + ...

where x is understood to be the n-dimensional vector representing the free parameters to be fitted and the super-script 'T' is the transpose of the row-vector. At or near the minimum, the gradient of the function is zero or negligible, respectively. So the leading term of the expansion is quadratic. The best root finding algorithm for a curve which is approximately parabolic is Muller's method [1]. Muller's method is a generalization of the secant method [2]: the secant method is an iterative root finding method that approximates the function by a straight line through two points, whereas Muller's method is an iterative root finding method that approxmiates the function by a quadratic polynomial through three points.

Three data points are the minimum input to Muller's root finding method. The first point to be submitted to the Muller's root finding method is the point at the minimum. To strategically choose the other two data points, the confidence function uses the output from covariance as the second data point. To generate the third data points for the input to Muller's root finding method, the secant root finding method is used since it only requires two data points to generate the next best approximation of the root.

However, there are cases where `conf` cannot locate the root even though the root is bracketed within an interval (perhaps due to the bad resolution of the data). In such cases, when the option openinterval is set to False (which is the default), the routine will print a warning message about not able to find the root within the set tolerance and the function will return the average of the open interval which brackets the root. If openinterval is set to True then `conf` will print the minimal open interval which brackets the root (not to be confused with the lower and upper bound of the confidence interval). The most accurate thing to do is to return an open interval where the root is localized/bracketed rather then the average of the open interval (since the average of the interval is not a root within the specified tolerance).



See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.

See Also

conf, covar, covariance, get_conf, get_conf_results, get_covar, get_covar_opt, get_covar_results, get_covariance_results, get_int_proj, get_int_unc, get_proj, get_proj_opt, get_proj_results, get_projection_results, get_reg_proj, get_reg_unc, int_proj, int_unc, proj, projection, reg_proj, reg_unc, set_conf_opt, set_covar_opt, set_proj_opt