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.
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!
proc hpnlmod data=a out=b;
parms alpha=.45 beta=.05 gamma=-.0025;
x0 = -.5*beta / gamma;
if (x < x0) then
yp = alpha + beta*x + gamma*x*x;
else
yp = alpha + beta*x0 + gamma*x0*x0;
model y ~ residual(yp);
estimate 'join point' -beta/2/gamma;
estimate 'plateau value c' alpha - beta**2/(4*gamma);
predict 'predicted' yp pred=yp;
predict 'response' y pred=y;
predict 'x' x pred=x;
run;
1
PROC HPNLMODDATA=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;
18
RUN;
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.
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.
SAS and all other SAS Institute Inc. product or service names are registered trademarks or trademarks of SAS Institute Inc. in the USA and other countries. ® indicates USA registration. WeAreCAS is an independent community site and is not affiliated with SAS Institute Inc.
This site uses technical and analytical cookies to improve your experience.
Read more.