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

Home » Public Forums » archive » Re: Weighted correlation
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Return to the default flat view Create a new topic Submit Reply
Re: Weighted correlation [message #76876] Sun, 10 July 2011 06:55 Go to previous message
Gray is currently offline  Gray
Messages: 253
Registered: February 2010
Senior Member
On Jul 10, 6:29 am, Fermiona Fermiona <fermion...@gmail.com> wrote:
> Hello,
>
> Is there a function in IDL that calculates the correlation coeff for
> data with weights?
>
> Many thanks!

This seems like it would be relatively easy to do:

function weighted_correlation, x, y, w
total_weights = total(w)
mean_x = total(w*x)/total_weights
mean_y = total(w*y)/total_weights
cov_xy = total(w*(x-mean_x)*(y-mean_y))/total_weights
cov_xx = total(w*(x-mean_x)*(x-mean_x))/total_weights
cov_yy = total(w*(y-mean_y)*(y-mean_y))/total_weights
return, cov_xy / sqrt(cov_xx * cov_yy)
end

You'd need to add error checking and type checking, and if your arrays
are very large you might want to do total(/double), but this should
get you there.
[Message index]
 
Read Message
Read Message
Previous Topic: Re: MP4/Animated GIF/JPEG woes....(Windows, IDL 8.1)
Next Topic: MP4/Animated GIF/JPEG woes....(Windows, IDL 8.1)

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

Current Time: Wed Oct 08 15:52:11 PDT 2025

Total time taken to generate the page: 0.00389 seconds