comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » CURVEFIT.PRO standard deviations?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
CURVEFIT.PRO standard deviations? [message #30670] Fri, 10 May 2002 21:51
Ralf Flicker is currently offline  Ralf Flicker
Messages: 19
Registered: October 2001
Junior Member
Folks, I'm at wits' end here, don't know what's going on.

I need to do a chi-square minimization curve fitting of a nonlinear
parametrized function to noisy data. Using the routine CURVEFIT.PRO
works admirably for the fitting itself, and the chi-square comes out
ok, but the values returned for the standard deviations (sigma
optional argument) on the fitted coefficients just don't make sense
to me.

Looking at the source code (idl 5.3) and comparing with the
Levenberg-Marquardt algorithm in Numerical Recipes (ch 15.5), I am
still unable to pinpoint the error (whether in my code or in my
admittedly lacking understanding of chi-square statistics..).

So here's a code I wrote (FTEST.PRO) for testing CURVEFIT versus a
routine I know works, LINFIT. It generates a noisy straight line,
fits a line using both LINFIT and CURVEFIT, and plots both fits
together with the fits offset by one sigma on the coefficients.

You can see the discrepancy in the one-sigma lines: can someone tell
me what's up with the sigma returned from CURVEFIT, and how I can
make them conform?


ralf


;===============================================
; straight line
pro fline,x,a,f,pder
f = a(0)+x*a(1)
end

;===============================================
; Test of CURVEFIT vs. LINFIT
pro ftest,noise

; sample calling sequence : ftest,0.4

; generate noisy line
f0 = (findgen(25)*3.-15)*(1.+randomn(seed,25)*noise)
x = findgen(25)
loadct,4
plot,x,f0,xstyle=2,psym=-1

; straight-line chi-square fitting with LINFIT.PRO
a = linfit(x,f0,chisq=csq,sigma=sig)
fline,x,a,f & oplot,x,f,color=80
fline,x,[a+sig],f & oplot,x,f,linestyle=2,color=80
fline,x,[a-sig],f & oplot,x,f,linestyle=2,color=80
print,'LINFIT parameters, sigma, and chi-square : '
print,a,sig,csq

; Levenberg-Marquardt chi-square fitting
;of straight line with CURVEFIT.PRO
a = [0.,1.]
weights = fltarr(n_elements(x))+1.
f=curvefit(x,f0,weights,a,sig,function_name='fline',chisq=cs q,/noderivative)
oplot,x,f,color=200
oplot,x,a(0)+sig(0)+x*(a(1)+sig(1)),linestyle=2,color=200
oplot,x,a(0)-sig(0)+x*(a(1)-sig(1)),linestyle=2,color=200
print,'CURVEFIT parameters, sigma, and chi-square : '
print,a,sig,csq

end
;===============================================

(recombine as necessary)
[Message index]
 
Read Message
Previous Topic: Beta version of the IDL/CSPICE interface (Icy)
Next Topic: Call_External and referenced symbol not found

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Thu Oct 09 07:18:05 PDT 2025

Total time taken to generate the page: 1.59787 seconds