Help with linear trend, please!

Eduardo Agosta Scarel eduardo.agosta at GMAIL.COM
Wed Jul 2 17:06:07 EDT 2008


Hi you all!

I have found myself the answer to my inquiry.

For this may help someone else, the way to estimate a linear trend (or
regression)  on one-monthly series from a multi-year multi-monthly data
file, wihtout having to seperate the chosen month interannual series into a
single file, is just to perform the regression calculus for that month!

I help myself from other previous prompts from the GRADSUSRS Archive.

Here it is the script that can do that:

'sdfopen file.nc'
'set lev 'k''
'set lat -90 0'
'set lon  -180 180'
'set t 1 276'
'define yvar = z' *this is the variable on which to estimate the linear
trend

* the lineal variable 1, 2, ..., 276 to estimate  m and c of y = mx + c
* y = mx + c
* y = amp*x + ave
'set lat -60'
'set lon  -180'
'set t 1 276'
'xvar = yvar*0 + 1'
'xvar = const(xvar,1,-u)'
'xvar = 277 - sum(xvar,t+0,t=276)'
'set lat -90 0'
'set lon  -180 180'
'set t 1'
'define p = sum(xvar,t=10,t=276,12)' * starttime=10, supposing you want to
estimate October linear trend
'define q = sum(yvar,t=10,t=276,12)'
'define r = sum(xvar*yvar,t=10,t=276,12)'
'define s = sum(xvar*xvar,t=10,t=276,12)'
'define rn = ave(xvar*yvar,t=10,t=276,12)'
'define n = r/rn'
'define amp =  (n*r - p*q)/(n*s - p*p)'  *this is m
'define ave = (q - amp*p)/n'
'set t 1 276'
'monmask 10'    * this is for month October, you need the monmas.gs script
from the Archive
'define trend=amp*xvar*mmask + ave' * this is the final linear trend for Oct
alone

That`s all!!

Bye.

Eduardo.




2008/7/2 Eduardo Agosta Scarel <eduardo.agosta at gmail.com>:

>  Dear Grads' Users,
>
> I am trying to extimate linear trend in an interannual series of
> one-monthly data from a multy-year monthly data file.
> I can estimate properly the linear trend using the script below, if
> the data file has the one-monthly data series previously separately. The
> problem is when using the full monthly multy-year data file.
>
> How can I just select one given month from the data , for instance June,
> and estimate the linear trend for the June-series alone, having a multy-year
> data file with all the months of the year?
> I have tried using the function monmask (with argument 6), but I cannot
> solve it properly.
>
> Any suggestion I will much appreciate.
>
> Eduardo.
>
> reinit'
> 'sdfopen d:\anterior\era\mes.nc'
> 'set clopts -1 -1 0.16'
> 'set mproj sps'
> k=70
>
> 'set grads off'
> 'set lev 'k''
> 'set mproj sps'
> 'set lat -90 0'
> 'set lon  -180 180'
>
> 'set lat -60'
> 'set lon  -180'
> 'set t 1 132'
> * contruyo variable lineal 1, 2, ..., 276 to para calcular m y c de y = mx
> + c
> 'xvar = 100*t*0 + 1'
> 'xvar = const(xvar,1,-u)'
> 'xvar = 133 - sum(xvar,t+0,t=132)'
>
> 'set lat -90 0'
> 'set lon  -180 180'
> 'set t 1'
>
> 'define coeff = tregr(xvar,100*t,t=1, t=132)'
> 'define tave = ave(100*t, t=1, t=132)'
> 'define xvarave = ave(xvar, t=1, t=132)'
> 'define trend = coeff*(xvar - xvarave) + tave'
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://gradsusr.org/pipermail/gradsusr/attachments/20080702/642e3810/attachment.html 


More information about the gradsusr mailing list