/* Single Exponential Smoothing where parameter alpha is automatically chosen. */ /* (Forecast Smoothing) Criteria: MAD */ new; cls; let data[12,1]= 23 25 36 31 26 28 48 36 31 42 53 43 ; t=seqa(1,1,rows(data)); library pgraph; graphset; _pltype=6; _plegctl=1; _plegstr="actual\000predicted"; title("Single Exponential Smoothing"); prec=0.01; xy(t,data~sesMAD(data,prec)); proc sesMAD(x,prec); local n,m,e,i,j,alpha,alphastar,count,MAD,MAD_1; n=rows(x); MAD_1=1e+8; count=1; j=1; do while j<=(1/prec); alpha=prec*(j-1); m=zeros(n,1); m[1]=x[1]; i=2; do while i<=n; m[i]=alpha*x[i-1]+(1-alpha)*m[i-1]; i=i+1; endo; e=x[2:n]-m[2:n]; MAD=sumc(abs(e))/rows(e); if MAD