[Thread Prev][Thread Next][Index]

Re: [ferret_users] [FERRET]calculate spatial correlation of 2 variables




Hi Zhen,

The spatial correlation of two varaibles can be found with the following ferret script. This is simply the regresst script re-written to consider space rather than time.

To use this, copy the regressxy script below to a .jnl file and then type

yes? go regressxy
yes? let P = myvar1
yes? let Q = myvar2

in ferret. The variable "corr" is then the spatial correlation between myvar1 and myvar2.

I hope this helps,

Andy


regressxy.jnl script:

\CANCEL MODE VERIFY
! Description: define FERRET variables for regression along the X and Y axis

say ... Linear Regression In the XY Plane
say ... Instructions:
say Use the LET command to define new variables
say Define the variable P as your independent (X) variable
say Define the variable Q as your dependent (Y) variable
say Results will be variables "SLOPE", "INTERCEP" and "RSQUARE"
say QHAT will be the regression estimate
say Note: If "Y" is your independent variable then
say ... "SET GRID Q" after defining Q.
say ...

let pq = p*q
let pqmask = pq-pq ! 0 or "missing" so all variables share the same missing
let pmasked = p + pqmask
let qmasked = q + pqmask
let pp = pmasked*pmasked
let qq = qmasked*qmasked

let pxave = pmasked[x=@ave]
let qxave = qmasked[x=@ave]
let pave = pxave[y=@ave]
let qave = qxave[y=@ave]
let pqxave = pq[x=@ave]
let ppxave = pp[x=@ave]
let qqxave = qq[x=@ave]
let pqave = pqxave[y=@ave]
let ppave = ppxave[y=@ave]
let qqave = qqxave[y=@ave]
let pvar = ppave - pave*pave
let qvar = qqave - qave*qave
let pqvar = pqave - pave*qave

let slope = pqvar / pvar
let intercep = qave - slope*pave
let qhat = slope*p + intercep
let rsquare = (pqvar*pqvar) / (pvar*qvar)
let corr = pqvar/(pvar*qvar)^0.5

SET MODE/LAST VERIFY






On Wed, 14 Jun 2006, zhen.li@gsfc.nasa.gov wrote:

Dear Ferret Users:

This question was asked previously in the mail archive, but I didn't find a practical solution
based on the answer.

Someone suggested using the "go variance" to check out the "CORREL" function. So, after I typed
this command, the "go variance" leads to some instructions on this function, but it doesn't show
the usage of CORREL function. I tried to find this information in the user guide, but it's
not there either.

I wonder if anyone knows how to use this function.

Thanks,

Zhen



--
Andy Chiodi

School of Oceanography
University of Washington
Seattle, WA

chiodi@ocean.washington.edu
(206) 526-6758

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement