Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
The NLIN Procedure

Example 45.1: Segmented Model

From theoretical considerations, you can hypothesize that

y &=& a + bx + cx^2 {\rm if}  x \lt x_0 \y &=& p {\rm if}  x \gt= x_0

That is, for values of x less than x0, the equation relating y and x is quadratic (a parabola); and, for values of x greater than x0, the equation is constant (a horizontal line). PROC NLIN can fit such a segmented model even when the joint point, x0, is unknown.

The curve must be continuous (the two sections must meet at x0), and the curve must be smooth (the first derivatives with respect to x are the same at x0).

These conditions imply that

x_0 &=& - b / 2 c \p &=& a - b^2 / 4 c

The segmented equation includes only three parameters; however, the equation is nonlinear with respect to these parameters.

You can write program statements with PROC NLIN to conditionally execute different sections of code for the two parts of the model, depending on whether x is less than x0 .

A PUT statement is used to print the constrained parameters every time the program is executed for the first observation (where x =1). The following statements perform the analysis.

   *---------FITTING A SEGMENTED MODEL USING NLIN-----*
   |      |                                           |
   |   Y  | QUADRATIC          PLATEAU                |
   |      | Y=A+B*X+C*X*X      Y=P                    |
   |      |                     ..................... |
   |      |              .     :                      |
   |      |          .         :                      |
   |      |       .            :                      |
   |      |     .              :                      |
   |      |    .               :                      |
   |      +-----------------------------------------X |
   |                          X0                      |
   |                                                  |
   | CONTINUITY RESTRICTION: P=A+B*X0+C*X0**2         |
   | SMOOTHNESS RESTRICTION: 0=B+2*C*X0 SO X0=-B/(2*C)|
   *--------------------------------------------------*;

   title 'Quadratic Model with Plateau';
   data a;
      input y x @@;
      datalines;
   .46 1  .47  2 .57  3 .61  4 .62  5 .68  6 .69  7
   .78 8  .70  9 .74 10 .77 11 .78 12 .74 13 .80 13
   .80 15 .78 16
   ;
   proc nlin;
      parms a=.45 b=.05 c=-.0025;
      
      x0=-.5*b / c;                 * Estimate join point;
      if x<x0 then                  * Quadratic part of Model;
         model y=a+b*x+c*x*x;
      else                          * Plateau part of Model;
         model y=a+b*x0+c*x0*x0;
         
      if _obs_=1 and _iter_ =.  then do;
         plateau=a+b*x0+c*x0*x0;
         put /  x0= plateau=  ;
         end;
      output out=b predicted=yp;
   run;

   /* Setup for creating the graph */
   legend1 frame cframe=ligr label=none cborder=black 
           position=center value=(justify=center);
   axis1 label=(angle=90 rotate=0) minor=none;
   axis2 minor=none; 

   proc gplot;
      plot y*x yp*x/frame cframe=ligr legend=legend1 
      vaxis=axis1 haxis=axis2 overlay ; 
   run;

Output 45.1.1: Nonlinear Least Squares Iterative Phase

Quadratic Model with Plateau

The NLIN Procedure
Iterative Phase
Dependent Variable y
Method: Gauss-Newton

Iter a b c Sum of
Squares
0 0.4500 0.0500 -0.00250 0.0562
1 0.3881 0.0616 -0.00234 0.0118
2 0.3930 0.0601 -0.00234 0.0101
3 0.3922 0.0604 -0.00237 0.0101
4 0.3921 0.0605 -0.00237 0.0101
5 0.3921 0.0605 -0.00237 0.0101
6 0.3921 0.0605 -0.00237 0.0101

NOTE: Convergence criterion met.

Output 45.1.2: Least Squares Analysis for the Quadratic Model

The NLIN Procedure

Source DF Sum of Squares Mean Square F Value Approx
Pr > F
Regression 3 7.7256 2.5752 114.22 <.0001
Residual 13 0.0101 0.000774    
Uncorrected Total 16 7.7357      
           
Corrected Total 15 0.1869      

Parameter Estimate Approx
Std Error
Approximate 95% Confidence
Limits
a 0.3921 0.0267 0.3345 0.4497
b 0.0605 0.00842 0.0423 0.0787
c -0.00237 0.000551 -0.00356 -0.00118

Approximate Correlation Matrix
  a b c
a 1.0000000 -0.9020250 0.8124327
b -0.9020250 1.0000000 -0.9787952
c 0.8124327 -0.9787952 1.0000000


Output 45.1.1 indicates that the join point is 12.75 and the plateau value is 0.78. As displayed in the following plot of the predicted values (YP) and the actual values, the selected join point and plateau value is reasonable. The predicted values for the estimation are written to the data set b with the OUTPUT statement.

Output 45.1.3: Observed and Predicted Values for the Quadratic Model
nlnef1.gif (3933 bytes)

Chapter Contents
Chapter Contents
Previous
Previous
Next
Next
Top
Top

Copyright © 1999 by SAS Institute Inc., Cary, NC, USA. All rights reserved.