5

I am using orthogonal distance regression method(scipy.odr) to fit my data, after fit, I have trouble in calculate the 95% confidence interval, please help me no how to calculate it~

here the code:

#define fit function
def def f(p,x):
    return p*x
linear = scipy.odr.Model(f)
mydata = scipy.odr.RealData(x, y, sx=dx, sy=dy)
myodr = scipy.odr.ODR(mydata, linear, beta0=[1.])
myoutput = myodr.run()
myoutput.pprint()
[solpe] = myoutput.beta

now I get solpe, get the fitted function: y=p*x,but how should I get 95% confidence interval?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Owen
  • 397
  • 7
  • 18
  • well, you can use `curve_fit` from `scipy.optimize` which will give you the covariance matrix of your best fit parameters, which you can then use to get the 95% confidence intervals – Srivatsan Nov 29 '14 at 14:46
  • but how can i get confidence intervals by using scipy.odr? – Owen Dec 01 '14 at 07:01
  • As far as I can see, `scipy.odr` does have it's `Output` class that you can find http://docs.scipy.org/doc/scipy-0.14.0/reference/generated/scipy.odr.Output.html#scipy.odr.Output. Here in the attributes section, you can find `cov_beta` which gives you the covariance matrix of the estimated parameters. So the `sqrt` of your covariance diagonal elements will give you the `1sigma` (68%) error. For 95%, convert accordingly – Srivatsan Dec 01 '14 at 09:09
  • thank you, but how to convert exactly to 95%?@ThePredator – Owen Dec 09 '14 at 02:33
  • [THIS answer should help](http://stackoverflow.com/questions/24633664/confidence-interval-for-exponential-curve-fit) – Srivatsan Dec 09 '14 at 09:11

0 Answers0