This function calculates the linear least-squares regression between two variables over an X-Y domain. It returns a single number. The syntax is:
sregr(expr1, expr2, xdim1, xdim2, ydim1, ydim2)
expr1- a valid GrADS expression varying in X and Y
expr2- a valid GrADS expression varying in X and Y
xdim1- starting X dimension expression
xdim2- ending X dimension expression
ydim1- starting Y dimension expression
ydim2- ending Y dimension expression
To do the regression over the global domain, a shorthand may be used:
sregr(expr1, expr2, global)or
sregr(expr1, expr2, g)
sregr(expr1, expr2, lon=0, lon=360, lat=-90, lat=90)
The result from
sregr is the expected value of
expr2 departure given a 1 unit departure in
expr1is the independent variable and
expr2is the dependent variable.
sregrmay be used in conjunction with
defineto create time series or time/height plots.
sregrassumes that the world coordinates are longitude in the X dimension and latitude in the Y dimension, and does weighting in the latitude dimension by the delta of the sin of the latitudes. Weighting is also performed appropriately for unequally spaced grids.
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 means are removed. If we define x and y to be the departures from the areal averages of X and Y:
x = X - Xave
y = Y - Yave
then the regression equation becomes:
y = coefficient * x
coefficient = (sum of x*y over area)/(sum of x*x over area)
coefficient is the output from the
The second example below shows how to construct the regression estimate of Y based on X.
tregrfunction to do regression over the time domain.
set lon 120 250 set lat 15 60 define ivar = tsfc ;* surface temperautre define dvar = shtfl ;* sensible heat flux set z 1 set t 1 d sregr(ivar, dvar, lon=120, lon=250, lat=15, lat=60)
define coeff = sregr(ivar, dvar, lon=120, lon=250, lat=15, lat=60) define dvarave = aave(dvar, lon=120, lon=250, lat=15, lat=60) define ivarave = aave(ivar, lon=120, lon=250, lat=15, lat=60) d coeff * (ivar - ivarave) + dvarave