Application Programming Interface (API)

nbi_stat Module

Module to help with various statistical choirs

This module contains many different functions and classes for statistical tasks, including

  • Robust and online mean and (co)variance calculations

  • Scientific rounding

  • Representation of results

  • Representation of data

  • Visualisation of data

  • Propagation of uncertainty

  • Sampling of arbitrary PDF

  • Histogramming

  • Fitting

  • Likelihood

  • Hypothesis testing

  • Simultanious fitting

  • Confidence intervals

Copyright © 2019 Christian Holm Christensen

2024-02-22 18:02:51.194062 UTC

Functions

abstractmethod(funcobj)

A decorator indicating abstract methods.

binned_llh(f, data, *theta[, logpdf, cdf, ...])

Calculate the binned logarithmic likelihood

binned_llh_c(n)

binned_llh_n(bins, data[, density])

cdf_cl(x, cdf, p[, direction])

Evaluate the confince interval from an evaluated CDF

chi2nu(x, y, f, theta[, delta, deltax, df, ...])

Calculate the chi-square over the sample (x,y)

corner_plot(*args, **kwargs)

Draw a corner plot of several variables.

cov(x, w[, ddof, frequency, component])

Calculated weighted covariance

curve_fit(f, x, y, p0[, dy, dx, df, ...])

Perform a non-linear least squares fit of f to data

dkl(p, q)

Calculate the Kullback-Leibler discrepancy (or relative entropy) of a discrete random variable with assumed probability p[i] and observed probability q[i]=n[i]/N

effective_variance(x, ex, f, p, ey[, df, ...])

Calculates the effective variance

eval_cdf(f, x[, dx, adjust, return_details])

Integrates the PDF f over the range x to get a table of the CDF

fc_cl(ranked, p[, fuzzy])

Estimate the confidence interval given using the Feldman-Cousine algorithm

fc_rank(pdf, measurement, hypothesis, best)

Calculates Feldman-Cousine rank of PDF with measurements, hypotheses, and best value

fill_histogram(x, bins, sumw[, sumw2, weight])

Fill a histogram

fini_histogram(bins, sumw[, sumw2, normalize])

Finalize histogram

fit(f, *args, **kwargs)

Unified interface for curve fitting

fit_plot(x, y, delta, f, p, ep[, xdelta, df])

Plot data and a fitted funtion

format_data_table(data[, columns, rows, ...])

Formats data into a LaTeX table

format_fit_result(p, ep[, parameters, ...])

Formats best-fit parameter values and uncertainties in a table.

format_result(value[, deltas, nsig, name, ...])

Function to pretty-format results

hist(data, **kwargs)

Calculates and plots a histogram of data

histo_pdf(x, y[, kind, extra, logpdf])

Generate a PDF function from a histogram

histogram(a[, bins, rnge, weights, ...])

Build a histogram of data in a

init_histogram(bins[, weighted])

Initialize a histogram structure

likelihood_ratio(lh_h1, lh_h0[, loglike])

Calculate the likelihood ratio of hypothesis H1 to H0

lin_fit(f, x, y[, delta])

Fit a linear model f to data

linfit(f, x, y[, delta])

Fit a linear model f to data

llh(f, x, *theta[, logpdf, extended, ...])

Calculate the logarithmic likelihood

lsq_fit(f, x, y, p0[, dy, dx, df, df_step, ...])

Perform a non-linear least squares fit of f to data

lsqfit(f, x, y, p0[, dy, dx, df, df_step, ...])

Perform a non-linear least squares fit of f to data

maximize_llh(f, data, p0, tomax[, kw])

Maximize a logarithmic likelihood function

mle_fit(f, data, p0, *args, **kwargs)

Do an MLE estimate of parameters of the PDF given data yield.

n_significant(num_or_string)

Determine the number of significant digits

nsigma_contour(p, cov[, n, nstep])

Calculate all n-sigma contours

nsigma_contour2(a, b, ea, eb, rho[, n, nstep])

Calculate the two parameter n-sigma contour

overall_sys_pdf(down, up[, mid, kind, ...])

A decorate that adds an overall systematic uncertainty to a PDF

pdf_sampler(f, x[, dx])

Creates a function to sample a PDF

plot_cdf_cl(x, theta, cdf, ps[, dirs, fig, ...])

Plots Confidence intervals of a CDF

plot_fit(x, y, delta, f, p, ep[, xdelta, df])

Plot data and a fitted funtion

plot_fit_detailed(x, y, ey, f, p, cov[, ax, ...])

Plot data, fit, residuals of fit, and contours of fit parameters.

plot_fit_func(x, f, p, cov, **kwargs)

Plot fit function with found parameters and (optional uncertainty band)

plot_fit_table(p, ep[, nsig, chi2nu, ...])

Plot a fit table in the current (or passed) axes

plot_hist(n, x, wx, en[, b, ax, as_bar])

Plot a histogram

plot_hist_with_poisson(n, x, wx, en[, ax, ...])

plot_nsigma_contour(p, cov[, ns, nstep, fig_kw])

Plot nsigma contour lines

plot_residual(x, y, f, p[, cov, ey])

Plot the residuls and uncertainty on function

print_result(x, deltas[, nsign, width])

Print a single result with uncertainties, properly rounded

propagate_uncertainty(f, x, delta[, step])

Propegate uncertainties on x to y

residual_plot(x, y, f, p[, cov, ey])

Plot the residuls and uncertainty on function

residuals(x, y, f, p[, ey])

Calculate the residuals with respect to some function

round(v[, n])

Round value(s) to the precision given by nbi_stat.py

round_result(x, deltas[, nsign])

Round result and associated uncertainties

round_result_expo(x, deltas[, nsign, expo])

sample_pdf(y, x, cdf)

Sample a PDF given by the table of the CDF

scale_pdf([logpdf])

Decorate to add norm to a PDF (any PDF)

scatter_hist2d(x, y, *args, **kwargs)

Draw a two-dimensional sample histogrammed as a scatter plot

sel_llh(data, kwargs)

shape_sys_pdf(down, up[, mid, ev, kind, ...])

A decorate that adds a shape systematic uncertainty to a PDF

simul_mle_fit(regions, p0, *args, **kwargs)

Perform simulatinous MLE fit over several regions

welford_init([ndim, covar])

Initialize a structure for use with welford_update

welford_merge(ma, cva, na, mb, cvb, nb[, ddof])

Merge two statistics into one

welford_update(x, mean, covar, n[, ddof, z])

Calculates running average and (co)variance by Welfords algorithm

west_init([ndim, covar, frequency, component])

Initialize a data-structure for use with west_update

west_merge(meana, cova, sumwa, sumw2a, ...)

Merge two statistics into one

west_update(x, w, mean, cv, sumw[, sumw2, ...])

Do a West online update of mean and (co)variance of the weighted sample.

Classes

ABC()

Helper class that provides a standard way to create an ABC using inheritance.

Histogram(bins[, weighted])

A 1 dimensional histogram class

Stat([covar, ddof])

Base class for statistics classes

StatDict()

A utility class for converting stat objects to and from dictionaries.

Welford(ndim[, covar, ddof])

An unweighted sample statistics

West(ndim[, covar, frequency, component, ddof])

An weighted sample statistics

WestIO()

rv_continuous([momtype, a, b, xtol, ...])

A generic continuous random variable class meant for subclassing.

rv_numerical(f, xev[, dx, adjust])

Class Inheritance Diagram

digraph inheritancea834c9d1b4 { bgcolor=transparent; rankdir=LR; size="8.0, 12.0"; "ABC" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Helper class that provides a standard way to create an ABC using"]; "Histogram" [URL="api/nbi_stat.Histogram.html#nbi_stat.Histogram",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A 1 dimensional histogram class"]; "Stat" [URL="api/nbi_stat.Stat.html#nbi_stat.Stat",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="Base class for statistics classes"]; "ABC" -> "Stat" [arrowsize=0.5,style="setlinewidth(0.5)"]; "StatDict" [URL="api/nbi_stat.StatDict.html#nbi_stat.StatDict",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="A utility class for converting stat objects to "]; "Welford" [URL="api/nbi_stat.Welford.html#nbi_stat.Welford",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="An unweighted sample statistics"]; "Stat" -> "Welford" [arrowsize=0.5,style="setlinewidth(0.5)"]; "West" [URL="api/nbi_stat.West.html#nbi_stat.West",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top",tooltip="An weighted sample statistics"]; "Stat" -> "West" [arrowsize=0.5,style="setlinewidth(0.5)"]; "WestIO" [URL="api/nbi_stat.WestIO.html#nbi_stat.WestIO",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "rv_continuous" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="A generic continuous random variable class meant for subclassing."]; "rv_generic" -> "rv_continuous" [arrowsize=0.5,style="setlinewidth(0.5)"]; "rv_generic" [fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",tooltip="Class which encapsulates common functionality between rv_discrete"]; "rv_numerical" [URL="api/nbi_stat.rv_numerical.html#nbi_stat.rv_numerical",fillcolor=white,fontname="Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans",fontsize=10,height=0.25,shape=box,style="setlinewidth(0.5),filled",target="_top"]; "rv_continuous" -> "rv_numerical" [arrowsize=0.5,style="setlinewidth(0.5)"]; }