Quantile Regression Modeling Action Set

Salary Data for Baseball Players

This section contains PROC CAS code.

Note: Input data must be accessible in your CAS session, either as a CAS table or as a transient-scope table. A CAS table has a two-level name: the first level is your CAS engine libref, and the second level is the table name. You refer to this table in the CAS procedure by specifying only the second level. For more information about two-level names, see Chapter 2, Shared Concepts. A transient-scope table is called directly from the action and exists in memory for the duration of the action. For more information about accessing data, see SAS Viya: System Programming Guide. For more information about PROC CAS and programming in CASL, see SAS Cloud Analytic Services: CASL Programmer’s Guide and SAS Cloud Analytic Services: CASL Reference.

The following example is modeled on the example in the section "Getting Started: QUANTSELECT Procedure" in the SAS/STAT User's Guide. The Sashelp.baseball data set contains salary and performance information for Major League Baseball (MLB) players, excluding pitchers, who played in at least one game in both the 1986 and 1987 seasons. The salaries (Time Inc. 1987) are for the 1987 season, and the performance measures are for the 1986 season (Reichler 1987).

The following statements display the variables in the data set. Output 18.1.1 shows the results.

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

Output 18.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


You can load the Sashelp.Baseball data set into your CAS session by naming your CAS engine libref in the first statement of the following DATA step:

data mycas.baseball;
   set sashelp.baseball;
run;

These statements assume that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.

Suppose you want to investigate how the MLB players’ salaries for the 1987 season depend on performance measures for the players’ previous season and MLB career. You might worry that some players who are outliers could dominate your least squares analysis. To address this concern, you can use the following statements to obtain a median regression model, which is equivalent to the 50th conditional percentile (the quantile regression model at quantile level 0.5):

proc cas;
   action quantreg.quantreg/
      table={name='baseball'},
      class={'league','division'},
      model={depvars='Salary',
             effects={'nAtBat', 'nHits', 'nHome', 'nRuns',
                      'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                      'crHits', 'crHome', 'crRuns', 'crRbi',
                      'crBB', 'league', 'division', 'nOuts',
                      'nAssts', 'nError'}};
run;

If you do not use the selection parameter, the quantreg action fits the full model that is specified by the model parameter without any effect selection.

Output 18.1.2 displays the data source and the response variable.

Output 18.1.2: Model Information

Results from quantreg.quantreg

Model Information
Data SourceBASEBALL
Response VariableSalary


Output 18.1.3 displays information about the number of observations, class levels, and dimensions.

Output 18.1.3: Number of Observations, Class Level Information, and Dimensions Tables

Number of Observations Read322
Number of Observations Used263

Class Level Information
ClassLevelsValues
League2American National
Division2East West

Dimensions
DescriptionValue
Number of Effects19
Number of Parameters21


The "Number of Observations" table in Output 18.1.3 shows that, of the 322 observations, the quantreg action uses only 263 observations for model fitting (and ignores 59 incomplete observations).

The "Class Level Information" table in Output 18.1.3 shows level information for two classification effects that the class parameter identifies: League and Division. League has two levels: American and National. Division also has two levels: East and West.

The "Dimensions" table in Output 18.1.3 shows that the model parameter identifies 19 effects for model fitting besides the intercept effect. Because the 19 effects include two classification effects and each level of a classification effect corresponds to a parameter, the 19 effects contain a total of 21 parameters.

The "Fit Statistics" table in Output 18.1.4 shows the values of model fitting criteria for the fitted median model. For more information about model fitting criteria for quantile regression, see the section Details.

Output 18.1.4: Fit Statistics

Results from quantreg.quantreg
 
Quantile Level = 0.5

Objective Function25977
R10.40584
Adj R10.36200
AIC2453.81587
AICC2456.94344
SBC2521.68680
ACL98.77118


The "Parameter Estimates" table in Output 18.1.5 shows the parameter estimates of the fitted median model. Among the 19 effective parameters whose degrees of freedom are not zero, the fitted model contains 13 insignificant parameters whose 95% confidence intervals cover zeros. Because more than half of the 19 effective parameters are insignificant, you might worry that the model is overfitted.

Output 18.1.5: Parameter Estimates

Parameter Estimates
ParameterDFEstimateStandard
Error
t ValuePr > |t|
Intercept1-67.7532239.95908-1.700.0912
nAtBat1-1.571120.44700-3.510.0005
nHits18.821921.949904.52<.0001
nHome1-5.917574.91015-1.210.2293
nRuns1-5.170762.14914-2.410.0169
nRBI10.775472.154690.360.7192
nBB15.288661.676033.160.0018
YrMajor16.618776.617981.000.3182
CrAtBat1-0.044630.15485-0.290.7734
CrHits10.078960.735940.110.9146
CrHome13.782311.900651.990.0477
CrRuns11.231050.771371.600.1118
CrRbi1-0.706950.76888-0.920.3588
CrBB1-0.689110.41382-1.670.0971
League American1-34.3913624.37175-1.410.1595
League National00...
Division East160.3085627.287302.210.0280
Division West00...
nOuts10.232730.121101.920.0558
nAssts10.098240.188880.520.6035
nError1-0.815743.51436-0.230.8166


It is well known that both overfitting and underfitting harm the prediction performance of a model. You can prevent overfitting and underfitting by using an effect-selection method. The following statements apply the forward selection method and the SL (significance level) criterion to choose a parsimonious model for the baseball data table:

proc cas;
   action quantreg.quantreg/
      table={name='baseball'},
      class={'league','division'},
      model={depvars='Salary',
             effects={'nAtBat', 'nHits', 'nHome', 'nRuns',
                      'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                      'crHits', 'crHome', 'crRuns', 'crRbi',
                      'crBB', 'league', 'division', 'nOuts',
                      'nAssts', 'nError'},
             stb=1,
             clb=1},
      selection={method='forward', select='sl', sle=0.1};
run;

The stb subparameter in the model parameter requests the standardized parameter estimates. The clb subparameter in the model parameter requests 95% confidence limits for the parameter estimates. The sle=0.1 subparameter in the selection parameter specifies the significance level for entry. A candidate effect can enter the model at a certain selection step only if the following conditions are met:

  • Its p-value is the smallest among all the valid candidate effects.

  • Its p-value is smaller than 0.1 (the significance level for entry).

Output 18.1.6: Selection Information

Results from quantreg.quantreg

Selection Information
Selection MethodForward
Select CriterionSignificance Level
Stop CriterionSignificance Level
Effect Hierarchy EnforcedNone
Entry Significance Level (SLE)0.1
Stop Horizon1


The "Selection Information" table in Output 18.1.6 provides details about the method and criteria used to perform the model selection. The requested selection method is the forward selection method, in which the decisions about what effects to add at any step and when to terminate the selection are both based on the significance level criterion.

Output 18.1.7: Selection Summary

Results from quantreg.quantreg
 
Quantile Level = 0.5
Selection Details

Selection Summary
StepEffect
Entered
Number
Effects In
p Value
0Intercept1.
1CrHome2<.0001
2nHits3<.0001
3CrHits4<.0001
4nOuts50.0185
5nAtBat60.0182
6Division70.0118
7nBB80.0647
8nRuns90.0558


Each row in the "Selection Summary" table in Output 18.1.7 shows the effect that enters the model at the corresponding step of the effect selection process together with its p-value for adding the effect into the model at that step.

Output 18.1.8: Stopping and Selection Reasons

Selection stopped because no candidate for entry is significant at the 0.1 level.

The model at step 8 is selected.

Selected Effects:Intercept nAtBat nHits nRuns nBB CrHits CrHome Division nOuts


The "Stop Reason" and "Selection Reason" tables in Output 18.1.8 indicate that effect selection stopped because no candidate for entry was significant at the 0.1 level after step 8. The "Selected Effects" table in Output 18.1.8 lists the effects that are included in the selected model.

Output 18.1.9: Details of the Selected Model

Results from quantreg.quantreg
 
Quantile Level = 0.5
Selected Model

Objective Function26568
R10.39232
Adj R10.37318
AIC2445.64547
AICC2446.35693
SBC2477.79485
ACL101.01768

Parameter Estimates
ParameterDFEstimateStandardized
Estimate
Standard
Error
95% Confidence Limitst ValuePr > |t|
Intercept1-130.65536033.04546-195.73336-65.57735-3.95<.0001
nAtBat1-1.20522-0.381060.41690-2.02624-0.38419-2.890.0042
nHits17.766670.757411.810454.2012711.332074.29<.0001
nRuns1-3.92180-0.217981.87567-7.61566-0.22795-2.090.0375
nBB13.920490.186911.043411.865655.975323.760.0002
CrHits10.176970.254550.068560.041950.311982.580.0104
CrHome11.669390.318400.730830.230123.108662.280.0232
Division East165.143270.0723324.4803816.93289113.353642.660.0083
Division West000.....
nOuts10.237190.147180.114030.012610.461762.080.0385


The "Fit Statistics" and "Parameter Estimates" tables in Output 18.1.9 give details of the final selected model. You can see that all nine effective parameters (excluding Division West) are significant at the 5% significance level, corresponding to the 95% confidence limits.

Like the sample median, a median regression model is robust to extreme observations, because it depends only on a small middle subset of all the observations in the data table. However, it is less representative of the entire conditional distribution of the response variable. You might want to further investigate the mycas.baseball data table at other quantile levels. The following statements select quantile regression models at the quantile levels 0.1 and 0.9, which correspond to the 10% and 90% conditional percentiles of the players’ salaries:

proc cas;
   action quantreg.quantreg/
      table={name='baseball'},
      alpha=0.1,
      class={'league','division'},
      model={depvars='Salary',
             effects={'nAtBat', 'nHits', 'nHome', 'nRuns',
                      'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                      'crHits', 'crHome', 'crRuns', 'crRbi',
                      'crBB', 'league', 'division', 'nOuts',
                      'nAssts', 'nError'},
             quantile={0.1, 0.9},
             stb=1,
             clb=1},
      selection={method='backward', select='sl', sle=0.1};
run;

The alpha=0.1 parameter in the quantreg.quantreg action specifies the significance level to be 0.1. Combined with the clb subparameter in the model parameter, the alpha=0.1 parameter requests 90% confidence limits for parameter estimates. The quantile={0.1, 0.9} subparameter in the model parameter specifies two quantile levels, 0.1 and 0.9, for fitting quantile regression models. The method=’backward’ subparameter in the selection parameter specifies the backward elimination method for effect selection.

Output 18.1.10 and Output 18.1.11 display the "Selected Effects" and "Parameter Estimates" tables at the quantile levels 0.1 and 0.9, respectively. Note, for example, that League is selected for its very large effect on how much the high-salary players were paid, but it apparently had a negligible effect on how much the low-salary players made.

Output 18.1.10: Parameter Estimates at Quantile Level 0.1

Results from quantreg.quantreg
 
Quantile Level = 0.1
Selection Details

Selected Effects:Intercept nAtBat nHits nBB CrRuns CrBB Division nAssts

Parameter Estimates
ParameterDFEstimateStandardized
Estimate
Standard
Error
90% Confidence Limitst ValuePr > |t|
Intercept14.75224018.94983-26.5311136.035580.250.8022
nAtBat1-0.73670-0.232930.17958-1.03316-0.44024-4.10<.0001
nHits12.693960.262720.635101.645513.742414.24<.0001
nBB11.818070.086680.405951.147912.488234.48<.0001
CrRuns10.654760.486000.095600.496940.812596.85<.0001
CrBB1-0.44622-0.268420.16254-0.71454-0.17790-2.750.0065
Division East128.354060.0314810.6892210.7077446.000382.650.0085
Division West000.....
nAssts10.149580.048110.058970.052230.246942.540.0118


Output 18.1.11: Parameter Estimates at Quantile Level 0.9

Selected Effects:Intercept nHits nBB CrAtBat CrHits CrHome CrRbi League Division nOuts

Parameter Estimates
ParameterDFEstimateStandardized
Estimate
Standard
Error
90% Confidence Limitst ValuePr > |t|
Intercept120.39804058.17164-75.63745116.433530.350.7261
nHits12.308970.225170.556401.390423.227524.15<.0001
nBB13.097990.147701.444140.713865.482132.150.0329
CrAtBat1-0.44914-2.280280.14651-0.69101-0.20727-3.070.0024
CrHits12.480643.568230.517251.626723.334574.80<.0001
CrHome16.298961.201381.371344.035028.562914.59<.0001
CrRbi1-2.12293-1.545530.76546-3.38662-0.85923-2.770.0060
League American1-103.28955-0.1145133.68480-158.89975-47.67935-3.070.0024
League National000.....
Division East1107.466940.1193250.8279723.55512191.378762.110.0355
Division West000.....
nOuts10.397660.246760.128200.186010.609313.100.0021


Salary Data for Baseball Players

This section contains Lua code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the baseball data to the comma-separated-value (CSV) file baseball.csv and then use the following code to load the CSV file into CAS:

s:loadtable{casLib="casuser", path="baseball.csv"}

For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.

The following code loads the quantreg action set, and then uses the quantreg action to fit quantile regression models to the baseball data table:

s:loadactionset{actionset="quantreg"}
m1 = s:quantreg{
   table='baseball',
   class={'league','division'},
   model={depvars='Salary',
          effects={'nAtBat', 'nHits', 'nHome', 'nRuns',
                   'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                   'crHits', 'crHome', 'crRuns', 'crRbi',
                   'crBB', 'league', 'division', 'nOuts',
                   'nAssts', 'nError'} } }

The following commands display the tables that are produced by this action call:

print(m1.ModelInfo)
print(m1.NObs)
print(m1.ClassInfo)
print(m1.Dimensions)
print(m1["Quantile1.FitStatistics"])
print(m1["Quantile1.ParameterEstimates"])
print(m1.Timing)

The following command displays all the tables that are produced by this action call along with their full name paths:

for k,t in pairs(m1) do print(k) print(t) end;

The following commands perform quantile regression model selection on the baseball data table by using the forward selection method:

m2 = s:quantreg{
   table='baseball',
   class={'league','division'},
   model={depvars='Salary',
          effects={'nAtBat', 'nHits', 'nHome', 'nRuns',
                   'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                   'crHits', 'crHome', 'crRuns', 'crRbi',
                   'crBB', 'league', 'division', 'nOuts',
                   'nAssts', 'nError'},
          stb=1,
          clb=1},
   selection={method='forward', select='sl', sle=0.1} }

The following commands display the tables that are produced by this action call:

print(m2.SelectionInfo)
print(m2["Quantile1.Summary.SelectionSummary"])
print(m2["Quantile1.Summary.StopReason"])
print(m2["Quantile1.Summary.SelectionReason"])
print(m2["Quantile1.Summary.SelectedEffects"])
print(m2["Quantile1.SelectedModel.FitStatistics"])
print(m2["Quantile1.SelectedModel.ParameterEstimates"])

The following commands perform quantile regression model selection on the baseball data table for the quantile levels 0.1 and 0.9 by using the backward selection method:

m3 = s:quantreg{
   table='baseball',
   class={'league','division'},
   model={depvars='Salary',
          effects={'nAtBat', 'nHits', 'nHome', 'nRuns',
                   'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                   'crHits', 'crHome', 'crRuns', 'crRbi',
                   'crBB', 'league', 'division', 'nOuts',
                   'nAssts', 'nError'},
          quantiles={0.1, 0.9},
          stb=1,
          clb=1},
   selection={method='backward', select='sl', sle=0.1} }

The following commands display the selected effects tables and the parameter estimates tables that are produced by this action call:

print(m3["Quantile1.Summary.SelectedEffects"])
print(m3["Quantile1.SelectedModel.ParameterEstimates"])
print(m3["Quantile2.Summary.SelectedEffects"])
print(m3["Quantile2.SelectedModel.ParameterEstimates"])

For more information about the results of this analysis, see the CASL version of this example.

Salary Data for Baseball Players

This section contains Python code for the analysis in the CASL version of this example, which contains details about the results.

Note: In order to run this code, the data that are described in the CASL version need to be accessible to the CAS server. One way to do this is to convert the baseball data to the comma-separated-value (CSV) file baseball.csv and then use the following code to load the CSV file into CAS:

s.upload_file('baseball.csv')

For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.

The following code loads the quantreg action set, and then uses the quantreg action to fit quantile regression models to the baseball data table:

s.loadactionset(actionset='quantreg')
m1=s.quantreg(
    table='baseball',
    classvars=['league','division'],
    model={'depvars':'Salary',
           'effects':['nAtBat', 'nHits', 'nHome', 'nRuns',
                      'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                      'crHits', 'crHome', 'crRuns', 'crRbi',
                      'crBB', 'league', 'division', 'nOuts',
                      'nAssts', 'nError']} )

The following commands display the tables that are produced by this quantreg action call:

print(m1.ModelInfo)
print(m1.NObs)
print(m1.ClassInfo)
print(m1.Dimensions)
print(m1["Quantile1.FitStatistics"])
print(m1["Quantile1.ParameterEstimates"])
print(m1.Timing)

The following command displays all the tables that are produced by this action call along with their full name paths:

print(m1)

The following commands perform quantile regression model selection on the baseball data table by using the forward selection method:

m2=s.quantreg(
    table='baseball',
    classvars=['league','division'],
    model={'depvars':'Salary',
           'effects':['nAtBat', 'nHits', 'nHome', 'nRuns',
                      'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                      'crHits', 'crHome', 'crRuns', 'crRbi',
                      'crBB', 'league', 'division', 'nOuts',
                      'nAssts', 'nError'],
           'stb':1,
           'clb':1},
    selection={'method':'forward',
               'select':'sl',
               'sle':0.1} )

The following commands display the tables that are produced by this action call:

print(m2.SelectionInfo)
print(m2["Quantile1.Summary.SelectionSummary"])
print(m2["Quantile1.Summary.StopReason"])
print(m2["Quantile1.Summary.SelectionReason"])
print(m2["Quantile1.Summary.SelectedEffects"])
print(m2["Quantile1.SelectedModel.FitStatistics"])
print(m2["Quantile1.SelectedModel.ParameterEstimates"])

The following commands perform quantile regression model selection on the baseball data table for the quantile levels 0.1 and 0.9 by using the backward selection method:

m3=s.quantreg(
    table='baseball',
    classvars=['league','division'],
    model={'depvars':'Salary',
           'effects':['nAtBat', 'nHits', 'nHome', 'nRuns',
                      'nRBI', 'nBB', 'yrMajor', 'crAtBat',
                      'crHits', 'crHome', 'crRuns', 'crRbi',
                      'crBB', 'league', 'division', 'nOuts',
                      'nAssts', 'nError'],
           'quantiles':{0.1, 0.9},
           'stb':1,
           'clb':1},
    selection={'method':'backward',
               'select':'sl',
               'sle':0.1} )

The following commands display the selected effects tables and the parameter estimates tables that are produced by this action call:

print(m3["Quantile1.Summary.SelectedEffects"])
print(m3["Quantile1.SelectedModel.ParameterEstimates"])
print(m3["Quantile2.Summary.SelectedEffects"])
print(m3["Quantile2.SelectedModel.ParameterEstimates"])

For more information about the results of this analysis, see the CASL version of this example.

Salary Data for Baseball Players

This example is not available for the R programming language.

Last updated: September 09, 2021