AHELP for CIAO 4.15 Sherpa

Context: statistics

## Synopsis

Create a user-defined statistic.

## Syntax

```load_user_stat(statname, calc_stat_func, calc_err_func=None, priors={})

statname - str
calc_stat_func - func
calc_err_func - func, optional
priors - dict```

## Description

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.

## Example

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)
...
>>> set_stat("qstat")```

### PARAMETERS

The parameters for this function are:

Parameter Definition
statname The name to use for the new statistic when calling `set_stat` .
calc_stat_func The function that calculates the statistic.
calc_err_func How to calculate the statistical error on a data point.
priors A dictionary of hyper-parameters for the priors.

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.

## Bugs

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