Re: How to plot linear regression relation of two array? [message #65032] |
Mon, 09 February 2009 15:09 |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Feb 9, 3:21 pm, Hu <jha...@gmail.com> wrote:
> On Feb 9, 1:13 pm, Vince Hradil <vincehra...@gmail.com> wrote:
>
>
>
>> On Feb 9, 2:51 pm, Hu <jha...@gmail.com> wrote:
>
>>> On Feb 9, 12:12 pm, Vince Hradil <vincehra...@gmail.com> wrote:
>
>>>> On Feb 9, 1:45 pm, Hu <jha...@gmail.com> wrote:
>
>>>> > Hi,
>
>>>> > I am trying to plot a linear regression relation of two array
>>>> > (supposing A and B) by using IDL. What I want is to got a chart like
>>>> > this link shows (the group is unable to post figure directly):http://serc.carleton.edu/images/introgeo/teachingw data/LeastSquaresGr...
>
>>>> > especially, How can I got the black straight line and the coefficients
>>>> > R^2 ?
>
>>>> > Thanks
>
>>>> Have you looked in the help for linfit()?
>
>>> BTW, I set MEASURE_ERRORS to SQRT(ABS(Y)), just follow the example,
>>> but what is MEASURE_ERRORS? and what is R^2 mean in the above picture?
>
>>> Thank you very much
>
>> Sounds like you're using REGRESS() not LINFIT()?
>
>> I'd use LINFIT() to get the nice line
>> and use CORRELATE() to get the Pearson correlation coefficient. I
>> think CORRELATE() gives you the Pearson correlation coefficient, r,
>> which, in this case can be squared to get R^2.
>
> I use Linfit(), this function need a MEASURE_ERRORS parameter to run.
> Anyway, I will try your suggestion, CORRELATE()
>
> Tnaks
Oh right, I've just never used it. Maybe these will help?
http://en.wikipedia.org/wiki/Linear_regression
http://en.wikipedia.org/wiki/Coefficient_of_determination
|
|
|
Re: How to plot linear regression relation of two array? [message #65033 is a reply to message #65032] |
Mon, 09 February 2009 14:39  |
pgrigis
Messages: 436 Registered: September 2007
|
Senior Member |
|
|
With all due respect, if you don't know
what R^2 is, why do you want to put
it in your plot? What will you do when
somebody asks you "what is R"?
Ciao,
Paolo
Hu wrote:
> On Feb 9, 12:12 pm, Vince Hradil <vincehra...@gmail.com> wrote:
>> On Feb 9, 1:45 pm, Hu <jha...@gmail.com> wrote:
>>
>>> Hi,
>>
>>> I am trying to plot a linear regression relation of two array
>>> (supposing A and B) by using IDL. What I want is to got a chart like
>>> this link shows (the group is unable to post figure directly):http://serc.carleton.edu/images/introgeo/teachingw data/LeastSquaresGr...
>>
>>> especially, How can I got the black straight line and the coefficients
>>> R^2 ?
>>
>>> Thanks
>>
>> Have you looked in the help for linfit()?
>
> BTW, I set MEASURE_ERRORS to SQRT(ABS(Y)), just follow the example,
> but what is MEASURE_ERRORS? and what is R^2 mean in the above picture?
>
> Thank you very much
|
|
|
Re: How to plot linear regression relation of two array? [message #65040 is a reply to message #65033] |
Mon, 09 February 2009 13:21  |
Hu
Messages: 35 Registered: January 2009
|
Member |
|
|
On Feb 9, 1:13 pm, Vince Hradil <vincehra...@gmail.com> wrote:
> On Feb 9, 2:51 pm, Hu <jha...@gmail.com> wrote:
>
>
>
>> On Feb 9, 12:12 pm, Vince Hradil <vincehra...@gmail.com> wrote:
>
>>> On Feb 9, 1:45 pm, Hu <jha...@gmail.com> wrote:
>
>>>> Hi,
>
>>>> I am trying to plot a linear regression relation of two array
>>>> (supposing A and B) by using IDL. What I want is to got a chart like
>>>> this link shows (the group is unable to post figure directly):http://serc.carleton.edu/images/introgeo/teachingw data/LeastSquaresGr...
>
>>>> especially, How can I got the black straight line and the coefficients
>>>> R^2 ?
>
>>>> Thanks
>
>>> Have you looked in the help for linfit()?
>
>> BTW, I set MEASURE_ERRORS to SQRT(ABS(Y)), just follow the example,
>> but what is MEASURE_ERRORS? and what is R^2 mean in the above picture?
>
>> Thank you very much
>
> Sounds like you're using REGRESS() not LINFIT()?
>
> I'd use LINFIT() to get the nice line
> and use CORRELATE() to get the Pearson correlation coefficient. I
> think CORRELATE() gives you the Pearson correlation coefficient, r,
> which, in this case can be squared to get R^2.
I use Linfit(), this function need a MEASURE_ERRORS parameter to run.
Anyway, I will try your suggestion, CORRELATE()
Tnaks
|
|
|
Re: How to plot linear regression relation of two array? [message #65041 is a reply to message #65040] |
Mon, 09 February 2009 13:20  |
David Fanning
Messages: 11724 Registered: August 2001
|
Senior Member |
|
|
Hu writes:
> Yes, I use function linfit() to get the parameters a and b (Y=3Da+b*X)
> But How can I get the R^2 ?
R is the correlation coefficient. I typically get
it from CORRELATE:
params = LinFit(x, y, /DOUBLE)
r = Correlate(x, y, /DOUBLE)
r_sqrd = r^2
You can put it on to your plot with XYOUTS:
XYOUTS, 0.1, 0.9, /NORMAL, 'R^2 = ' + $
StrTrim(String(r_sqrd, FORMAT='(F8.2)'),2)
Cheers,
David
--
David Fanning, Ph.D.
Coyote's Guide to IDL Programming (www.dfanning.com)
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
|
|
|
Re: How to plot linear regression relation of two array? [message #65042 is a reply to message #65041] |
Mon, 09 February 2009 13:13  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Feb 9, 2:51 pm, Hu <jha...@gmail.com> wrote:
> On Feb 9, 12:12 pm, Vince Hradil <vincehra...@gmail.com> wrote:
>
>> On Feb 9, 1:45 pm, Hu <jha...@gmail.com> wrote:
>
>>> Hi,
>
>>> I am trying to plot a linear regression relation of two array
>>> (supposing A and B) by using IDL. What I want is to got a chart like
>>> this link shows (the group is unable to post figure directly):http://serc.carleton.edu/images/introgeo/teachingw data/LeastSquaresGr...
>
>>> especially, How can I got the black straight line and the coefficients
>>> R^2 ?
>
>>> Thanks
>
>> Have you looked in the help for linfit()?
>
> BTW, I set MEASURE_ERRORS to SQRT(ABS(Y)), just follow the example,
> but what is MEASURE_ERRORS? and what is R^2 mean in the above picture?
>
> Thank you very much
Sounds like you're using REGRESS() not LINFIT()?
I'd use LINFIT() to get the nice line
and use CORRELATE() to get the Pearson correlation coefficient. I
think CORRELATE() gives you the Pearson correlation coefficient, r,
which, in this case can be squared to get R^2.
|
|
|
Re: How to plot linear regression relation of two array? [message #65043 is a reply to message #65042] |
Mon, 09 February 2009 12:51  |
Hu
Messages: 35 Registered: January 2009
|
Member |
|
|
On Feb 9, 12:12 pm, Vince Hradil <vincehra...@gmail.com> wrote:
> On Feb 9, 1:45 pm, Hu <jha...@gmail.com> wrote:
>
>> Hi,
>
>> I am trying to plot a linear regression relation of two array
>> (supposing A and B) by using IDL. What I want is to got a chart like
>> this link shows (the group is unable to post figure directly):http://serc.carleton.edu/images/introgeo/teachingw data/LeastSquaresGr...
>
>> especially, How can I got the black straight line and the coefficients
>> R^2 ?
>
>> Thanks
>
> Have you looked in the help for linfit()?
BTW, I set MEASURE_ERRORS to SQRT(ABS(Y)), just follow the example,
but what is MEASURE_ERRORS? and what is R^2 mean in the above picture?
Thank you very much
|
|
|
Re: How to plot linear regression relation of two array? [message #65044 is a reply to message #65043] |
Mon, 09 February 2009 12:42  |
Hu
Messages: 35 Registered: January 2009
|
Member |
|
|
On Feb 9, 12:12 pm, Vince Hradil <vincehra...@gmail.com> wrote:
> On Feb 9, 1:45 pm, Hu <jha...@gmail.com> wrote:
>
>> Hi,
>
>> I am trying to plot a linear regression relation of two array
>> (supposing A and B) by using IDL. What I want is to got a chart like
>> this link shows (the group is unable to post figure directly):http://serc.carleton.edu/images/introgeo/teachingw data/LeastSquaresGr...
>
>> especially, How can I got the black straight line and the coefficients
>> R^2 ?
>
>> Thanks
>
> Have you looked in the help for linfit()?
Yes, I use function linfit() to get the parameters a and b (Y=a+b*X)
But How can I get the R^2 ?
|
|
|
Re: How to plot linear regression relation of two array? [message #65045 is a reply to message #65044] |
Mon, 09 February 2009 12:12  |
Vince Hradil
Messages: 574 Registered: December 1999
|
Senior Member |
|
|
On Feb 9, 1:45 pm, Hu <jha...@gmail.com> wrote:
> Hi,
>
> I am trying to plot a linear regression relation of two array
> (supposing A and B) by using IDL. What I want is to got a chart like
> this link shows (the group is unable to post figure directly):http://serc.carleton.edu/images/introgeo/teachingw data/LeastSquaresGr...
>
> especially, How can I got the black straight line and the coefficients
> R^2 ?
>
> Thanks
Have you looked in the help for linfit()?
|
|
|