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