[Thread Prev][Thread Next][Index]

Re: [ferret_users] 21 yr running correlation



Hi Andrew,

On Wed, Aug 29, 2018 at 5:07 AM Andrew Wittenberg - NOAA Federal <andrew.wittenberg@xxxxxxxx> wrote:
Running correlations are easy to compute in Ferret.  If your signals are A and B, then:

! define the running time-averaging transformation,
! e.g. 21*12 grid points (21 years, if time step is 1 month)
def sym trans "t=@sbx:`21*12`"

let a2 = a^2; let b2 = b^2; let prod = a*b
let a_b_cov = prod[($trans)] - a[($trans)]*b[($trans)]
let a_b_corr = a_b_cov/((a2[($trans)] - a[($trans)]^2)*(b2[($trans)] - b[($trans)]^2))^.5

Thanks!  That's what I was looking for. The method I had in my mind was

 dev = a - a[($trans)]
 dev2 = dev*dev
 var = dev2[($trans)]

to compute the variance, which is wrong.  Your method utilizes the identity

mean{ [a - mean(a)]^2}
= mean(a^2) - [mean(a)]^2

so that the operation mean() is applied only once in each term.  That's elegant.

Currently, I need a "running skewness", which I think I can calculate applying your method.

Cheers,
Ryo


[Thread Prev][Thread Next][Index]
Contact Us
Dept of Commerce / NOAA / OAR / PMEL / Ferret

Privacy Policy | Disclaimer | Accessibility Statement