The ORTHOREG Procedure

Example 85.3 Fitting Polynomials

(View the complete code for this example.)

The extra accuracy of the regression algorithm used by PROC ORTHOREG is most useful when the model contains near-singularities that you want to be able to distinguish from true singularities. This example demonstrates this usefulness in the context of fitting polynomials of high degree.

Note: The results from this example vary from machine to machine, depending on floating-point configuration.

The following DATA step computes a response y as an exact ninth-degree polynomial function of a predictor x evaluated at 0, 0.01, 0.02, …, 1.

title 'Polynomial Data';
data Polynomial;
   do i = 1 to 101;
      x = (i-1)/(101-1);
      y = 10**(9/2);
      do j = 0 to 8;
         y = y * (x - j/8);
      end;
      output;
   end;
run;

The polynomial is constructed in such a way that its zeros lie at for . The following statements use the EFFECT statement to fit a ninth-degree polynomial to this data with PROC ORTHOREG. The EFFECT statement makes it easy to specify complicated polynomial models.

ods graphics on;

proc orthoreg data=Polynomial;
   effect xMod = polynomial(x / degree=9);
   model y = xMod;
   effectplot fit / obs;
   store OStore;
run;

ods graphics off;

The effect xMod defined by the EFFECT statement refers to all nine degrees of freedom in the ninth-degree polynomial (excluding the intercept term). The resulting output is shown in Output 85.3.1. Note that the R square for the fit is 1, indicating that the ninth-degree polynomial has been correctly fit.

Output 85.3.1: PROC ORTHOREG Results for Ninth-Degree Polynomial

Polynomial Data

The ORTHOREG Procedure
 
Dependent Variable: y

SourceDFSum of SquaresMean SquareF ValuePr > F
Model915.5271800551.72524222841.65E22<.0001
Error919.496616E-211.043584E-22  
Corrected Total10015.527180055   

Root MSE1.02156E-11
R-Square1

ParameterDFParameter EstimateStandard
Error
t ValuePr > |t|
Intercept1-3.24572035915E-118.114115E-12-4.000.0001
x175.99773124406784.898326E-101.55E11<.0001
x^21-1652.407813621919.5027919E-9-174E9<.0001
x^3114249.45397697838.3110512E-81.71E11<.0001
x^41-64932.4615752053.8997072E-7-167E9<.0001
x^51173315.3593607791.066611E-61.62E11<.0001
x^61-280158.036460021.7523078E-6-16E10<.0001
x^71269781.8128876531.7021134E-61.58E11<.0001
x^81-142302.4947100559.0027891E-7-158E9<.0001
x^9131622.77660224681.997493E-71.58E11<.0001


The fit plot produced by the EFFECTPLOT statement, Output 85.3.2, also demonstrates the perfect fit.

Output 85.3.2: PROC ORTHOREG Fit Plot for Ninth-Degree Polynomial

PROC ORTHOREG Fit Plot for Ninth-Degree Polynomial


Finally, you can use the PLM procedure with the fit model saved by the STORE statement in the item store OStore to check the predicted values for the known zeros of the polynomial, as shown in the following statements:

data Zeros(keep=x);
   do j = 0 to 8;
      x = j/8;
      output;
   end;
run;

proc plm restore=OStore noprint;
   score data=Zeros out=OZeros pred=OPred;
run;

proc print noobs;
run;

The predicted values of the zeros, shown in Output 85.3.3, are again all minuscule.

Output 85.3.3: Predicted Zeros for Ninth-Degree Polynomial

Polynomial Data

xOPred
0.000-3.2457E-11
0.125-2.1262E-11
0.250-9.5867E-12
0.375-2.2895E-11
0.500-5.2154E-11
0.625-1.2329E-10
0.750-2.5329E-10
0.875-3.9836E-10
1.000-5.9663E-10


To compare these results with those from a least squares fit produced by an alternative algorithm, consider fitting a polynomial to this data using the GLM procedure. PROC GLM does not have an EFFECT statement, but the familiar bar notation can still be used to specify a ninth-degree polynomial fairly succinctly, as shown in the following statements:

proc glm data=Polynomial;
   model y = x|x|x|x|x|x|x|x|x;
   store GStore;
run;

Partial results are shown in Output 85.3.4. In this case, the R square for the fit is only about 0.83, indicating that the full ninth-degree polynomial was not correctly fit.

Output 85.3.4: PROC GLM for Ninth-Degree Polynomial

Polynomial Data

The GLM Procedure
 
Dependent Variable: y

SourceDFSum of SquaresMean SquareF ValuePr > F
Model812.911666431.6139583056.77<.0001
Error922.615513630.02842950  
Corrected Total10015.52718006   

R-SquareCoeff VarRoot MSEy Mean
0.831553-6.6691E170.168610-0.000000


The following statements, which use the PLM procedure to compute predictions based on the GLM fit at the true zeros of the polynomial, also confirm that PROC GLM is not able to correctly fit a polynomial of this degree, as shown in Output 85.3.5.

proc plm restore=GStore noprint;
   score data=Zeros out=GZeros pred=GPred;
run;

data Zeros;
   merge OZeros GZeros;
run;

proc print noobs;
run;

Output 85.3.5: Predicted Zeros for Ninth-Degree Polynomial

Polynomial Data

xOPredGPred
0.000-3.2457E-110.44896
0.125-2.1262E-110.22087
0.250-9.5867E-12-0.19037
0.375-2.2895E-110.12710
0.500-5.2154E-110.00000
0.625-1.2329E-10-0.12710
0.750-2.5329E-100.19037
0.875-3.9836E-10-0.22087
1.000-5.9663E-10-0.44896