Re: least square error for a regression [message #41037] |
Wed, 15 September 2004 20:50 |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
"yaj" <tgupta2000@hotmail.com> writes:
> Hello,
> I am fitting a function of the form
> ASin(wt + theta) + constant to a set of points. Instead of a readymade
> fitting routine from IDL (to avoid any potential problems with small numbers
> later), I use the three linear equations to minimize the least square error,
> then use an IDL function to solve the matrix equation. Could someone suggest
> a simple way to calculate the least squares error and goodness of fit using
> some higher level IDL functions ?
Pardon me for asking, but which "small numbers" problems are you
hoping to avoid? If you are able to linearize your problem yourself,
as you seem to have done, then I believe that a routine like CURVEFIT
or MPFIT should do just fine at estimating the parameters and
returning the uncertainties. And these routines have the added
benefit of tested by years of use.
Happy fitting,
Craig
http://cow.physics.wisc.edu/~craigm/idl/idl.html
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@REMOVEcow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: least square error for a regression [message #41040 is a reply to message #41037] |
Wed, 15 September 2004 17:25  |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
In article <ciafmg$al3$1@sunburst.ccs.yorku.ca>,
"yaj" <tgupta2000@hotmail.com> wrote:
> Hello,
> I am fitting a function of the form
> ASin(wt + theta) + constant to a set of points. Instead of a readymade
> fitting routine from IDL (to avoid any potential problems with small numbers
> later), I use the three linear equations to minimize the least square error,
> then use an IDL function to solve the matrix equation. Could someone suggest
> a simple way to calculate the least squares error and goodness of fit using
> some higher level IDL functions ?
> Thanks in advance
> Y. Bhattacharya
> yajnaval_at-hotmail
>
>
I think you want something like this:
n = 32
eps = 0.1D0
x = DINDGEN(n)/n
y = COS(2.0D0*!DPI*x - !DPI/4) + eps*RANDOMN(seed, n, /DOUBLE)
c = COS(2.0*!PI*x)
s = SIN(2.0*!PI*x)
f = TRANSPOSE([[c], [s]])
coeff = REGRESS(f, y, CONST = a0, YFIT = yfit, CHISQ = chisq, FTEST =
ftest, /DOUBLE)
a = coeff[0]
b = coeff[1]
amp = SQRT(a^2 + b^2)
phz = ATAN(b, a)
PRINT, a0, a, b, amp, phz, chisq, ftest
PLOT, x, y
OPLOT, x, yfit
Regards, Ken Bowman
|
|
|