Published on :
Statistical CREATION_INTERNE

Nonlinear Regression for Patient Prognosis

This code is also available in: Deutsch Español Français
Awaiting validation
The script analyzes data from 15 patients to predict a recovery prognosis index (prog) based on the number of hospitalization days (days). First, it uses a DATA step to create the 'patient' table from embedded data (cards). Then, it fits an exponential nonlinear regression model `prog = a0*exp(a1*days)` with PROC NLIN. It generates predictions, residuals, and confidence intervals. Graphs (PROC GPLOT) are created to visualize raw data and model fit. In parallel, a second linear regression model is tested on the logarithm of the response variable (`ln(prog)`) with PROC REG to compare approaches.
Data Analysis

Type : CREATION_INTERNE


Data is created directly in the script via a DATA step and the 'cards' statement, forming the 'patient' table with 15 observations and 3 variables (prog, days, lnprog).

1 Code Block
DATA STEP Data
Explanation :
This block creates the 'patient' table in memory. It reads two variables, 'prog' (prognosis index) and 'days' (days of hospitalization), from the data provided via the 'cards' statement. It also calculates 'lnprog', the natural logarithm of 'prog'.
Copied!
1DATA patient;
2INPUT prog days;
3lnprog=log(prog);
4CARDS;
5 54 2
6 50 5
7 45 7
8 37 10
9 35 14
10 25 19
11 20 26
12 16 31
13 18 34
14 13 38
15 8 45
16 11 52
17 8 53
18 4 60
19 6 65
20 ;
21RUN;
2 Code Block
PROC NLIN
Explanation :
This procedure fits a nonlinear regression model. The model has an exponential form: `prog = a0*exp(a1*days)`. Initial values for parameters `a0` and `a1` are provided. The procedure calculates parameter estimates and generates an output table 'a' containing predicted values, residuals, and 90% confidence and prediction intervals (alpha=0.1).
Copied!
1PROC NLIN alpha=0.1;
2parameters a0=10
3 a1=-1;
4 model prog = a0*exp(a1*days);
5 OUTPUT out=a p=p r=resid lcl=lci ucl=uci lclm=l90 uclm=u90;
6RUN;
3 Code Block
PROC PRINT
Explanation :
Prints the content of table 'a' generated by PROC NLIN, which contains the modeling results (observed, predicted values, residuals, etc.).
Copied!
1PROC PRINT DATA=a;
2RUN;
4 Code Block
PROC PLOT
Explanation :
The PROC PLOT procedure is used to create a graph of residuals versus predicted values, to graphically assess the appropriateness of the nonlinear model.
Copied!
1PROC PLOT;
2plot resid*p;
3RUN;
5 Code Block
PROC GPLOT
Explanation :
This block configures graphical options (goptions, title, symbol, axis) to generate graphs. The first PROC GPLOT creates a scatter plot of the original data. The second superimposes the fitted model curve on the scatter plot to visualize the fit.
Copied!
1goptions reset=global gunit=pct border cback=white
2 colors=(black blue green red)
3 ftitle=swissb ftext=swiss htitle=4 htext=4;
4title1 'Prognostic index versus Days';
5symbol1 color=red
6 interpol=none
7 value=dot
8 height=3;
9symbol2 color=red
10 interpol=join;
11 axis1 label=('Days')
12 order=(0 to 70 BY 10)
13 width=3;
14 axis2 label=('Pyrene')
15 order=(0 to 60 BY 10)
16 width=3;
17 
18PROC GPLOT DATA=a;
19 plot prog*days/ haxis=axis1 vaxis=axis2;
20 RUN;
21 
22PROC GPLOT DATA=a;
23 plot prog*days p*days/ overlay haxis=axis1 vaxis=axis2;
24 RUN;
25QUIT;
6 Code Block
PROC REG
Explanation :
For comparison purposes, this procedure performs a simple linear regression on the 'lnprog' variable (logarithm of the prognosis index) as a function of 'days'. The results, including predicted values and residuals, are stored in table 'b'.
Copied!
1PROC REG;
2model lnprog=days;
3 OUTPUT out=b p=pln r=residln;
4RUN;
7 Code Block
PROC PLOT
Explanation :
This block uses PROC PLOT to display the residual plot of the linear model versus predicted values. This allows checking the homoscedasticity assumption (constant variance of residuals) for the log-linear model.
Copied!
1PROC PLOT;
2plot residln*pln;
3RUN;
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 : Data source: Textbook 'Applied Linear Statistical Model', Kutner et al. (5th), p.515. Original file name: ch13-patient-nonlinear.sas