[SciPy-Dev] parameters of fitting data
James Phillips
zunzun@zunzun....
Tue Nov 22 16:23:39 CST 2011
I dug up some old code that should point you in the right direction. Look
over the ODR example in scipy and this should make some sense to you.
# see both scipy.odr.odrpack and
http://www.scipy.org/Cookbook/OLS
# this is inefficient but works for every possible case
model = scipy.odr.odrpack.Model(function)
data = scipy.odr.odrpack.Data(indepData, depData])
myodr = scipy.odr.odrpack.ODR(data, model,
beta0=solvedCoefficients, maxit=0)
myodr.set_job(fit_type=2)
parameterStatistics = myodr.run()
self.cov_beta = parameterStatistics.cov_beta # parameter
covariance matrix
try:
self.sd_beta = parameterStatistics.sd_beta *
parameterStatistics.sd_beta
except:
self.sd_beta = None
self.ci = [] # 95% confidence intervals
t_df = scipy.stats.t.ppf(0.975, self.df_e)
for i in range(len(self.solvedCoefficients)):
self.ci.append([self.solvedCoefficients[i] - t_df *
parameterStatistics.sd_beta[i], self.solvedCoefficients[i] + t_df *
parameterStatistics.sd_beta[i]])
try:
self.tstat_beta = self.solvedCoefficients /
parameterStatistics.sd_beta # coeff t-statistics
except:
self.tstat_beta = None
try:
self.pstat_beta = (1.0 -
scipy.stats.t.cdf(numpy.abs(self.tstat_beta), self.df_e)) * 2.0 # coef.
p-values
except:
self.pstat_beta = None
James
http://zunzun.com
On Tue, Nov 22, 2011 at 2:56 PM, Krzysztof Berniak <
krzysztof.berniak@gmail.com> wrote:
> Hello,
> I'm writing script in python, which fitting exponencial curve to data (
> f(x) = a*exp(x*b).
> To resolve this problem I use scipy.
> It works fine. I get in v1 new parameters, but where is calculation
> errors of this parameters ?
>
> When I use gnuplot my results look like this:
> Final set of parameters Asymptotic Standard Error
> ======================= ==========================
>
> a1 = 12.1566 +/- 0.2286
> (1.88%)
> b1 = 0.000858396 +/- 4.362e-006
> (0.5082%)
>
> ^
>
>
> |
> where in
> scipy i get this numbers
>
> This is my code
> def main():
> z,f = numbers_col()
> fitfunc = lambda v, z: v[0]*exp(z*v[1])
> errfunc = lambda v, z,f: fitfunc(v,z) - f
> v0 = [10., 0.005]
> v1,success = optimize.leastsq(errfunc, v0[:], args =
> (z,f),full_output=True)
>
> regards and please help,
> Cristopher
>
> _______________________________________________
> SciPy-Dev mailing list
> SciPy-Dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-dev/attachments/20111122/c5d0fadd/attachment.html
More information about the SciPy-Dev
mailing list