sherpa.astro.ui.load_user_stat(statname, calc_stat_func, calc_err_func=None, priors={})

Create a user-defined statistic.

The choice of statistics - that is, the numeric value that is minimised during the fit - can be extended by providing a function to calculate a numeric value given the data. The statistic is given a name and then can be used just like any of the pre-defined statistics.

  • statname (str) – The name to use for the new statistic when calling set_stat.

  • calc_stat_func (func) – The function that calculates the statistic.

  • calc_err_func (func, optional) – How to calculate the statistical error on a data point.

  • priors (dict) – A dictionary of hyper-parameters for the priors.

See also


Calculate the fit statistic for a data set.


Set the statistical method.


The calc_stat_func should have the following signature:

def func(data, model, staterror=None, syserrr=None, weight=None)

where data is the array of dependent values, model the array of the predicted values, staterror and syserror are arrays of statistical and systematic errors respectively (if valid), and weight an array of weights. The return value is the pair (stat_value, stat_per_bin), where stat_value is a scalar and stat_per_bin is an array the same length as data.

The calc_err_func should have the following signature:

def func(data)

and returns an array the same length as data.


Define a chi-square statistic with the label “qstat”:

>>> def qstat(d, m, staterr=None, syserr=None, w=None):
...     if staterr is None:
...         staterr = 1
...     c = ((d-m) / staterr)
...     return ((c*c).sum(), c)
>>> load_user_stat("qstat", qstat)
>>> set_stat("qstat")