The Nonlinear Programming Solver

A Least Squares Estimation Problem for a Regression Model

The following data are used to build a regression model:

data samples;
   input x1 x2 y;
   datalines;
 4  8   43.71
62  5  351.29
81 62 2878.91
85 75 3591.59
65 54 2058.71
96 84 4487.87
98 29 1773.52
36 33  767.57
30 91 1637.66
 3 59  215.28
62 57 2067.42
11 48  394.11
66 21  932.84
68 24 1069.21
95 30 1770.78
34 14  368.51
86 81 3902.27
37 49 1115.67
46 80 2136.92
87 72 3537.84
;

Suppose you want to compute the parameters in your regression model based on the preceding data, and the model is

upper L left-parenthesis a comma b comma c right-parenthesis equals a asterisk x Baseline 1 plus b asterisk x Baseline 2 plus c asterisk x Baseline 1 asterisk x Baseline 2

where a comma b comma c are the parameters that need to be found.

The following PROC OPTMODEL call specifies the least squares problem for the regression model:

/* Reqression model with interactive term: y = a*x1 + b*x2 + c*x1*x2 */
proc optmodel;
   set obs;
   num x1{obs}, x2{obs}, y{obs};
   num mycov{i in 1.._nvar_, j in 1..i};
   var a, b, c;
   read data samples into obs=[_n_] x1 x2 y;
   impvar Err{i in obs} = y[i] - (a*x1[i]+b*x2[i]+c*x1[i]*x2[i]);
   min f = sum{i in obs} Err[i]^2;
   solve with nlp/covest=(cov=5 covout=mycov);
   print mycov;
   print a b c;
quit;

The solution is displayed in Figure 9.

Figure 9: Least Squares Problem Estimation Results

The OPTMODEL Procedure

Problem Summary
Objective SenseMinimization
Objective Functionf
Objective TypeQuadratic
  
Number of Variables3
Bounded Above0
Bounded Below0
Bounded Below and Above0
Free3
Fixed0
  
Number of Constraints0

Solution Summary
SolverNLP
AlgorithmInterior Point Direct
Objective Functionf
Solution StatusOptimal
Objective Value7.1862967833
  
Optimality Error1.4236901E-8
Infeasibility0
  
Iterations1
Presolve Time0.00
Solution Time0.00

mycov
 123
10.0000047825  
2-.00000009960.0000032426 
3-.0000000676-.00000004420.0000000017

abc
3.01132.00330.4998


Last updated: September 09, 2026