comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » CORRELATE where is the problem?
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
CORRELATE where is the problem? [message #65472] Sun, 08 March 2009 10:40 Go to next message
xiao zhang is currently offline  xiao zhang
Messages: 81
Registered: June 2008
Member
Hi~ everyone. I have a simple question here. I have two arrays and I
calculated the correlation between them. The result is 0.49. But when
I use the equation to calculate the correlation. The result is 0.99.
And I can see from the plot that they are actually highly correlated.
Why is that? THX

openr,1,'data.txt'
data=fltarr(2,1227)
readf,1,data

temp=data(1,*)
oo=data(0,*)
;print,temp(0)

temp=reform(temp)
oo=reform(oo)

corr=CORRELATE(oo,temp)
print,corr
rr=LINFIT(temp,oo)
print,rr
plot,psym=2,temp,oo
Re: CORRELATE where is the problem? [message #65554 is a reply to message #65472] Mon, 09 March 2009 05:24 Go to previous message
Brian Larsen is currently offline  Brian Larsen
Messages: 270
Registered: June 2006
Senior Member
On Mar 8, 1:40 pm, xiao <littledd...@gmail.com> wrote:
> Hi~ everyone. I have a simple question here. I have two arrays and I
> calculated the correlation between them.  The result is 0.49. But when
> I use the equation to calculate the correlation. The result is 0.99.
> And I can see from the plot that they are actually highly correlated.
> Why is that?  THX
>
> openr,1,'data.txt'
> data=fltarr(2,1227)
> readf,1,data
>
> temp=data(1,*)
> oo=data(0,*)
> ;print,temp(0)
>
> temp=reform(temp)
> oo=reform(oo)
>
> corr=CORRELATE(oo,temp)
> print,corr
> rr=LINFIT(temp,oo)
> print,rr
> plot,psym=2,temp,oo

Are you talking about the difference between corr and rr?

Correlate:
Return Value

If vectors of unequal lengths are specified, the longer vector is
truncated to the length of the shorter vector and a single correlation
coefficient is returned. If an m x n array is specified, the result
will be an m x m array of linear Pearson correlation coefficients,
with the element i,j corresponding to correlation of the ith and jth
columns of the input array.

Linfit:
Return Value

The result is a two-element vector containing the linear model
parameters [A, B].

Those two are less related than apples and oranges, more like apples
and peanuts.



Brian

------------------------------------------------------------ --------------
Brian Larsen
Boston University
Center for Space Physics
http://people.bu.edu/balarsen/Home/IDL
Re: CORRELATE where is the problem? [message #65567 is a reply to message #65472] Sun, 08 March 2009 13:52 Go to previous message
David Fanning is currently offline  David Fanning
Messages: 11724
Registered: August 2001
Senior Member
xiao writes:

> I used the equation in this link:
>
> http://www.jerrydallal.com/LHSP/corr.htm
>
> but the result is different from IDL :(

I doubt it, but let's see how you implemented it. :-)

Cheers,

David
--
David Fanning, Ph.D.
Fanning Software Consulting, Inc.
Coyote's Guide to IDL Programming: http://www.dfanning.com/
Sepore ma de ni thui. ("Perhaps thou speakest truth.")
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Function Makes Unexpected Appearance
Next Topic: Use of ++ operator to count frequency of an entry (Was: Majority Voting)

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:14:10 PDT 2025

Total time taken to generate the page: 0.00634 seconds