LinearFitResult
The immutable result object returned by lin_fit. Its numerical fields describe one fit; its optional Matplotlib figure can still be edited and saved.
Public attributes
Attribute |
Meaning |
|---|---|
|
The fitted slope and intercept. |
|
Their standard uncertainties. |
|
Covariance between slope and intercept. |
|
Parameter correlation, or |
|
Read-only physical residuals, |
|
Square root of the residual sum of squares divided by |
|
Common vertical dispersion estimated in OLS; equals |
|
Weighted residual criterion, or |
|
|
|
Upper-tail chi-square probability, or |
|
Number of observations minus two. |
|
|
|
|
|
Matplotlib figure, or |
For x_error_method="iterate", parameter covariance, the band, and the interpretation of chi-squared and p-value belong to the historical effective-variance approximation. They are not validated York/ODR results. fit_method remains "wls" and estimated_sigma remains None.
normalize_residuals changes only the plot; residuals always keep the units of y. Changes to fitted fields through dataclasses.replace() are rejected when they would disagree with the retained fit. You may modify result.figure and save it separately; this does not update an earlier automatic PDF export.
Prediction
result = lin_fit(x, y, sigma_y, plot=False)
predicted = result.predict([1.0, 2.0, 3.0])
predict() accepts a finite real scalar or one-dimensional vector. It uses the retained local representation to preserve accuracy near large coordinate offsets.
TOML export
result.to_toml("fit_results.toml")
The destination directory must already exist. A missing extension becomes .toml; an existing destination is replaced atomically. The method returns the written Path.
The document contains the [mespy], [data], [fit], [diagnostics], [residuals] and [plot] tables. Input uncertainties are stored in their original form after scalar expansion, and floating-point results keep full precision. Undefined diagnostics are omitted. Figure edits and the full Matplotlib configuration are not serialized.
Without sigma_x, exports retain schema 2. With sigma_x, schema 3 also stores [data].sigma_x and [fit].x_error_method, including "none" when horizontal bars were only displayed.