Resources

Almon Lag Regression

 /****************************************************************/
 /*          S A S   S A M P L E   L I B R A R Y                 */
 /*                                                              */
 /*    NAME: ALMON                                               */
 /*   TITLE: Almon Lag Regression                                */
 /* PRODUCT: IML                                                 */
 /*    KEYS: MATRIX REGR                                         */
 /*   PROCS: IML                                                 */
 /*    DATA:                                                     */
 /*                                                              */
 /* SUPPORT: LWB                         UPDATE:                 */
 /*     REF:                                                     */
 /*    MISC: CONVERTED FROM MATRIX TO IML USING MATIML           */
 /*                                                              */
 /****************************************************************/
*---THIS CODE SHOWS HOW THE ALMON LAG REGRESSION MIGHT BE
    IMPLEMENTED WITH PROC IML;

TITLE 'National Industrial Conference Board Data';

DATA A;
    INPUT Y X @@;
    CARDS;
2072 1660 2077 1926 2078 2181 2043 1897 2062 1695 2067 1705 1964 1731
1981 2151 1914 2556 1991 3152 2129 3763 2309 3903 2614 3912 2896 3571
3058 3199 3309 3262 3446 3476 3466 2993 3435 2262 3183 2011 2697 1511
2338 1631 2140 1990 2012 1993 2071 2520 2192 2804 2240 2919 2421 3024
2639 2725 2733 2321 2721 2131 2640 2552 2513 2234 2448 2282 2429 2533
2516 2517 2534 2772 2494 2380 2596 2568 2572 2944 2601 2629 2648 3133
2840 3449 2937 3764 3136 3983 3299 4381 3514 4786 3815 4094 4093 4870
4262 5344 4531 5433 4825 5911 5160 6109 5319 6542 5574 5785 5749 5707
5715 5412 5637 5465 5383 5550 5467 5465
;
PROC PRINT;
RUN;

title "Almon Results";
PROC IML;
      RESET AUTONAME;
      USE A;
      READ ALL INTO DATA;
      Y=DATA[,1];
      X=DATA[,2];

      *-----DISTRIBUTED LAG ESTIMATION-----;
      * P IS THE NUMBER OF LAGS BACK       ;
      * Q IS THE DEGREE OF THE POLYNOMIAL  ;
      * X IS THE INDEPENDENT VARIABLE      ;
      * Y IS THE DEPENDENT VARIABLE        ;
      * THIS ROUTINE ASSUMES THAT THERE IS ;
      * NOT A CONSTANT TERM, OR IT HAS BEEN;
      * ABSORBED BY STANDARDIZING THE DATA ;
      * TO MEAN ZERO.                      ;
      *------------------------------------;
      START DISTLAG (P,Q,X,Y);
         PRINT P Q;
         N=NROW(X);
         P1=P+1;
         Q1=Q+1;

         *-----CREATE XX WITH LAGS OF X-----;
         XX=X[P1:N,];
         YY=Y[P1:N,];
         DO II=1 TO P;
              XX=XX||X[(P1-II):(N-II),];
         END;

         *-----COMPLETE REGRESSION------------;
         ZINV=INV(XX`*XX);
         BETA0=ZINV*(XX`*YY);
         SSE0=SSQ(YY-XX*BETA0);
         PRINT "Regression with Complete Lags", BETA0 SSE0;

         *-----COMPOSE VANDERMONDES-----;
         V=J(1,P1,1);
         DO II=1 TO Q;
             V=V//( (0:P)##II );
         END;
         PRINT V[L="Partial Vandermonde Matrix"];

         *-----ALMON POLYNOMIAL ESTIMATES-----;
         Z=XX*V`;
         ZINV=INV(Z`*Z);
         ALPHA=ZINV*Z`*YY;
         BETA1=V`*ALPHA;
         SSE1=SSQ(YY-Z*ALPHA);
         MSE=SSE1/(N-P-Q1);
         VAR=ZINV*MSE;
         PRINT ALPHA[L="POLYNOMIAL PARAMETER ESTIMATES"];
         PRINT SSE1[L="SUM OF SQUARES ERROR"];
         PRINT BETA1[L="LAG PARAMETER ESTIMATES"];
         PRINT VAR[L="VARIANCE OF POLYNOM ESTIMATES"];

      FINISH;
      *--THIS TRIES VARIOUS MAXIMUM LAGS AND DEGREES;
      RUN DISTLAG(8,2,X,Y);
      RUN DISTLAG(8,3,X,Y);
      RUN DISTLAG(5,2,X,Y);
      RUN DISTLAG(10,3,X,Y);
  QUIT;
  title;