[Thread Prev][Thread Next][Index]

Re: regression line



hi Celine,
	regressx (or, y, z, t) calculates linear regression
coefficients along the specified axis (x for regressx and similarly
for the others). That means, if you have a data set of shape XYT then
regressx will give JSIZE*LSIZE values of SLOPE and INTERCEP so that
you can fit a line at every Y and T grid of the data.

	In your case, if I've got the point, you want to have only one
slope and intercept for the full subset of the data you are
specifying and want to generate a single line with this slope and
intercept values. Therefore, you have to reshape your 3D data to 1D
and do regression along that dimension using the regress[x,y,z,t] 
routine. So, you may do something like this:

def sym xi = 120W
def sym xf = 60W
def sym yi = 15N
def sym yf = 45N
def sym zz = 1000 ! select the desired level if you have multi-layer temp

let pin = IF (cloud LT 30 AND snow LT 1) THEN temp
let qin = IF (cloud LT 30 AND snow LT 1) THEN prec

set reg/x=($xi):($xf)/y=($yi):($yf)/z=($zz)

let npt = `pin,r=size`

set win 1
cancel view

plot/vs/line=1/symbol=28 pin,qin

can reg/all
def axis/x=1:`npt`:1 xlin
let p = reshape(pin[x=($xi):($xf),y=($yi):($yf),z=($zz)],x[gx=xlin])
let q = reshape(qin[x=($xi):($xf),y=($yi):($yf)],x[gx=xlin])

! this plot should come exactly above the previous one
plot/vs/line=2/symbol=10/over p,q

go regressx ! the regression calculation along x axis

let pmin = p[x=@min]
let pmax = p[x=@max]

let pplt = if j eq 1 then pmin else pmax
let qplt = SLOPE*pplt + INTERCEP ! SLOPE and INTERCEP are calculated
in regressx

list/j=1:2 pplt,qplt
plot/vs/j=1:2/line=9/over pplt,qplt


Hope this helps.

~ Arindam C

On Fri, 7 Mar 2003, Celine Bonfils wrote:

> Hi Ferret users,
> 
> I have got two variables (e.g. temp and prec) for the month of july for 50 
> years, over the globe.
> I select a region (x=120W:60W,y=15N:45N) in which I select only the points
> which fulfill given conditions (cloud, snow).
> 
> let var1=temp[x=120W:60W,y=15N:45N]
> let var2=prec[x=120W:60W,y=15N:45N]
> let p = IF (cloud LT 30 AND snow LT 1) THEN var1
> let p = IF (cloud LT 30 AND snow LT 1) THEN var2
> so p and q are still a function of lat, lon and time.
> 
> And I plot one variable as a function of the other
> plot/vs p, q
> 
> I would like to compute only one regression line between all these points.
> 
> If I use regresst or regressx, I obtain many regression lines.
> e.g.:
> go regresst
> plot/vs p,q                   ! the original scatter plot
> plot/vs/line=2/over p,qhat    ! the regression lines in red
> 
> Do you have any idea I could compute this unique regression line?
> Thank you!
> Celine
> 



[Thread Prev][Thread Next][Index]

Dept of Commerce / NOAA / OAR / PMEL / TMAP

Contact Us | Privacy Policy | Disclaimer | Accessibility Statement