fit_utils.py

fit_utils.py contains the package’s weighted linear fit and its associated return type. It is the densest module in the project because it combines statistics, input validation, and optional plotting, while also reusing the style system defined in plot_utils.

Main imports

What it exports

What it does

  • validate x, y, sigma_y, and optionally sigma_x

  • validate decimals, tol, and max_iter

  • estimate slope and intercept with weighted least squares

  • update the weights iteratively when uncertainties on x are also present

  • compute residuals, chi2, reduced_chi2, correlation, and other diagnostics

  • create, when requested, a matplotlib figure with a fit panel and a residuals panel, using the same style system as histogram

Related helpers

Detailed pages