[Thread Prev][Thread Next][Index]

Re: [ferret_users] [Doubt in script of regressxy function]



Hi Ruksana
G'day

I think there is some other way.

I am assuming you are having 4-d variable (lat, lon, time depth)

(1) I think for pattern correlation you have to select equal size boxes for the variable e.g. box1 (of 10 lat grids * 10 lon grids * 12 time steps and 12 depth levels) and same size of box2.
(2) then you have to arrange this 4-d array in to 1-d array using sequence or sequence or sequence etc. So this sequence function will convert your n-d variable to 1-d variable. Apply it to both fields.
(3) then you will have two 1-d variables of size (10*10*12*12 = 14400 e.g.) that you can use for regression or/and correlation

I hope I am clear, if I sound confusing let me know. Otherwise, you can also try the NCL-Ncar function (https://www.ncl.ucar.edu/Document/Functions/Contributed/pattern_cor.shtml)

Cheers, Saurabh

On Thu, Apr 8, 2021 at 6:38 AM RUKSANA SALIM <ruksanasalim8197@xxxxxxxxx> wrote:
Dear Ferreters,
I wanted to do pattern correlation for 'DSL'(dynamic sea-level), where I have .nc files of observation and model.
I could find out that the 'corr' function after 'regressxy' in ferret gives the pattern correlation. But there have been 2 scripts discussed in the archive for 'regressxy'.
Which one is the appropriate one to find pattern correlation?
I couldn't find any updates since these threads were written (~2006).
Thanks in advance!

regressxy.jnl :

\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




regressxy_new.jnl :

\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 pave = pmasked[x=@ave,y=@ave]
let qave = qmasked[x=@ave,y=@ave]
let pqave = pq[x=@ave,y=@ave]
let ppave = pp[x=@ave,y=@ave]
let qqave = qq[x=@ave,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

--
With regards,
Ruksana Salim,
SC19M070,
M.Tech in Earth System Science,
Indian Institute Of Space Science And Technology,
Trivandrum, Kerala, India - 695547.



--


REGARDS

Saurabh Rathore
Research Scholar (PhD.)
Centre For Oceans, Rivers, Atmosphere & Land Science Technology
Indian Institute Of Technology, Kharagpur
contact :- 91- 8345984434

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

Privacy Policy | Disclaimer | Accessibility Statement