UserStat

class sherpa.stats.UserStat(statfunc: UserStatFunc | None = None, errfunc: Callable[[ndarray], ndarray] | None = None, name: str = 'userstat')[source] [edit on github]

Bases: Stat

Support simple user-supplied statistic calculations.

Methods

calc_stat(data, model)

Return the statistic value for the data and model.

calc_staterror(data)

Return the statistic error values for the data.

goodness_of_fit(statval, dof)

Return the reduced statistic and q value.

set_errfunc

set_statfunc

Notes

This class is used by the sherpa.ui.load_user_stat to provide a user-definable statistic calculation as a function. For more complicated cases it is suggested that users should write their own class instead of using this one.

Methods Summary

calc_stat(data, model)

Return the statistic value for the data and model.

calc_staterror(data)

Return the statistic error values for the data.

goodness_of_fit(statval, dof)

Return the reduced statistic and q value.

set_errfunc(func)

set_statfunc(func)

Methods Documentation

calc_stat(data: Data | DataSimulFit, model: Model) → tuple[float, ndarray][source] [edit on github]

Return the statistic value for the data and model.

Parameters:
datasherpa.data.Data or sherpa.data.DataSimulFit

The data set, or sets, to use.

modelsherpa.models.model.Model or sherpa.models.model.SimulFitModel

The model expression, or expressions. If a sherpa.models.model.SimulFitModel is given then it must match the number of data sets in the data parameter.

Returns:
statvalnumber

The value of the statistic.

fvecarray of numbers

The per-bin “statistic” value.

calc_staterror(data: ndarray) → ndarray[source] [edit on github]

Return the statistic error values for the data.

Parameters:
datascalar or 1D array of numbers

The data values.

Returns:
staterrorscalar or array of numbers

The errors for the input data values (matches the data argument).

goodness_of_fit(statval: float, dof: int) → tuple[Literal[None], Literal[None]] | tuple[float, float] [edit on github]

Return the reduced statistic and q value.

The reduced statisitc is conceptually simple, as it is just statistic / degrees-of-freedom, but it is not meaningful for all statistics, and it is only valid if there are any degrees of freedom.

Parameters:
statvalfloat

The statistic value. It is assumed to be finite.

dofint

The number of degrees of freedom, which may be 0 or negative.

Returns:
rstatfloat or NaN or None

The reduced statistic. If the statistic does not support a goodness of fit then the return value is None. If it does then NaN is returned if either the number of degrees of freedom is 0 (or less), or the statistic value is less than 0.

qvalfloat or NaN or None

The q value. If the statistic does not support a goodness of fit then the return values are None. If it does then NaN is returned if either the number of degrees of freedom is 0 (or less), or the statistic value is less than 0.

set_errfunc(func: Callable[[ndarray], ndarray] | None) → None[source] [edit on github]
set_statfunc(func: UserStatFunc | None) → None[source] [edit on github]