Re: Equivalent of EXCEL LINEST function? [message #24775] |
Mon, 23 April 2001 13:09  |
Bruce Bowler
Messages: 128 Registered: September 1998
|
Senior Member |
|
|
Craig Markwardt wrote:
> However using REGRESS may be like killing a fly with a shotgun, a bit
> of overkill.
>
> Why not use LINFIT and CORRELATE, which standard IDL functions?
>
> p = linfit(x,y, sigma=dp) ;; DP are parameter uncertainties
> r2 = correlate(x,y)
Jeopardy style answer...
what is "because the IDL documentation stinks?"
I wanted to regress 2 vectors so I go into the online help in 5.3 (which
is what I'm using) and type regress. Up pops the REGRESS function. No
where does the REGRESS help mention LINFIT or CORRELATE.
After "rolling my own", I find them and they do (almost) what I want.
They don't (like LINEST in excel, or "my own") provide standard errors
of the coefficents, the constant and Y estimate and a few other little
bits.
|
|
|
Re: Equivalent of EXCEL LINEST function? [message #24781 is a reply to message #24775] |
Fri, 20 April 2001 17:30   |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Bruce Bowler <bbowler@bigelow.org> writes:
> So it is... now for "stupid question #347" (tm).
>
> How do I turn a vector (which is what I have for x) into an array?
>
> help, x
> x float = array[12345]
> help, y
> y float = array[12345]
> weight = replicate(1.0,n_elements(y))
> help, weight
> weight float = array[12345]
> result = regress(x,y,weight,/relative_weight)
> % REGRESS: Incompatable arrays.
>
> Looking at the code for regress, the only condition I violate to cause
> that message is that my X is only 1 dimenesion, not 2...
Probably you want to REFORM the vector into an array ( = reform(x,1,n))
However using REGRESS may be like killing a fly with a shotgun, a bit
of overkill.
Why not use LINFIT and CORRELATE, which standard IDL functions?
p = linfit(x,y, sigma=dp) ;; DP are parameter uncertainties
r2 = correlate(x,y)
Done!
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|
Re: Equivalent of EXCEL LINEST function? [message #24786 is a reply to message #24781] |
Fri, 20 April 2001 11:05   |
Bruce Bowler
Messages: 128 Registered: September 1998
|
Senior Member |
|
|
So it is... now for "stupid question #347" (tm).
How do I turn a vector (which is what I have for x) into an array?
help, x
x float = array[12345]
help, y
y float = array[12345]
weight = replicate(1.0,n_elements(y))
help, weight
weight float = array[12345]
result = regress(x,y,weight,/relative_weight)
% REGRESS: Incompatable arrays.
Looking at the code for regress, the only condition I violate to cause
that message is that my X is only 1 dimenesion, not 2...
Hey it's late Friday and my brain is mush, I can't see straight, and my
back hurts, what can I say???
Bruce
Med Bennett wrote:
>
> I believe the IDL function is REGRESS or REGRESSION, I haven't checked
> lately though.
>
> Bruce Bowler wrote:
>
>> I'm probably just having a brain cramp but I can't figure out how to do
>> something that seems as simple as the EXCEL function LINEST.
>>
>> Basically, I have an X vector and a Y vector and I want to find the
>> linear "best fit" function, the r^2 of that fit, and the standard errors
>> of all the parameters. (I could do it all by writing my own routines,
>> but I'm *SURE* that someone has already done it, you know, steal from
>> your friends :-)
>>
>> Thanks!
>> Bruce
|
|
|
|
Re: Equivalent of EXCEL LINEST function? [message #24874 is a reply to message #24775] |
Mon, 23 April 2001 13:46  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
Bruce Bowler <bbowler@bigelow.org> writes:
> I wanted to regress 2 vectors so I go into the online help in 5.3 (which
> is what I'm using) and type regress. Up pops the REGRESS function. No
> where does the REGRESS help mention LINFIT or CORRELATE.
I agree, I was a little surprised that the REGRESS docs didn't mention
LINFIT, since LINFIT is the degenerate case of one dimension.
> After "rolling my own", I find them and they do (almost) what I want.
> They don't (like LINEST in excel, or "my own") provide standard errors
> of the coefficents, the constant and Y estimate and a few other little
> bits.
Umm, here I think I have to disagree. The SIGMA keyword provides the
errors of the coefficients, as my example showed. The R^2 constant is
directly from CORRELATE, so I'm not sure your complaint here. And
finally,
YFIT = A*X + B
Sometimes things are simple enough that having a canned procedure to
do them is overkill. :-)
Craig
--
------------------------------------------------------------ --------------
Craig B. Markwardt, Ph.D. EMAIL: craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
------------------------------------------------------------ --------------
|
|
|