Frage

I'm kind of new to Python and I want to find the root of an linear fit function inclusive errors.

I fitted the function with

import numpy as np
import scipy.optimize as op

def lin_fit(x, a, b):
    return a * x + b

...

popt, pconv = op.curve_fit(lin_fit, U, sqrt_I)
x = np.linspace(np.min(U), np.max(U), 100)
y = lin_fit(x, *popt)

Then I found the root with

def root(x):
    return lin_fit(x, *popt)

return op.fsolve(root, 0)

That was no problem, but I don't now, how to find the error of these roots.

Can anyone help?

War es hilfreich?

Lösung

The error is contained in pconv, where the diagonal contains the variance for each one estimated coefficients, which in this case are a and b.

From the MathWorld the correlation coefficient r which measures the overall quality of the fit can be computed as:

sxy = pconv[0,1]*x.shape[0]
sxx = pconv[0,0]
syy = pconv[1,1]
r = (sxy**2/(sxx*syy))**0.5
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top