MODEL:
 ! Multiple linear weighted asymmetric regression;
 ! User can specify: a) weight appled to error
   of each observation, b) a different weight for
   the up error as opposed to the down error, and
   c) the Norm to be used, e.g., absolute error or
    squared error;
! Keywords: regression, weighted regression,
   assymetric regression, L1 norm;
SETS:
 ! Attributes associated with each observation;
  OBS: Y, ERRU, ERRD, WGTU, WGTD; 
 ! Each independent variable has a coefficient;
  INDEP: COEF;
 ! The explanatory data;
  OXI( OBS, INDEP): X;
     
 ENDSETS
DATA: NORM = 2; ! Do least squares; INDEP = 1..6; ! Six explanatory variables; ! This is the Longley data set; ! The dependent variable and weights for up and down errors; Y, WGTU, WGTD = 60323 1 1 61122 1 1 60171 1 1 61187 1 1 63221 1 1 63639 1 1 64989 1 1 63761 1 1 66019 1 1 67857 1 1 68169 1 1 66513 1 1 68655 1 1 69564 1 1 69331 1 1 70551 1 1; X = 83 234289 2356 1590 107608 1947 88.5 259426 2325 1456 108632 1948 88.2 258054 3682 1616 109773 1949 89.5 284599 3351 1650 110929 1950 96.2 328975 2099 3099 112075 1951 98.1 346999 1932 3594 113270 1952 99 365385 1870 3547 115094 1953 100 363112 3578 3350 116219 1954 101.2 397469 2904 3048 117388 1955 104.6 419180 2822 2857 118734 1956 108.4 442769 2936 2798 120445 1957 110.8 444546 4681 2637 121950 1958 112.6 482704 3813 2552 123366 1959 114.2 502601 3931 2514 125368 1960 115.7 518173 4806 2572 127852 1961 116.9 554894 4007 2827 130081 1962; ENDDATA ! Number of observations; NK = @SIZE( OBS); ! The coefficients may be negative; @FREE(COEF0); @FOR( INDEP(K): @FREE( COEF(K)); ); ! Error = predicted minus actual; @FOR( OBS(I): ERRU(I) - ERRD(I) = COEF0 + @SUM( INDEP(K): COEF(K)*X(I,K)) - Y(I); ); ! Minimize weighted norm error; MIN = @SUM( OBS(I): WGTU(I)*ERRU(I)^NORM + WGTD(I)*ERRD(I)^NORM); END