# Linear Trend analysis

Dear all,

I have used following script to see the the linear trend in data. I am attaching one fig. for the reference.
Yellow line is representing mean
Green line represents trend
1. This script is working fine but in the result kinks are coming in the line which dont know how to smooth it ?
2. How to check the statsistical significance level in the trend ?

Script :
*assuming this is the time limit
'reinit'
'enable print print.meta'
'open test1.ctl'
'set vpage 0 8 7.5 11'
'set grid off'
'set t 1 57'
'set lat 18.96'
'set lon 72.83'
'set z 1'
'define yvar = ave(rf,t=1,t=57)'
'set vrange 0 1000'
'set ylabs 0| 100| 200| 300| 400| 500| 600| 700| 800| 900| 1000|'
'd rf'
* make a variable 1, 2, ..., 24 to calculate m and c of y = mx + c
'xvar = rf*0 + 1'
'xvar = const(xvar,1,-rf)'
'xvar = 58 - sum(xvar,t+0,t=57)'
'set t 1'
'define p = sum(xvar,t=1,t=57)'
'define q = sum(rf,t=1,t=57)'
'define r = sum(xvar*rf,t=1,t=57)'
'define s = sum(xvar*xvar,t=1,t=57)'
'define rn = ave(xvar*rf,t=1,t=57)'
'define n = r/rn'
'define amp = (n*r - p*q)/(n*s - p*p)'
'define dd = (q - amp*p)/n'
'set t 1 57'
'define yvar = ave(rf,t=1,t=57)'
'define aa= (amp*xvar + dd)'
'set cmark 0'
'd aa'
'set cmark 0'
'd yvar'
'draw ylab mm'
'draw xlab Year'
'draw title 1SD_Ahm blk_Act_TS ylw_mean grn_trend'
'close 1'

···

-----Original Message-----
From: dhaval.prajapati@iccsir.org [mailto:dhaval.prajapati@iccsir.org]
Sent: Friday, May 15, 2009 11:12 AM
To: hdf-forum@hdfgroup.org
Subject: [hdf-forum] Linear Trend analysis

**__________________________________________________________________________________________________________

'open test2.ctl'
'set vpage 0 8 4 7.5'
'set grid off'
'set t 1 57'
'set lat 18.96'
'set lon 72.83'
'set z 1'
'define yvar = ave(rf,t=1,t=57)'
*'set vrange 0 1000'
'set ylabs 0| 100| 200| 300| 400| 500| 600| 700| 800| 900| 1000|'
'd rf'
* make a variable 1, 2, ..., 24 to calculate m and c of y = mx + c
'xvar = rf*0 + 1'
'xvar = const(xvar,1,-rf)'
'xvar = 58 - sum(xvar,t+0,t=57)'
'set t 1'
'define p = sum(xvar,t=1,t=57)'
'define q = sum(rf,t=1,t=57)'
'define r = sum(xvar*rf,t=1,t=57)'
'define s = sum(xvar*xvar,t=1,t=57)'
'define rn = ave(xvar*rf,t=1,t=57)'
'define n = r/rn'
'define amp = (n*r - p*q)/(n*s - p*p)'
'define dd = (q - amp*p)/n'
'set t 1 57'
'define yvar = ave(rf,t=1,t=57)'
'define aa= (amp*xvar + dd)'
'set cmark 0'
'd aa'
'set cmark 0'
'd yvar'
'draw ylab mm'
'draw xlab Year'
'draw title 2SD_Ahm blk_Act_TS ylw_mean grn_trend'
'close 1'

**__________________________________________________________________________________________________________

'open test3.ctl'
'set vpage 0 8 0.5 4'
'set grid off'
'set t 1 57'
'set lat 18.96'
'set lon 72.83'
'set z 1'
'define yvar = ave(rf,t=1,t=57)'
'set vrange 0 1000'
'set ylabs 0| 100| 200| 300| 400| 500| 600| 700| 800| 900| 1000|'
'd rf'
* make a variable 1, 2, ..., 24 to calculate m and c of y = mx + c
'xvar = rf*0 + 1'
'xvar = const(xvar,1,-rf)'
'xvar = 58 - sum(xvar,t+0,t=57)'
'set t 1'
'define p = sum(xvar,t=1,t=57)'
'define q = sum(rf,t=1,t=57)'
'define r = sum(xvar*rf,t=1,t=57)'
'define s = sum(xvar*xvar,t=1,t=57)'
'define rn = ave(xvar*rf,t=1,t=57)'
'define n = r/rn'
'define amp = (n*r - p*q)/(n*s - p*p)'
'define dd = (q - amp*p)/n'
'set t 1 57'
'define yvar = ave(rf,t=1,t=57)'
'define aa= (amp*xvar + dd)'
'set cmark 0'
'd aa'
'set cmark 0'
'd yvar'
'draw ylab mm'
'draw xlab Year'
'draw title 3SD_Ahm blk_Act_TS ylw_mean grn_trend'
'close 1'
'print'
'disable print'
'!gxps -c -i print.meta -o TS_Ahm_June_123SD_magnitude_mm.ps'
'!rm print.meta'

Thanks,

Dhaval
Indian Centre for Climate and Societal Impacts Research (ICCSIR)