Last modified: December 2025

URL: https://cxc.cfa.harvard.edu/sherpa/ahelp/sherpa_kaastra17.html
AHELP for CIAO 4.18 Sherpa

sherpa_kaastra17

Context: contrib

Synopsis

Use the Kaastra 2017 approximation as a goodness-of-fit for the CStat statistic

Syntax

from sherpa_contrib.stats.kaastra17 import *

calc_cstat_gof_kaastra17(id=None, *otherids, bkg_only=False)
show_cstat_gof_kaastra17(id=None, *otherids, bkg_only=False,
outfile=None, clobber=False)
simulate_stats(id=None, *otherids, bkg_only=False, niter=1000,
method=None)

Description

The paper by Kaastra 2017 (A&A 605, A51) provides an approximation for the CStat statistic that provides a "goodness-of-fit" metric.

Loading the routines

The module can be loaded into Sherpa with:

from sherpa_contrib.stats.kaastra17 import *

Contents

The kaastra17 module currenly provides the following routines:

calc_cstat_gof_kaastra17

Calculate the expected CStat, and its variance, for the current model using the Kaastra 2017 approximation.

calc_cstat_gof_kaastra17(id=None, *otherids, bkg_only=False)

The calculation will default to all fitted datasets.

show_cstat_gof_kaastra17

Compare the current statistic to the expected value from the Kaastra 2017 approximation.

show_cstat_gof_kaastra17(id=None, *otherids, bkg_only=False,
outfile=None, clobber=False)

The calculation will default to all fitted datasets.

simulate_stats

Use Poisson statistics to simulate the data given the current model and calculate the statistic value.

simulate_stats(id=None, *otherids, bkg_only=False, niter=1000,
method=None)

The calculation will default to all fitted datasets. The niter argument controls the number of statistic values that will be returned. The method argument controls how the random realisation of the model is created (the default is to use a Poisson distribution).


Examples

Example 1

sherpa> get_stat_name()
'cstat'
sherpa> calc_stat()
472.76671442887954
sherpa> calc_cstat_gof_kaastra17()
Using fit results from dataset: 1
(485.2926987513286, 860.8742628407508)

After a fit with CStat the best fit statistic is 472.767 and the approximation from Kaastra 2017 suggests that a range around 485.293 with a variance of 860.874 is expected. This suggests that this is a good fit.

Example 2

sherpa> show_cstat_gof_kaastra17()
Dataset              = 1
Statistic            = cstat
  calculated         = 472.76671442887954
  model prediction   = 485.2926987513286 +/- 29.3406588685522
  separation         = -0.4269 sigma

Example 3

sherpa> got = calc_cstat_gof_kaastra17(2, 4)
Using fit results from datasets: 2, 4

Restrict the analysis to just datasets 2 and 4.

Example 4

sherpa> from sherpa.utils.logging import SherpaVerbosity
sherpa> with SherpaVerbosity("WARN"):
...: got = calc_cstat_gof_kaastra17(2, 4)

Avoid the screen output from the command with the SherpaVerbosity context manager.

Example 5

sherpa> stats = simulate_stats()
Using fit results from dataset: 1
sherpa> plot_cdf(stats)
sherpa> mean, var = calc_cstat_gof_kaastra17()
Using fit results from dataset: 1
sherpa> print(f"{mean:.3f} +/- {np.sqrt(var):.3f}")
485.293 +/- 29.341

The takes the current model and simulates 1000 datasets assuming Poisson statistics, and calculates the fit statistic for each simulation. The stats array contains these values, and plot_cdf is used to plot this distribution. The plot marks the median and +/- 1 sigma range, which can be compared to the Kaastra 2017 approximation.


Changes in the scripts 4.18.0 (December 2025) release

The sherpa_contrib.stats.kaastra17 module is new.


Bugs

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