Synopsis
Returns goodness-of-fit statistics associated with a Sherpa data set.
Syntax
calc_stat_info()
Description
The calc_stat_info() function returns the goodness-of-fit statistics associated with a data set and its assigned model. The advantage it offers over the other Sherpa functions which return similar information, e.g. fit() and get_fit_results(), is that it returns statistics on individual data sets included in a simultaneous fit, plus the statistics of the simultaneous fit, whereas the other functions would only return the statistics of the simultaneous fit. The get_stat_info() function is available for parsing the information returned by calc_stat_info(), e.g. so that it can be stored in variables and therefore easily accessed and manipulated within a script.
The calc_stat_info() functions returns the following information about how well the specified models fit the data:
Field | Description |
---|---|
Dataset | data set ID |
Statistic | The name of the chosen fit statistic |
Fit statistic value | The current statistic value |
Data points | The number of bins in the fit |
Degrees of freedom | The number of degrees of freedom in the fit, i.e. the number of bins minus the number of free parameters |
Probability [Q-value] | A measure of the probability that one would observe the reduced statistic value, or a larger value, if the assumed model is true and the best-fit model parameters are the true parameter values. This is only reported for the chi-square, 'cstat', and 'wstat' statistics. |
Reduced statistic | The fit statistic value divided by the number of degrees of freedom. This is only reported for the chi-square, 'cstat', and 'wstat' statistics. |
This function accepts no arguments; it returns the fit statistics for all data sets which have been assigned models, including background data sets associated with source data sets. This means that if a fit has not yet been performed in the Sherpa session, calc_stat_info() will return not-very-meaningful statistics for data sets which have been assigned models but which have not yet been fit. Also, if a fit has been performed for only some of the data sets with assigned models, those data sets which were not explicitly fit will be included in the simultaneous fit results returned by calc_stat_info() (see an example of this behavior below in the examples section).
Examples
Example 1
sherpa> load_pha("source.pi") sherpa> load_arf("arf1.fits") sherpa> load_rmf("rmf1.fits") sherpa> set_source(xsphabs.abs1 * xspowerlaw.p1) sherpa> subtract() sherpa> fit() sherpa> calc_stat_info() sherpa> f = get_stat_info()[0] sherpa> print(f.rstat)
The calc_stat_info() function is used to return the goodness-of-fit statistics resulting from the fit of an absorbed power law model to background-subtracted data set 1. The get_stat_info() function is used to store this information to variable "f", and variable "f" is used to access the reduced statistic value contained in the calc_stat_info() results.
sherpa> calc_stat_info() Dataset = 1 Statistic = chi2gehrels Fit statistic value = 703.792 Data points = 1024 Degrees of freedom = 1021 Probability [Q-value] = 1 Reduced statistic = 0.689316 sherpa> f = get_stat_info()[0] sherpa> print(f) name = Dataset [1] ids = [1] bkg_ids = None statname = chi2gehrels statval = 703.791857589 numpoints = 1024 dof = 1021 qval = 1.0 rstat = 0.689316217031 sherpa> print(f.rstat) 0.689316217031
Example 2
sherpa> set_source(xsphabs.abs1 * powlaw1d.p1) sherpa> set_bkg_source(p1) sherpa> fit() ... sherpa> calc_stat_info()
Return the statistics resulting from a simultaneous fit of the source spectrum assigned to default data set 1 and its associated background spectrum.
sherpa> calc_stat_info() Dataset = 1 Statistic = chi2gehrels Fit statistic value = 229.711 Data points = 46 Degrees of freedom = 43 Probability [Q-value] = 2.46463e-27 Reduced statistic = 5.34212 Background 1 in Dataset = 1 Statistic = chi2gehrels Fit statistic value = 150.291 Data points = 46 Degrees of freedom = 44 Probability [Q-value] = 1.54791e-13 Reduced statistic = 3.4157 Dataset = 1 Statistic = chi2gehrels Fit statistic value = 380.002 Data points = 92 Degrees of freedom = 89 Probability [Q-value] = 1.318e-37 Reduced statistic = 4.26968
Example 3
sherpa> fit(2) sherpa> calc_stat_info()
Return the statistics resulting from an explicit fit to source data set 2, and the statistics for data set 1 had it been included in the fit to data set 2.
sherpa> list_data_ids() [1,2] sherpa> fit(2) sherpa> calc_stat_info() WARNING: data set 1 has associated backgrounds, but they have not been subtracted, nor have background models been set WARNING: data set 2 has associated backgrounds, but they have not been subtracted, nor have background models been set Dataset = 1 Statistic = chi2gehrels Fit statistic value = 225.242 Data points = 46 Degrees of freedom = 43 Probability [Q-value] = 1.54579e-26 Reduced statistic = 5.23818 Dataset = 2 Statistic = chi2gehrels Fit statistic value = 54.4582 Data points = 46 Degrees of freedom = 44 Probability [Q-value] = 0.134171 Reduced statistic = 1.23769 Datasets = [1, 2] Statistic = chi2gehrels Fit statistic value = 279.7 Data points = 92 Degrees of freedom = 89 Probability [Q-value] = 1.44025e-21 Reduced statistic = 3.1427
Bugs
See the bugs pages on the Sherpa website for an up-to-date listing of known bugs.
See Also
- confidence
- get_conf, get_covar, get_int_proj, get_int_unc, get_proj, get_reg_proj, get_reg_unc
- contrib
- get_chart_spectrum, get_marx_spectrum
- data
- get_areascal, get_arf, get_arf_plot, get_axes, get_backscal, get_bkg, get_bkg_plot, get_bkg_scale, get_coord, get_counts, get_data, get_data_plot, get_dep, get_dims, get_error, get_exposure, get_grouping, get_indep, get_quality, get_rmf, get_specresp, get_staterror, get_syserror
- filtering
- get_filter
- fitting
- get_fit, get_stat_info
- info
- get_default_id, list_stats
- methods
- get_draws, get_iter_method_name, get_iter_method_opt, get_method
- modeling
- get_model, get_model_component, get_model_component_image, get_model_component_plot, get_model_plot, get_num_par, get_order_plot, get_par, get_pileup_model, get_response, get_source, get_source_component_image, get_source_component_plot, image_source
- plotting
- get_split_plot
- psfs
- get_kernel, get_psf
- statistics
- get_chisqr_plot, get_delchi_plot, get_prior, get_sampler, get_stat
- utilities
- get_analysis, get_rate
- visualization
- get_ratio, get_resid, image_getregion