'Life is after all a recursive summation, indeed     Let's do some Statistics!

Department of Civil and Environmental Engineering
Frank Batten College of Engineering and Technology
Old Dominion University
Norfolk, Virginia 23529-0241, USA
Tel) (757) 683-3753
Fax) (757) 683-5354


	
Return to CEE 700/800 Homepage
CEE 700/800 Access Counter
 
Go back to
SAS Source Page
Linear Least-Square Regression
SAS Source: LS_REG.SAS

Description

Straightforward example on simple linear least-square regression method -- all self-explanatory.

Examine comments in the source carefully for specific model options.

SAS Listing


OPTIONS LINESIZE=80; 
TITLE1 'Linear Least-Square Regression Example';
TITLE2 'Dependent Variable, Y: Oxygen Purity (%)';
TITLE3 'Independent Variable, X:  Hydrocarbon Level (%)';
DATA ChemHC;
/* @@ means a loop in reading input variable sequence */
INPUT Purity H_Carbon @@;  
CARDS;
90.01  0.99     89.05  1.02     91.43  1.15  
93.74  1.29     96.73  1.46     94.45  1.36  
87.59  0.87     91.77  1.23     99.42  1.55  
93.65  1.40     93.54  1.19     92.52  1.15  
90.56  0.98     89.54  1.01     89.85  1.11  
90.39  1.20     93.25  1.26     93.41  1.32  
94.98  1.43     87.33  0.95  
;  
RUN;

/* Print the original data set                   */
PROC PRINT; 
RUN;

/* Regression Procedure                          */
PROC REG DATA=ChemHC;  
  MODEL Purity = H_Carbon /P R;  
/* P = Calculates predicted values from the      */
/*     input data and the estimated regression   */ 
/*     model                                     */ 
/* R = Calculate the analysis of the residuals   */ 

/* Create output dataset "A" for later plotting  */ 
  OUTPUT OUT=A P=YHAT R=RESID STUDENT=STDR;  
RUN;

/* Plot output sub-datasets 'YHAT', 'RESID' and 'STDR'   */
/* from the regression analysis output dataset "A"  */ 
PROC PLOT DATA=A; 
  PLOT RESID * YHAT; 
  PLOT STDR * YHAT;  
RUN;

/* Compute Normal Scores of input data, 'A'      */
/* using cum. normal function/Residual           */
/* BLOM -> yi = þ-1(ri -3/8)/(n+1/4)              */
/*         ri = rank of the ith obs              */
PROC RANK DATA=A NORMAL=BLOM OUT=NPLOT;
  VAR RESID;
  RANKS NSCORE;
RUN;

PROC PLOT DATA=NPLOT;
  PLOT NSCORE * RESID;  
RUN;

/* Compute Normal Scores of input data, 'A'      */
/* using cum. normal function/Studentized Residual */
/* BLOM -> yi = þ-1(ri -3/8)/(n+1/4)              */
/*         ri = rank of the ith obs              */
PROC RANK DATA=A NORMAL=BLOM OUT=NPLOT;
  VAR STDR; 
  RANKS NTSCORE;  
RUN;

PROC PLOT DATA=NPLOT;
  PLOT NTSCORE * STDR;
RUN;



SAS Listing

Above SAS source can be simplified into a skeleton source for a simple linear least-square regression.


OPTIONS LINESIZE=80; 
TITLE1 'Linear Least-Square Regression Example';
TITLE2 'Dependent Variable, Y: Oxygen Purity (%)';
TITLE3 'Independent Variable, X:  Hydrocarbon Level (%)';
DATA ChemHC;
/* @@ means a loop in reading input variable sequence */
INPUT Purity H_Carbon @@;  
CARDS;
90.01  0.99     89.05  1.02     91.43  1.15  
93.74  1.29     96.73  1.46     94.45  1.36  
87.59  0.87     91.77  1.23     99.42  1.55  
93.65  1.40     93.54  1.19     92.52  1.15  
90.56  0.98     89.54  1.01     89.85  1.11  
90.39  1.20     93.25  1.26     93.41  1.32  
94.98  1.43     87.33  0.95  
;  
RUN;

/* Regression Procedure                          */
PROC REG DATA=ChemHC;  
  MODEL Purity = H_Carbon ;  
RUN;


SAS User Guide (SUG) for Procedures (PROC) used in the Source

SUG PLOT procedure
SUG PRINT procedure
SUG RANK procedure
SUG REG procedure
Go back to
SAS Source Page

Return to CEE 700/800 Homepage Return to CEE 700/800 Homepage Move to the Top of this page