- 积分
- 18571
- 贡献
-
- 精华
- 在线时间
- 小时
- 注册时间
- 2012-9-8
- 最后登录
- 1970-1-1
|

楼主 |
发表于 2013-9-25 15:06:20
|
显示全部楼层
*
* computing Lead / Lag correlation coefficient of Two Sequences
*
function tcpl(arg)
var1=subwrd(arg,1)
var2=subwrd(arg,2)
t1=subwrd(arg,3)
t2=subwrd(arg,4)
pl1=subwrd(arg,5)
pl2=subwrd(arg,6)
opts=subwrd(arg,7)
if(pl2='')
say 'Computing the Lead / Lag Correlation Coef of Two Sequences Usage:'
say 'TCPL SEQ1 SEQ2 TSTRT TEND PLSTRT PLEND [opts]'
return
else
say 'Computing the Lead / Lag Correlation Coef of Two Sequences::'
say 'Seq1 = 'var1' Seq2 = 'var2' Time Range 't1' to 't2' Lead/Lag Range 'pl1' to 'pl2
endif
if(opts='')
say 'Computing Two Single Points'
else
say 'Computing a Single Point to a Field'
endif
n=pl1
nn=1
while(n<=pl2)
if(n<0)
tt1=1-n;tt2=t2
'set t 'tt1' 'tt2
'define 'pl'='var1'(t'n')'
else
tt1=t1;tt2=t2-n
'set t 'tt1' 'tt2
'define 'pl'='var1'(t+'n')'
endif
'set t 1'
'define plrr=tcorr('pl','var2',t='tt1',t='tt2')'
if(opts='')
****sgl to sgl
'd plrr'
corr=subwrd(result,4)
plr.nn=corr;nn=nn+1
****screen print
if(n<0)
n2=0-n
say var1' Lead to 'var2' 'n2' Intvls corr='corr' Freedom='tt2-tt1+1-2
else
if(n=0)
say var1' Cont to 'var2' 'n' Intvls corr='corr' Freedom='tt2-tt1+1-2
else
say var1' Lag to 'var2' 'n' Intvls corr='corr' Freedom='tt2-tt1+1-2
endif
endif
else
**sgl-field
**draw confident shades
say 'SF: Input critic correlation coef(return continue):'
say 'SF: Freedom='tt2-tt1+1-2
pull r0
if(r0 != '')
r1=-1*r0
'set gxout shaded';'set rbcols 5 0 5';'set clevs 'r1' 'r0
'd plrr'
'set rbcols auto';'set gxout contour';'d plrr'
else
'd plrr'
endif
**draw title
say 'SF: Input your title(return continue):'
say 'SF: Lead(<0)/Lag(>0) 'n
pull title
if(title='')
if(n<0)
n2=0-n
'draw title 'var1' Lead to 'var2' 'n2' Corr. Ceof. (N='tt2-tt1+1')'
else
if(n=0)
'draw title 'var1' and 'var2' Corr. Ceof. (N='tt2-tt1+1')'
else
'draw title 'var1' Lag to 'var2' 'n' Corr. Ceof. (N='tt2-tt1+1')'
endif
endif
else
'draw title 'title
endif
**your own cmd for example print the fig
while(1)
say 'SF: input your own cmd(return continue)'
pull cmd
if(cmd=''); break; endif
cmd
endwhile
'c'
endif
n=n+1
endwhile
*draw the sgl-sgl VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
if(opts='')
xbl=2;ybl=2;xtr=8;ytr=6;ym=0.5*(ybl+ytr);siz=0.12;sizz=0.08
dx=(xtr-xbl)/(nn+2);dy=(ytr-ybl)/10;xs=xbl+dx
**draw shaded area
if(pl1<0 & pl2>0)
x2=xs+(1-pl1)*dx
'set line 9';'draw recf 'xbl' 'ybl' 'x2' 'ytr
'set line 4';'draw recf 'x2' 'ybl' 'xtr' 'ytr
endif
**draw frame
'set line 1 1 6'
'draw rec 'xbl' 'ybl' 'xtr' 'ytr
**draw line 0
'set line 15 5 3'
'draw line 'xbl' 'ym' 'xtr' 'ym
**draw ylabs
'set line 1 1 3';'set strsiz 0.12';'set string 1 r 0.05'
n=0;lab=-1
while(n<=10)
'draw line 'xbl' 'ybl+n*dy' 'xbl+siz' 'ybl+n*dy
'draw line 'xtr' 'ybl+n*dy' 'xtr-siz' 'ybl+n*dy
lab=-1+0.2*n
'draw string 'xbl-siz' 'ybl+n*dy' 'lab
n=n+1
endwhile
**draw curve
'set line 1 1 3'
'set string 1 tc'
nn=nn-1
n=1
x1=xs+n*dx;y1=ybl+(ytr-ybl)*(1+plr.1)/2
if(pl1<0)
'draw mark 2 'x1' 'y1' 'sizz
else
'draw mark 3 'x1' 'y1' 'sizz
endif
'draw line 'x1' 'ybl' 'x1' 'ybl+siz;'draw line 'x1' 'ytr' 'x1' 'ytr-siz
n=2
n2=pl1+1
while(n<=nn)
x2=xs+n*dx;y2=ybl+(ytr-ybl)*(1+plr.n)/2
if(n2<0)
'draw mark 2 'x2' 'y2' 'sizz
else
'draw mark 3 'x2' 'y2' 'sizz
endif
if(n2=0);'set line 15 5 3';'draw line 'x2' 'ybl' 'x2' 'ytr;'set line 1 1 3';endif
'draw line 'x2' 'ybl' 'x2' 'ybl+siz;'draw line 'x2' 'ytr' 'x2' 'ytr-siz
'draw line 'x1' 'y1' 'x2' 'y2
x1=x2;y1=y2
n=n+1;n2=n2+1
endwhile
**draw xlabs
x2=xs+1*dx
'draw string 'x2' 'ybl-siz' 'pl1
x2=xs+nn*dx
'draw string 'x2' 'ybl-siz' 'pl2
if(pl1<0 & pl2>0)
x2=xs+(1-pl1)*dx
'draw string 'x2' 'ybl-siz' 0'
endif
**draw title
'set string 1 bc';'set strsiz 0.2'
say 'SS: input title(return continue)'
pull title
if(title='')
'draw string '0.5*(xbl+xtr)' 'ytr+0.2' Lead/Lag Correlation Coefficients'
else
'draw string '0.5*(xbl+xtr)' 'ytr+0.2' 'title' Lead/Lag Corr. Coef.'
endif
**draw critic lines
say 'SS: input critic correlation coef(return continue)'
pull r0
if(r0 != '')
'set line 2 1 3'
y2=ybl+(ytr-ybl)*(1-r0)/2
y1=ybl+(ytr-ybl)*(1+r0)/2
'draw line 'xbl' 'y1' 'xtr' 'y1;'draw line 'xbl' 'y2' 'xtr' 'y2
endif
endif
*draw the sgl-sgl AAAAAAAAAAAAAAAAAAAAA
'undefine 'pl
*end
要如何改呢 {:eb522:}{:eb522:} |
|