Published on :
Statistical INTERNAL_CREATION

Fitting Polynomial Models with PROC ORTHOREG and GLM

This code is also available in: Deutsch Español Français
Awaiting validation
The script first generates a 'Polynomial' dataset based on a polynomial function. Then, it uses PROC ORTHOREG to fit a 9th-degree polynomial model. The model results are stored and used by PROC PLM to score the zeros of the original function. Concurrently, PROC GLM is used to fit a similar model, and predictions are also calculated with PROC PLM. Finally, the predictions from both models (ORTHOREG and GLM) are merged and displayed for comparison.
Data Analysis

Type : INTERNAL_CREATION


The script creates two datasets: 'Polynomial' and 'Zeros'. The data is entirely generated via 'do' loops in DATA steps, without relying on external sources.

1 Code Block
DATA STEP Data
Explanation :
This block creates the 'Polynomial' table. It generates 101 observations by calculating 'x' and 'y' values according to a polynomial function, without using input data.
Copied!
1title 'Polynomial Data';
2DATA Polynomial;
3 DO i = 1 to 101;
4 x = (i-1)/(101-1);
5 y = 10**(9/2);
6 DO j = 0 to 8;
7 y = y * (x - j/8);
8 END;
9 OUTPUT;
10 END;
11RUN;
2 Code Block
PROC ORTHOREG
Explanation :
This block uses the ORTHOREG procedure to perform a 9th-degree polynomial regression on the 'y' variable as a function of 'x'. The model is stored in the 'OStore' object and a plot of the fitted model is produced.
Copied!
1ods graphics on;
2 
3PROC ORTHOREG DATA=Polynomial;
4 effect xMod = polynomial(x / degree=9);
5 model y = xMod;
6 effectplot fit / obs;
7 store OStore;
8RUN;
9 
10ods graphics off;
3 Code Block
DATA STEP Data
Explanation :
This block creates the 'Zeros' table which contains the roots (zeros) of the polynomial function used to generate the initial data. These 'x' values will be used for prediction.
Copied!
1DATA Zeros(keep=x);
2 DO j = 0 to 8;
3 x = j/8;
4 OUTPUT;
5 END;
6RUN;
4 Code Block
PROC PLM
Explanation :
This procedure uses the 'OStore' model (created by PROC ORTHOREG) to calculate predicted values ('OPred') for each observation in the 'Zeros' table. The results are saved in the 'OZeros' table.
Copied!
1 
2PROC PLM restore=OStore noprint;
3score
4DATA=Zeros out=OZeros pred=OPred;
5RUN;
6 
5 Code Block
PROC PRINT
Explanation :
Displays the content of the last created table, which is 'OZeros', showing the predictions from the ORTHOREG model.
Copied!
1PROC PRINT noobs;
2RUN;
6 Code Block
PROC GLM
Explanation :
This block uses the GLM (General Linear Model) procedure to fit a 9th-degree polynomial model (specified by successive interactions of 'x'). The model is stored in 'GStore' for later use.
Copied!
1PROC GLM DATA=Polynomial;
2 model y = x|x|x|x|x|x|x|x|x;
3 store GStore;
4RUN;
7 Code Block
PROC PLM
Explanation :
Similar to the previous step, this procedure uses the 'GStore' model (created by PROC GLM) to calculate predictions ('GPred') for the 'Zeros' table. The results are stored in the 'GZeros' table.
Copied!
1 
2PROC PLM restore=GStore noprint;
3score
4DATA=Zeros out=GZeros pred=GPred;
5RUN;
6 
8 Code Block
DATA STEP Data
Explanation :
This block merges the 'OZeros' and 'GZeros' tables to create a new 'Zeros' table that contains the predictions from both models (ORTHOREG and GLM) side-by-side for easy comparison.
Copied!
1DATA Zeros;
2 MERGE OZeros GZeros;
3RUN;
9 Code Block
PROC PRINT
Explanation :
Displays the content of the final 'Zeros' table, which compares the predicted values from the ORTHOREG model ('OPred') and the GLM model ('GPred').
Copied!
1PROC PRINT noobs;
2RUN;
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