tregr (expr1, expr2, tdim1, tdim2)
This function calculates the leastsquares regression between two timedependent variables.
expr1

a valid GrADS expression that varies in timeexpr2

a valid GrADS expression that varies in time and may also vary in X and Ytdim1

starting time dimension expression tdim2

ending time dimension expression
The result is a grid that matches the X and Y dimensions of
expr2
where each grid point is the temporal
regression of expr2
(the dependent variable) onto
expr1
(the independent variable).
tregr
gives the expected value of
the expr2
departure given a 1 unit departure in
expr1
.
expr1
and expr2
vary only in time, the output is a single value.
Y = slope * X + intercept
where X is the independent variable, Y is the dependent variable, and the slope and intercept are calculated using complicated algebraic formulas. The calculation is simplified if the time means are removed. If we define x and y to be the departures from the time averages of X and Y:
x = X  Xave
y = Y  Yave
then the regression equation becomes:
y = coefficient * x
Where
coefficient = (sum of x*y over time)/(sum of x*x over time)
This coefficient
is the output from the tregr
function.
The second example below shows how to construct the regression estimate of Y based on X.
sregr
function to do regression over the spatial domain.
set y 1 set z 1 set t 1 100 define elnino = aave(ts, lon=160, lon=80, lat=20, lat=10) set lon 0 360 set lat 90 90 set z 1 set t 1 d tregr(elnino, slp, t=1, t=100)
define coeff = tregr(elnino, slp, t=1, t=100) define slpave = ave(slp, t=1, t=100) define ninoave = ave(elnino, t=1, t=100) d coeff * (elnino  ninoave) + slpave