Curvefit [message #9041] |
Wed, 21 May 1997 00:00  |
zanotti
Messages: 5 Registered: May 1997
|
Junior Member |
|
|
Hi,
I use CURVEFIT (on PV-WAVE CL Version 6.05 (sun4 solaris sparc)) to perform non-linear least sqares fitting. It works rather well, but once the fit is performed, the vector of standard deviations for parameters (named Sigmaa) seems to give very large values:
for a given set of data, the error on parameters is ten times greater with Curvefit than, for exemple, with Kaleidagraph.
In fact, Curvefit is based on the Gradient-expansion algorithm, and the way the programm calculates the error (i.e SIGMAA = SQRT(ARRAY(DIAG)/ALPHA(DIAG)) ) is perharps wrong (something missing ???).
Does anybody has an idea ?
Thanks for help.
J.Marc
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/_/_/_/ Jean-Marc Zanotti _/ _/_/_/
_/_/_/_/ Laboratoire Leon Brillouin _/_/_/_/
_/_/_/_/ C.E.A Saclay _/_/_/_/
_/_/_/_/ F-91191 Gif-sur-Yvette Cedex _/_/_/_/
_/_/_/_/ _/_/_/_/
_/_/_/_/ Tel:(33)(0)1-69-08-97-01 _/_/_/_/
_/_/_/_/ Fax:(33)(0)1-69-08-82-61 _/_/_/_/
_/_/_/_/ Email: zanotti@bali.saclay.cea.fr _/_/_/_/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
|
|
|
Re: Curvefit [message #9043 is a reply to message #9041] |
Wed, 21 May 1997 00:00   |
thompson
Messages: 584 Registered: August 1991
|
Senior Member |
|
|
zanotti@bali.saclay.cea.fr (J.M. Zanotti) writes:
> Hi,
> I use CURVEFIT (on PV-WAVE CL Version 6.05 (sun4 solaris sparc)) to perform
> non-linear least sqares fitting. It works rather well, but once the fit is
> performed, the vector of standard deviations for parameters (named Sigmaa)
> seems to give very large values:
> for a given set of data, the error on parameters is ten times greater with
> Curvefit than, for exemple, with Kaleidagraph.
> In fact, Curvefit is based on the Gradient-expansion algorithm, and the way
> the programm calculates the error (i.e SIGMAA = SQRT(ARRAY(DIAG)/ALPHA(DIAG))
> ) is perharps wrong (something missing ???).
> Does anybody has an idea ?
It probably depends on the weighting function that you give it. If the weights
are related to true errors on the measurements, i.e. 1/sigma^2, then the SIGMAA
values should normally be realistic. However, if the weights have an arbitrary
normalization, then the SIGMAA values will also be off. A good test is to look
at the chi-squared value, which is returned in the keyword CHI2. Realistic
weights should result in a chi-squared close to 1. If far away from 1, then
the SIGMAA values will be off as well. One way to adjust for this is to
multiply the SIGMAA values by SQRT(CHI2).
Bill Thompson
|
|
|
|
Re: CURVEFIT [message #39642 is a reply to message #9041] |
Wed, 02 June 2004 11:40   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Andreas Ernst <aernst@ari.nis> writes:
> Hi,
>
> (1) I am using CURVEFIT to fit a straight line
> through my data points. My user-supplied
> function looks like this:
>
> PRO gerade, X, A, F, PDER
> F=A[0]+A[1]*X
> IF N_PARAMS() GE 4 THEN $
> PDER = [[REPLICATE(1.0, N_ELEMENTS(X))], [X]]
> RETURN
> END
>
> Anyway, even though it defines a straight line,
> the routine CURVEFIT seems to fit some other
> curve through the data points, which is something
A linear fit is trivial, and CURVEFIT shouldn't produce problems like
you found. My guess is that it is more likely that you have a data
handling problem. For example, if you perform a data selection on the
X values but forget to do the same for the Y values.
As the other poster said, you can use LINFIT/POLYFIT* to do the simple
fits you desire.
For more complicated fits, or as a cross check, you can use my own
fitting program, MPFIT + MPCURVEFIT, which have a wide acknowledgement
in the IDL community. As a combination, they are a drop-in
replacement for CURVEFIT (although if you don't have the requirement
to keep CURVEFIT compatibility, then I recommend using MPFITFUN).
Happy fitting!
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
|
Re: curvefit [message #44403 is a reply to message #9041] |
Tue, 14 June 2005 09:16  |
Paolo Grigis
Messages: 171 Registered: December 2003
|
Senior Member |
|
|
nolan.smith1@gmail.com wrote:
> I spoke too soon!
> So I have set up my function:
> (the model I am trying to fit is y=a/((1+(x/b))^2) )
>
> FUNCTION myfun,X,P
> RETURN,P(0)/(1+(X/P(1))^2)
> END
>
> and then I try to run
>
> result=MPFITFUN('myfun',x,y,0.5,0.01)
The 4th argument should be an array with the errors on y and the
5th argument an array with the estimates for the parameters,
so try something like:
err=replicate(1,n_elements(x));constant errors in y
par=[0.5,0.01];parameter estimate
result=MPFITFUN('myfun',x,y,err,par)
>
> Where x,y are my x,y coordinates of the data that I am trying to fit,
> 0.5 is the first guess for P(0) and 0.01 is the first guess for P(1).
> As you guessed it is not working. What am I doing wrong?
>
> Thank you,
> Nolan
>
|
|
|
Re: curvefit [message #44408 is a reply to message #9041] |
Tue, 14 June 2005 08:20  |
nolan.smith1
Messages: 12 Registered: June 2005
|
Junior Member |
|
|
I spoke too soon!
So I have set up my function:
(the model I am trying to fit is y=a/((1+(x/b))^2) )
FUNCTION myfun,X,P
RETURN,P(0)/(1+(X/P(1))^2)
END
and then I try to run
result=MPFITFUN('myfun',x,y,0.5,0.01)
Where x,y are my x,y coordinates of the data that I am trying to fit,
0.5 is the first guess for P(0) and 0.01 is the first guess for P(1).
As you guessed it is not working. What am I doing wrong?
Thank you,
Nolan
|
|
|
Re: curvefit [message #44427 is a reply to message #9041] |
Mon, 13 June 2005 21:02  |
nolan.smith1
Messages: 12 Registered: June 2005
|
Junior Member |
|
|
Thank you!
I had a little typo in the function that I gave you,
it is y(x)=A/(1+x/B)^2.
Your answer was really helpful so thanks again!!!
Nolan
Vinay L. Kashyap wrote:
> In article <1118691431.765056.244800@f14g2000cwb.googlegroups.com>,
> <nolan.smith1@gmail.com> wrote:
>> Hello,
>>
>> I am new in IDL and I am trying to fit my data (x,y coordinates) in a
>> function of this form:
>>
>> y(x)=A/[(1+x/B)^1/2]^2
>>
>> so that I can calculate A and B.
>>
>> I have read the documentation but I am very confused as to how I should
>> set up my function to use it at the curvefit.
>> Could you please explain to me how to set up the function and how to
>> use curvefit correctly?
>>
>> Thank you,
>> Nolan Smith
>>
>
> Create a new procedure, say testfun.pro:
>
> pro testfun,x,y,par,dfdpar
> y=par[0]/((1+x/par[1])^(1./2.))^2
> ;question: why is this not y=par[0]/(1+x/par[1]) ?
> dfdpar=fltarr(n_elements(x),2)
> dfdpar[*,0]=y/par[0]
> dfdpar[*,1]= {partial}y/{partial}B ..
> ;calculation left as an exercise for the reader!
> return
> end
>
> and then call curvefit as
> yfit=curvefit(x,y,weights,par,function_name='testfun')
>
> vinay
> --
> ____________________________________________________________ __________________
> kashyap@head.cfa.harvard.edu 617 495 7173 [CfA/P-145] 617 496 7173 [F]
|
|
|
Re: curvefit [message #44429 is a reply to message #9041] |
Mon, 13 June 2005 20:07  |
nolan.smith1
Messages: 12 Registered: June 2005
|
Junior Member |
|
|
It was really helpful. I just wanted a little more details on how to
set up the function but now I understand it better.
Thank you for the help,
Nolan
|
|
|
Re: curvefit [message #44434 is a reply to message #9041] |
Mon, 13 June 2005 15:24  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
nolan.smith1@gmail.com writes:
> Thank you. I had already looked at those routines as well but the
> problems I had with those routines were the same with the curvefit
> routine.
> I do not know how set up the function correctly and use it in the
> curvefit or mpcurvefit program.
Greetings,
Did this tutorial page not help?
http://cow.physics.wisc.edu/~craigm/idl/mpfittut.html
Yours,
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: curvefit [message #44437 is a reply to message #9041] |
Mon, 13 June 2005 14:50  |
kashyap
Messages: 26 Registered: April 1993
|
Junior Member |
|
|
In article <1118691431.765056.244800@f14g2000cwb.googlegroups.com>,
<nolan.smith1@gmail.com> wrote:
> Hello,
>
> I am new in IDL and I am trying to fit my data (x,y coordinates) in a
> function of this form:
>
> y(x)=A/[(1+x/B)^1/2]^2
>
> so that I can calculate A and B.
>
> I have read the documentation but I am very confused as to how I should
> set up my function to use it at the curvefit.
> Could you please explain to me how to set up the function and how to
> use curvefit correctly?
>
> Thank you,
> Nolan Smith
>
Create a new procedure, say testfun.pro:
pro testfun,x,y,par,dfdpar
y=par[0]/((1+x/par[1])^(1./2.))^2
;question: why is this not y=par[0]/(1+x/par[1]) ?
dfdpar=fltarr(n_elements(x),2)
dfdpar[*,0]=y/par[0]
dfdpar[*,1]= {partial}y/{partial}B ..
;calculation left as an exercise for the reader!
return
end
and then call curvefit as
yfit=curvefit(x,y,weights,par,function_name='testfun')
vinay
--
____________________________________________________________ __________________
kashyap@head.cfa.harvard.edu 617 495 7173 [CfA/P-145] 617 496 7173 [F]
|
|
|
Re: curvefit [message #44440 is a reply to message #9041] |
Mon, 13 June 2005 12:59  |
nolan.smith1
Messages: 12 Registered: June 2005
|
Junior Member |
|
|
Thank you. I had already looked at those routines as well but the
problems I had with those routines were the same with the curvefit
routine.
I do not know how set up the function correctly and use it in the
curvefit or mpcurvefit program.
Any help will be greatly appreciated.
Thank you,
Nolan
|
|
|
Re: curvefit [message #44441 is a reply to message #9041] |
Mon, 13 June 2005 12:46  |
Benjamin Hornberger
Messages: 258 Registered: March 2004
|
Senior Member |
|
|
nolan.smith1@gmail.com wrote:
> Hello,
>
> I am new in IDL and I am trying to fit my data (x,y coordinates) in a
> function of this form:
>
> y(x)=A/[(1+x/B)^1/2]^2
>
> so that I can calculate A and B.
>
> I have read the documentation but I am very confused as to how I should
> set up my function to use it at the curvefit.
> Could you please explain to me how to set up the function and how to
> use curvefit correctly?
>
> Thank you,
> Nolan Smith
>
Most people use Craig Markwardt's fitting routines rather than the ones
provided with IDL:
http://cow.physics.wisc.edu/~craigm/idl/idl.html
Good luck,
Benjamin
|
|
|