[Thread Prev][Thread Next][Index]

[Fwd: linear regression]




-- 
Andreas Schmittner                        andreas@ocean.seos.uvic.ca
School of Earth and Ocean Sciences        Tel: (250) 472-4060
University of Victoria                    Fax: (250) 472-4004
PO Box 3055, Stn CSC
Victoria, BC, V8W 3P6, Canada
http://climate.uvic.ca/people/andreas/andreas.html
--- Begin Message ---
Hi Gert,

if I understand you right, you want to compute the spatial
correlation. Look at the following script (regressxy.jnl) that I
modified using the standard journal:

\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



Gert van Dijken wrote:
> 
> Hi all,
> 
> I have some problems using the linear regression go-tools.
> 
> My data set looks as follows:
> 
> yes? show data
>      currently SET data sets:
>     1> ./ozo_prod_diff.cdf  (default)
>  name     title                             I         J         K         L
>  OZODIFF  (OZO[D=map.79F.V2]-OZO[D=map.92  1:301     1:301     ...       1:153
>  PRODDIFF (PROD79_MASK- PROD92_MASK)*100/  1:301     1:301     ...       1:153
> 
> I would like to find the equation of the best fit (and r^2) for each day
> (L) when I plot ozodiff vs. proddiff.
> 
> What I tried was more or less the following, for example day 45:
> yes? plot/vs/l=45 ozodiff,proddiff
> yes? ! lots of points, but it looks like a pretty good linear correlation...
> yes? let q = ozodiff[l=45]
> yes? let p = proddiff[l=45]
> yes? go regresst
> yes? set grid q
> yes? list slope
> 
> The problem is that 'slope', 'intercep' or 'rsquare' are not one point,
> but a 301x301 array.  When I use 'go regressx' or 'go regressy' I get a
> 1x301 array.  Using 'go regressz' also gives a 301x301 array.
> 
> Am I using the wrong go-tool?
> 
> Ferret version:  ! Version 5.22 - 07/27/00
> 
> Thanks,
> 
> Gert

-- 
Andreas Schmittner                        andreas@ocean.seos.uvic.ca
School of Earth and Ocean Sciences        Tel: (250) 472-4060
University of Victoria                    Fax: (250) 472-4004
PO Box 3055, Stn CSC
Victoria, BC, V8W 3P6, Canada
http://climate.uvic.ca/people/andreas/andreas.html
--- End Message ---

[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement