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)
|