diff --git a/docs/pyerrors/fits.html b/docs/pyerrors/fits.html index a0d51384..af7c33b8 100644 --- a/docs/pyerrors/fits.html +++ b/docs/pyerrors/fits.html @@ -89,6 +89,9 @@
from collections.abc import Sequence +@@ -1620,6 +1664,70 @@ check if the residuals of the fit are gaussian distributed.import gc +from collections.abc import Sequence import warnings import numpy as np import autograd.numpy as anp @@ -855,6 +859,46 @@ err = np.array(err) return err + + +def ks_test(objects=None): + """Performs a Kolmogorov–Smirnov test for the p-values of all fit object. + + Parameters + ---------- + objects : list + List of fit results to include in the analysis (optional). + """ + + if objects is None: + obs_list = [] + for obj in gc.get_objects(): + if isinstance(obj, Fit_result): + obs_list.append(obj) + else: + obs_list = objects + + p_values = [o.p_value for o in obs_list] + + bins = len(p_values) + x = np.arange(0, 1.001, 0.001) + plt.plot(x, x, 'k', zorder=1) + plt.xlim(0, 1) + plt.ylim(0, 1) + plt.xlabel('p-value') + plt.ylabel('Cumulative probability') + plt.title(str(bins) + ' p-values') + + n = np.arange(1, bins + 1) / np.float64(bins) + Xs = np.sort(p_values) + plt.step(Xs, n) + diffs = n - Xs + loc_max_diff = np.argmax(np.abs(diffs)) + loc = Xs[loc_max_diff] + plt.annotate('', xy=(loc, loc), xytext=(loc, loc + diffs[loc_max_diff]), arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0)) + plt.draw() + + print(scipy.stats.kstest(p_values, 'uniform'))
def ks_test(objects=None): + """Performs a Kolmogorov–Smirnov test for the p-values of all fit object. + + Parameters + ---------- + objects : list + List of fit results to include in the analysis (optional). + """ + + if objects is None: + obs_list = [] + for obj in gc.get_objects(): + if isinstance(obj, Fit_result): + obs_list.append(obj) + else: + obs_list = objects + + p_values = [o.p_value for o in obs_list] + + bins = len(p_values) + x = np.arange(0, 1.001, 0.001) + plt.plot(x, x, 'k', zorder=1) + plt.xlim(0, 1) + plt.ylim(0, 1) + plt.xlabel('p-value') + plt.ylabel('Cumulative probability') + plt.title(str(bins) + ' p-values') + + n = np.arange(1, bins + 1) / np.float64(bins) + Xs = np.sort(p_values) + plt.step(Xs, n) + diffs = n - Xs + loc_max_diff = np.argmax(np.abs(diffs)) + loc = Xs[loc_max_diff] + plt.annotate('', xy=(loc, loc), xytext=(loc, loc + diffs[loc_max_diff]), arrowprops=dict(arrowstyle='<->', shrinkA=0, shrinkB=0)) + plt.draw() + + print(scipy.stats.kstest(p_values, 'uniform')) +
Performs a Kolmogorov–Smirnov test for the p-values of all fit object.
+ +