Lindo Systems

! Nonlinear regression model in LINGO;
! Keywords: Nonlinear regression, Regression,
      Least squares, Chwirut;
SETS:
 OBS: FCAST, ERRUP, ERRDN;
 VAR;
 PARAM: BETA;
 OXV( OBS, VAR): XOBS;
ENDSETS
DATA:
! The parameters;
 PARAM = B1 B2 B3; ! Only 3 in this case;

! The variables in the forecasting equation,
  explanatory and dependent;
 VAR = Y X ; ! Only 2 in this case;

! The 1st variable is the dependent variable;
 DEPVAR = 1;
!Reference:    Chwirut, D., NIST (1979).  
               Ultrasonic Reference Block Study. 

Data:          1 Response  (y = ultrasonic response)
               1 Predictor (x = metal distance)
               54 Observations

Model:   y = exp(-b1*x)/(b2+b3*x)  +  e

                          Certified Values
                      Parameter     Standard Deviation
  b1 =            1.6657666537E-01  3.8303286810E-02
  b2 =            5.1653291286E-03  6.6621605126E-04
  b3 =            1.2150007096E-02  1.5304234767E-03

Residual Sum of Squares:                    5.1304802941E+02
Residual Standard Deviation:                3.1717133040E+00
   = ((RSSQ/(DF))^0.5.
Degrees of Freedom:                                51
Number of Observations:                            54

Data:  y             x;
 XOBS =
      92.9000E0     0.500E0
      57.1000E0     1.000E0
      31.0500E0     1.750E0
      11.5875E0     3.750E0
       8.0250E0     5.750E0
      63.6000E0     0.875E0
      21.4000E0     2.250E0
      14.2500E0     3.250E0
       8.4750E0     5.250E0
      63.8000E0     0.750E0
      26.8000E0     1.750E0
      16.4625E0     2.750E0
       7.1250E0     4.750E0
      67.3000E0     0.625E0
      41.0000E0     1.250E0
      21.1500E0     2.250E0
       8.1750E0     4.250E0
      81.5000E0      .500E0
      13.1200E0     3.000E0
      59.9000E0      .750E0
      14.6200E0     3.000E0
      32.9000E0     1.500E0
       5.4400E0     6.000E0
      12.5600E0     3.000E0
       5.4400E0     6.000E0
      32.0000E0     1.500E0
      13.9500E0     3.000E0
      75.8000E0      .500E0
      20.0000E0     2.000E0
      10.4200E0     4.000E0
      59.5000E0      .750E0
      21.6700E0     2.000E0
       8.5500E0     5.000E0
      62.0000E0      .750E0
      20.2000E0     2.250E0
       7.7600E0     3.750E0
       3.7500E0     5.750E0
      11.8100E0     3.000E0
      54.7000E0      .750E0
      23.7000E0     2.500E0
      11.5500E0     4.000E0
      61.3000E0      .750E0
      17.7000E0     2.500E0
       8.7400E0     4.000E0
      59.2000E0      .750E0
      16.3000E0     2.500E0
       8.6200E0     4.000E0
      81.0000E0      .500E0
       4.8700E0     6.000E0
      14.6200E0     3.000E0
      81.7000E0      .500E0
      17.1700E0     2.750E0
      81.3000E0      .500E0
      28.9000E0     1.750E0;
ENDDATA

! May want to use global solver to get the global
 minimum.  Click on:
  LINGO -> Options -> Global Solver -> Use Global Solver;
! May want to also set a time limit on proving optimality
  of, say, 5 seconds, by clicking on:
  LINGO -> Options -> General Solver -> Runtime Limits -> Time;

! Min Squared error objective;
  MIN = @SUM( OBS(i): (ERRUP(i) + ERRDN(i))^2);

! Alternatively...
! Min Absolute deviations objective;
!  MIN = @SUM( OBS(i): ERRUP(i) + ERRDN(i));

 ! Allow parameters to be negative;
  @FOR( PARAM(j):
     @FREE( BETA(j));
      );

!Model:   
       y = exp(-b1*x)/(b2+b3*x)  +  e ;
@FOR( OBS(i):
 ! Compute forecast for observation i;
  FCAST(i) = @EXP( -BETA(1)*XOBS(i,2))/(BETA(2)+BETA(3)*XOBS(i,2));
 ! Compute up and down error;
  ERRUP(i) - ERRDN(i) = FCAST(i) - XOBS(i,DEPVAR);
    );