Published on :
Statistical Modeling INTERNAL_CREATION

Documentation Example for PROC HPNLMOD

This code is also available in: Deutsch Español Français
Awaiting validation
The script begins by creating a dataset 'a' using inline data (datalines). This dataset contains the variables 'y' (response) and 'x' (predictor). Then, the HPNLMOD procedure is used to fit a segmented nonlinear model to the data in 'a', producing an output dataset 'b' containing the predictions. The model defines a junction point 'x0' and applies conditional logic to calculate the predicted value 'yp' before and after this junction point, ensuring continuity. Estimates for the junction point and the plateau value are also calculated. Finally, PROC SGPLOT is used to visualize the observed data and predicted values, including reference lines for the plateau and the junction point to facilitate model interpretation.
Data Analysis

Type : INTERNAL_CREATION


All data used in this script is created internally via a DATA step with 'datalines'.

1 Code Block
DATA STEP Data
Explanation :
This DATA STEP block creates a temporary dataset named 'a'. The variables 'y' and 'x' are read from the provided datalines. This data constitutes the set of observations to which the model will be fitted.
Copied!
1DATA a;
2 INPUT y x;
3 DATALINES;
4.46 1 .47 2 .57 3 .61 4 .62 5 .68 6 .69 7
5.78 8 .70 9 .74 10 .77 11 .78 12 .74 13 .80 13
6.80 15 .78 16
7 ;
2 Code Block
PROC HPNLMOD Data
Explanation :
This procedure fits a segmented nonlinear model to the data in dataset 'a'. It initializes the parameters 'alpha', 'beta', and 'gamma'. A junction point 'x0' is calculated. The predicted variable 'yp' is determined by a quadratic function before 'x0' and by a constant after 'x0' (plateau value), ensuring continuity. The model 'y ~ residual(yp)' is specified. 'Estimate' statements are used to obtain estimates for the 'join point' and the 'plateau value'. 'Predict' statements save the predicted values 'yp' as well as the observed values 'y' and 'x' into the output dataset 'b'.
Copied!
1PROC HPNLMOD DATA=a out=b;
2 parms alpha=.45 beta=.05 gamma=-.0025;
3 
4 x0 = -.5*beta / gamma;
5 
6 IF (x < x0) THEN
7 yp = alpha + beta*x + gamma*x*x;
8 ELSE
9 yp = alpha + beta*x0 + gamma*x0*x0;
10 
11 model y ~ residual(yp);
12 
13 estimate 'join point' -beta/2/gamma;
14 estimate 'plateau value c' alpha - beta**2/(4*gamma);
15 predict 'predicted' yp pred=yp;
16 predict 'response' y pred=y;
17 predict 'x' x pred=x;
18RUN;
3 Code Block
PROC SGPLOT
Explanation :
This procedure generates a high-quality graph to visualize the model results. It uses dataset 'b' (produced by PROC HPNLMOD). The Y-axis is labeled 'Observed or Predicted'. Two reference lines are added: a horizontal one for the 'Plateau' (y-value=0.7775) and a vertical one for the 'Join point' (x-value=12.7477). A scatter plot displays the observed data ('y' vs 'x'), and a series of lines ('series') represents the predicted values ('yp' vs 'x'), allowing a visual comparison between observations and the segmented model fit.
Copied!
1PROC SGPLOT DATA=b noautolegend;
2 yaxis label='Observed or Predicted';
3 refline 0.7775 / axis=y label="Plateau" labelpos=min;
4 refline 12.7477 / axis=x label="Join point" labelpos=min;
5 scatter y=y x=x;
6 series y=yp x=x;
7RUN;
This material is provided "as is" by We Are Cas. There are no warranties, expressed or implied, as to merchantability or fitness for a particular purpose regarding the materials or code contained herein. We Are Cas is not responsible for errors in this material as it now exists or will exist, nor does We Are Cas provide technical support for it.
Copyright Info : S A S S A M P L E L I B R A R Y