The REG Procedure

Example 100.1 Modeling Salaries of Major League Baseball Players

(View the complete code for this example.)

This example features the use of ODS Graphics in the process of building models by using the REG procedure and highlights the use of fit and influence diagnostics.

The Sashelp.Baseball data set contains salary and performance information for Major League Baseball players who played at least one game in both the 1986 and 1987 seasons, excluding pitchers. The salaries (Sports Illustrated, April 20, 1987) are for the 1987 season and the performance measures are from 1986 (Collier Books, The 1987 Baseball Encyclopedia Update). The following step displays in Output 100.1.1 the variables in the data set:

proc contents varnum data=sashelp.baseball;
   ods select position;
run;

Output 100.1.1: Sashelp.Baseball Data Set

The CONTENTS Procedure

Variables in Creation Order
#VariableTypeLenLabel
1NameChar18Player's Name
2TeamChar14Team at the End of 1986
3nAtBatNum8Times at Bat in 1986
4nHitsNum8Hits in 1986
5nHomeNum8Home Runs in 1986
6nRunsNum8Runs in 1986
7nRBINum8RBIs in 1986
8nBBNum8Walks in 1986
9YrMajorNum8Years in the Major Leagues
10CrAtBatNum8Career Times at Bat
11CrHitsNum8Career Hits
12CrHomeNum8Career Home Runs
13CrRunsNum8Career Runs
14CrRbiNum8Career RBIs
15CrBBNum8Career Walks
16LeagueChar8League at the End of 1986
17DivisionChar8Division at the End of 1986
18PositionChar8Position(s) in 1986
19nOutsNum8Put Outs in 1986
20nAsstsNum8Assists in 1986
21nErrorNum8Errors in 1986
22SalaryNum81987 Salary in $ Thousands
23DivChar16League and Division
24logSalaryNum8Log Salary


Suppose you want to investigate whether you can model the players’ salaries for the 1987 season based on batting statistics for the previous season and lifetime batting performance. Since the variation in salaries is much greater for higher salaries, it is appropriate to apply a log transformation for this analysis. The following statements begin the analysis:

ods graphics on;

proc reg data=sashelp.baseball;
   id name team league;
   model logSalary = nhits nruns nrbi nbb yrmajor crhits;
run;

Output 100.1.2 shows the default output produced by PROC REG. The number of observations table shows that 59 observations are excluded because they have missing values for at least one of the variables used in the analysis. The analysis of variance and parameter estimates tables provide details about the fitted model.

Output 100.1.2: Default Output from PROC REG

The REG Procedure
Model: MODEL1
Dependent Variable: logSalary Log Salary

Number of Observations Read322
Number of Observations Used263
Number of Observations with Missing Values59

Analysis of Variance
SourceDFSum of
Squares
Mean
Square
F ValuePr > F
Model6121.5305220.2550960.56<.0001
Error25685.623220.33447  
Corrected Total262207.15373   

Root MSE0.57833R-Square0.5867
Dependent Mean5.92722Adj R-Sq0.5770
Coeff Var9.75719  

Parameter Estimates
VariableLabelDFParameter
Estimate
Standard
Error
t ValuePr > |t|
InterceptIntercept14.146140.1361230.46<.0001
nHitsHits in 198610.006630.002103.150.0018
nRunsRuns in 198610.000198900.003980.050.9602
nRBIRBIs in 198610.001250.002350.530.5947
nBBWalks in 198610.006720.002392.810.0054
YrMajorYears in the Major Leagues10.071080.019253.690.0003
CrHitsCareer Hits10.000239100.000145711.640.1020


Before you accept a regression model, it is important to examine influence and fit diagnostics to see whether the model might be unduly influenced by a few observations and whether the data support the assumptions that underlie the linear regression. To facilitate such investigations, you can obtain diagnostic plots by enabling ODS Graphics.

Output 100.1.3: Fit Diagnostics

Fit Diagnostics


Output 100.1.3 shows a panel of diagnostic plots. The plot of externally studentized residuals (RStudent) by leverage values reveals that there is one observation with very high leverage that might be overly influencing the fit produced. The plot of Cook’s D by observation also indicates two highly influential observations. To investigate further, you can use the PLOTS= option in the PROC REG statement as follows to produce labeled versions of these plots:

proc reg data=sashelp.baseball
         plots(only label)=(RStudentByLeverage CooksD);
   id name team league;
   model logSalary = nhits nruns nrbi nbb yrmajor crhits;
run;

Output 100.1.4 and Output 100.1.5 reveal that Pete Rose is the highly influential observation. You might obtain a better fit to the remaining data if you omit his statistics when building the model.

Output 100.1.4: Outlier and Leverage Diagnostics

Outlier and Leverage Diagnostics


Output 100.1.5: Cook’s D

Cook’s


The following statements use a WHERE statement to omit Pete Rose’s statistics when building the model. An alternative way to do this within PROC REG is to use a REWEIGHT statement. See Reweighting Observations in an Analysis for details about reweighting.

proc reg data=sashelp.baseball
         plots=(RStudentByLeverage(label) residuals(smooth));
   where name^="Rose, Pete";
   id name team league;
   model logSalary = nhits nruns nrbi nbb yrmajor crhits;
run;

Output 100.1.6 shows the new fit diagnostics panel. You can see that there are still several influential and outlying observations. One possible reason for observing outliers is that the linear model specified is not appropriate to capture the variation in this data. You can often see evidence of an inappropriate model by observing patterns in plots of residuals.

Output 100.1.6: Fit Diagnostics

Fit Diagnostics


Output 100.1.7 shows plots of the residuals by the regressors in the model. When you specify the RESIDUALS(SMOOTH) suboption of the PLOTS option in the PROC REG statement, a loess fit is overlaid on each of these plots. You can see the same clear pattern in the residual plots for YrMajor and CrHits. Players near the start of their careers and players near the end of their careers get paid less than the model predicts.

Output 100.1.7: Residuals by Regressors

Residuals by Regressors


You can address this lack of fit by using polynomials of degree 2 for these two variables as shown in the following statements:

data baseball;
   set sashelp.baseball(where=(name^="Rose, Pete"));
   YrMajor2 = yrmajor*yrmajor;
   CrHits2  = crhits*crhits;
run;

proc reg data=baseball
      plots=(diagnostics(stats=none) RStudentByLeverage(label)
             CooksD(label) Residuals(smooth)
             DFFITS(label) DFBETAS ObservedByPredicted(label));
   id name team league;
   model logSalary = nhits nruns nrbi nbb yrmajor crhits
                     yrmajor2 crhits2;
run;

Output 100.1.8 shows the analysis of variance and parameter estimates for this model. Note that the R-square value of 0.787 for this model is considerably larger than the R-square value of 0.587 for the initial model shown in Output 100.1.2.

Output 100.1.8: Output from PROC REG

The REG Procedure
Model: MODEL1
Dependent Variable: logSalary Log Salary

Analysis of Variance
SourceDFSum of
Squares
Mean
Square
F ValuePr > F
Model8162.7347320.34184117.13<.0001
Error25343.937120.17366  
Corrected Total261206.67186   

Root MSE0.41673R-Square0.7874
Dependent Mean5.92458Adj R-Sq0.7807
Coeff Var7.03393  

Parameter Estimates
VariableLabelDFParameter
Estimate
Standard
Error
t ValuePr > |t|
InterceptIntercept13.789220.1158132.72<.0001
nHitsHits in 19861-0.000127530.00159-0.080.9363
nRunsRuns in 198610.002150.002880.750.4549
nRBIRBIs in 198610.004310.001722.510.0127
nBBWalks in 198610.005010.001732.900.0040
YrMajorYears in the Major Leagues10.239080.034436.94<.0001
CrHitsCareer Hits10.001700.000275626.18<.0001
YrMajor2 1-0.014400.00165-8.73<.0001
CrHits2 1-3.31739E-71.001272E-7-3.310.0011


The plots of residuals by regressors in Output 100.1.9 and Output 100.1.10 show that the strong pattern in the plots for CrMajors and CrHits has been reduced, although there is still some indication of a pattern remaining in these residuals. This suggests that a quadratic function might be insufficient to capture dependence of salary on these regressors.

Output 100.1.9: Residuals by Regressors

Residuals by Regressors


Output 100.1.10: Residuals by Regressors

Residuals by Regressors


Output 100.1.11 show the diagnostics plots; three of the plots, with points of interest labeled, are shown individually in Output 100.1.12, Output 100.1.13, and Output 100.1.14. The STATS=NONE suboption specified in the PLOTS=DIAGNOSTICS option replaces the inset of statistics with a box plot of the residuals in the fit diagnostics panel. The observed by predicted value plot reveals a reasonably successful model for explaining the variation in salary for most of the players. However, the model tends to overpredict the salaries of several players near the lower end of the salary range. This bias can also be seen in the distribution of the residuals that you can see in the histogram, Q-Q plot, and box plot in Output 100.1.11.

Output 100.1.11: Fit Diagnostics

Fit Diagnostics


Output 100.1.12: Outlier and Leverage Diagnostics

Outlier and Leverage Diagnostics


Output 100.1.13: Observed by Predicted Values

Observed by Predicted Values


Output 100.1.14: Cook’s D

Cook’s


The RStudent by leverage plot in Output 100.1.12 and the Cook’s D plot in Output 100.1.14 show that there are still a number of influential observations. By specifying the DFFITS and DFBETAS suboptions of the PLOTS= option, you obtain the additional influence diagnostics plots shown in Output 100.1.15 and Output 100.1.16. For more information about the interpretation of DFFITS and DFBETAS statistics, see the section Influence Statistics.

You can continue this analysis by investigating how the influential observations that are identified in the various influence plots affect the fit. You can also use PROC ROBUSTREG to obtain a fit that is resistant to the presence of high-leverage points and outliers.

You can create marginal fit diagnostic plots outside PROC REG by using the %Marginal autocall macro. Marginal model plots (Cook and Weisberg 1997) display the marginal relationship between the response and each predictor. Each plot contains a scatter plot of the two variables overlaid with two curves: a smooth fit function for the variables in the plot (labeled "Data") and the overall model predicted values (labeled "Model"). One additional plot displays predicted values on the horizontal axis rather than an independent variable. (See Output 100.1.17.) When the two curves are similar in each of the graphs, there is evidence that the model fits well. When they differ in at least one of the graphs, there is evidence that the model does not fit well.

Output 100.1.15: DFFITS

DFFITS


Output 100.1.16: DFBETAS

DFBETAS


The following statements refit the last model, create a data set that contains predicted values, and use the %Marginal autocall macro to display the marginal model plots:

%let ind = nhits nruns nrbi nbb yrmajor crhits yrmajor2 crhits2;
proc reg data=baseball plots=none;
   model logSalary = &ind;
   output out=pred p=p;
run;

%marginal(dependent=logSalary, predicted=p, independents=&ind)

The independent variables are specified in a macro variable for convenience to avoid listing them twice; this is not required. Output 100.1.17 displays the results and shows that the model fits less well for the players who spent the most time in the major leagues.

The macro requires you to specify the dependent variable, predicted values variable, and independent variables. The macro input data set is the output data set from PROC REG. Additional options are available. For more information about the %Marginal macro, see the section Marginal Model Plots in Chapter 22: ODS Graphics Template Modification.

Output 100.1.17: Marginal Model Plots

Marginal Model Plots


Last updated: February 13, 2019