Package ComboCode :: Package cc :: Package ivs :: Package sigproc :: Package lmfit :: Module confidence
[hide private]
[frames] | no frames]

Module confidence

source code

Contains functions to calculate confidence intervals.

Classes [hide private]
  ConfidenceInterval
Class used to calculate the confidence interval.
Functions [hide private]
 
f_compare(ndata, nparas, new_chi, best_chi, nfix=1.0)
Returns the probalitiy for two given parameter sets.
source code
 
copy_vals(params)
Saves the values and stderrs of params in temporay dict
source code
 
restore_vals(tmp_params, params)
Restores values and stderrs of params in temporay dict
source code
 
conf_interval(minimizer, p_names=None, sigmas=(0.674, 0.95, 0.997), trace=False, maxiter=200, verbose=False, prob_func=None)
Calculates the confidence interval for parameters from the given minimizer.
source code
 
map_trace_to_names(trace, params)
maps trace to param names
source code
 
conf_interval2d(minimizer, x_name, y_name, nx=10, ny=10, limits=None, prob_func=None, verbose=True)
Calculates confidence regions for two fixed parameters.
source code
Variables [hide private]
  __package__ = 'ComboCode.cc.ivs.sigproc.lmfit'
Function Details [hide private]

f_compare(ndata, nparas, new_chi, best_chi, nfix=1.0)

source code 

Returns the probalitiy for two given parameter sets. nfix is the number of fixed parameters.

conf_interval(minimizer, p_names=None, sigmas=(0.674, 0.95, 0.997), trace=False, maxiter=200, verbose=False, prob_func=None)

source code 
Calculates the confidence interval for parameters
from the given minimizer.

The parameter for which the ci is calculated will be varied, while
the remaining parameters are re-optimized for minimizing chi-square.
The resulting chi-square is used  to calculate the probability with
a given statistic e.g. F-statistic. This function uses a 1d-rootfinder
from scipy to find the values resulting in the searched confidence
region.

Parameters
----------
minimizer : Minimizer
    The minimizer to use, should be already fitted via leastsq.
p_names : list, optional
    Names of the parameters for which the ci is calculated. If None,
    the ci is calculated for every parameter.
sigmas : list, optional
    The probabilities (1-alpha) to find. Default is 1,2 and 3-sigma.
trace : bool, optional
    Defaults to False, if true, each result of a probability calculation
    is saved along with the parameter. This can be used to plot so
    called "profile traces".

Returns
-------
output : dict
    A dict, which contains a list of (sigma, vals)-tuples for each name.
trace_dict : dict
    Only if trace is set true. Is a dict, the key is the parameter which
    was fixed.The values are again a dict with the names as keys, but with
    an additional key 'prob'. Each contains an array of the corresponding
    values.

See also
--------
conf_interval2d

Other Parameters
----------------
maxiter : int
    Maximum of iteration to find an upper limit.
prob_func : ``None`` or callable
    Function to calculate the probability from the optimized chi-square.
    Default (``None``) uses built-in f_compare (F test).
verbose: bool
    print extra debuggin information. Default is ``False``.


Examples
--------

>>> from lmfit.printfuncs import *
>>> mini=minimize(some_func, params)
>>> mini.leastsq()
True
>>> report_errors(params)
... #report
>>> ci=conf_interval(mini)
>>> report_ci(ci)
... #report

Now with quantiles for the sigmas and using the trace.

>>> ci, trace=conf_interval(mini, sigmas=(0.25,0.5,0.75,0.999),trace=True)
>>> fixed=trace['para1']['para1']
>>> free=trace['para1']['not_para1']
>>> prob=trace['para1']['prob']

This makes it possible to plot the dependence between free and fixed.

conf_interval2d(minimizer, x_name, y_name, nx=10, ny=10, limits=None, prob_func=None, verbose=True)

source code 
Calculates confidence regions for two fixed parameters.

The method is explained in *conf_interval*: here we are fixing
two parameters.

Parameters
----------
minimizer : minimizer
    The minimizer to use, should be already fitted via leastsq.
x_name : string
    The name of the parameter which will be the x direction.
y_name : string
    The name of the parameter which will be the y direction.
nx, ny : ints, optional
    Number of points.
limits : tuple: optional
    Should have the form ((x_upper, x_lower),(y_upper, y_lower)). If not
    given, the default is 5 std-errs in each direction.

Returns
-------
x : (nx)-array
    x-coordinates
y : (ny)-array
    y-coordinates
grid : (nx,ny)-array
    grid contains the calculated probabilities.

Examples
--------

>>> from lmfit.printfuncs import *
>>> mini=minimize(some_func, params)
>>> mini.leastsq()
True
>>> x,y,gr=conf_interval2d('para1','para2')
>>> plt.contour(x,y,gr)

Other Parameters
----------------
prob_func : ``None`` or callable
    Function to calculate the probability from the optimized chi-square.
    Default (``None``) uses built-in f_compare (F test).