Proportional Hazards Regression Modeling Action Set
Cox Regression
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 DATA step creates the data table mycas.getStarted in your CAS session. This data table consists of 100 observations on a failure time variable (Time), an indicator variable (Status) that has two values (0 for censored observations and 1 for event observations), three classification variables (C1–C3), and four interval variables (X1–X4). This DATA step assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.getStarted;
input Time Status C1$ C2 C3$ X1-X4;
datalines;
53 0 Low 1 M 1.11 2.000 3.6128 12.0
12 0 High 1 M 1.40 1.362 3.8388 8.8
11 1 Low 1 F 1.57 1.672 3.8865 7.5
7 1 Medium 0 M 1.04 2.000 3.7324 5.1
2 1 Low 1 M 1.52 2.000 3.8751 9.8
41 0 High 1 M 1.76 1.447 3.7243 12.8
6 1 Critical 1 F 1.36 1.462 3.5441 9.0
6 1 Critical 1 M 1.42 1.690 3.9294 10.4
16 1 Medium 1 M 1.32 0.699 3.6990 8.8
41 1 Medium 1 M 1.00 1.477 3.4771 10.2
2 1 High 0 M 1.30 2.000 3.7243 5.1
58 1 Medium 1 M 1.20 1.580 3.6990 12.1
11 1 High 1 M 1.08 1.903 3.5051 9.6
12 0 Critical 1 F 1.15 1.146 3.6435 11.6
16 0 High 1 F 1.15 0.903 3.8573 13.0
54 1 Medium 1 M 1.26 1.699 3.7243 9.0
51 1 Low 0 M 1.57 1.041 3.4150 7.7
67 1 Medium 1 M 1.32 1.041 3.6435 12.8
1 1 Low 1 M 1.94 1.954 3.9868 12.0
19 0 Medium 1 M 1.32 2.000 3.7709 13.0
1 1 Medium 1 M 2.22 1.954 3.6628 9.4
35 1 Medium 0 M 1.11 1.176 3.6532 7.0
41 1 High 1 M 1.15 1.342 3.5185 5.0
58 1 Medium 1 M 1.20 1.580 3.6990 12.1
11 1 Medium 1 M 1.11 1.279 3.8808 14.0
41 1 Medium 1 M 1.00 1.477 3.4771 10.2
19 1 High 0 M 1.26 1.929 3.7924 7.5
89 1 High 1 M 1.32 1.623 3.6532 14.0
4 0 Medium 1 F 1.95 0.778 4.0453 10.2
6 1 Critical 1 F 1.36 1.462 3.5441 9.0
57 0 Low 1 F 1.26 1.954 3.9685 12.5
5 1 High 1 M 2.24 1.663 4.9542 10.1
17 1 Medium 1 F 1.59 1.613 3.4314 11.2
77 0 Low 1 F 1.08 0.954 3.6812 14.0
66 1 High 1 M 1.45 1.820 3.7853 6.6
16 1 Medium 1 M 1.32 0.699 3.6990 8.8
8 0 Critical 1 M 1.08 1.653 3.8325 9.9
19 1 High 0 M 1.26 1.929 3.7924 7.5
37 1 High 1 F 1.60 1.204 3.9542 11.0
52 1 Medium 1 M 1.00 1.653 3.8573 10.1
13 0 High 0 F 1.66 1.792 3.6435 4.9
3 1 Medium 1 F 1.54 1.935 4.4757 6.7
51 1 Low 0 M 1.57 1.041 3.4150 7.7
2 1 High 0 M 1.30 2.000 3.7243 5.1
25 1 Medium 1 M 1.00 1.644 3.8195 12.4
11 1 Low 1 F 1.57 1.672 3.8865 7.5
19 1 Low 1 M 1.08 2.000 3.9191 14.4
9 1 Low 1 M 1.72 1.740 3.7993 8.2
6 1 Medium 1 M 1.11 1.398 3.5185 9.7
16 1 Medium 1 M 1.34 2.000 3.9345 9.0
12 0 High 1 M 1.40 1.362 3.8388 8.8
17 1 High 1 M 1.23 1.447 3.8808 10.0
17 1 High 1 M 1.23 1.447 3.8808 10.0
41 0 High 1 M 1.76 1.447 3.7243 12.8
88 1 High 1 F 1.18 1.756 3.5563 10.6
16 0 High 1 F 1.15 0.903 3.8573 13.0
4 0 Low 1 F 1.92 1.623 3.9590 10.0
7 1 Low 1 M 1.18 1.519 3.7243 11.4
19 0 Medium 1 M 1.32 1.519 3.8808 10.8
8 0 Critical 1 M 1.08 1.653 3.8325 9.9
57 0 Low 1 F 1.26 1.954 3.9685 12.5
7 1 Medium 1 M 1.98 1.568 3.3617 9.5
19 1 Low 1 M 1.08 2.000 3.9191 14.4
7 0 Low 1 F 1.53 1.881 3.5911 10.2
5 1 High 1 F 1.68 1.732 3.7324 6.5
2 1 Low 0 M 1.75 1.255 3.8062 11.3
1 1 Low 1 M 1.94 1.954 3.9868 12.0
15 1 Low 1 M 1.60 1.431 3.6902 10.6
26 1 Low 1 M 1.23 2.000 3.6021 11.2
92 1 Low 1 M 1.43 1.415 4.0755 11.0
11 1 Medium 1 M 1.30 1.820 3.7993 13.2
3 1 Medium 1 F 1.54 1.935 4.4757 6.7
66 1 High 1 M 1.45 1.820 3.7853 6.6
1 1 Medium 1 M 2.22 1.954 3.6628 9.4
11 1 Medium 1 M 1.30 1.820 3.7993 13.2
14 1 Medium 1 M 1.40 1.255 3.7243 14.6
32 1 High 1 M 1.32 1.634 3.6990 10.6
24 1 High 1 M 1.30 0.477 4.0899 14.6
18 1 Critical 1 F 1.45 0.903 3.5682 7.5
5 1 High 1 F 1.68 1.732 3.7324 6.5
2 1 Low 0 M 1.75 1.255 3.8062 11.3
26 1 Low 1 M 1.23 2.000 3.6021 11.2
11 1 High 1 M 1.23 1.176 3.7709 12.0
28 0 High 1 M 1.23 1.672 3.7482 7.3
19 0 Medium 1 M 1.32 2.000 3.7709 13.0
54 1 Medium 1 M 1.26 1.699 3.7243 9.0
2 1 Low 1 M 1.52 2.000 3.8751 9.8
7 0 Medium 1 M 1.11 1.857 3.7993 12.4
19 0 Medium 1 M 1.32 1.519 3.8808 10.8
6 1 Critical 1 M 1.42 1.690 3.9294 10.4
6 1 Medium 1 M 1.11 1.398 3.5185 9.7
11 1 Medium 1 M 1.11 1.279 3.8808 14.0
6 1 Critical 0 M 2.11 1.362 3.5441 10.2
13 1 Medium 0 M 0.78 1.398 3.5798 5.5
18 1 Critical 1 F 1.45 0.903 3.5682 7.5
7 0 Low 1 F 1.53 1.881 3.5911 10.2
53 0 Low 1 M 1.11 2.000 3.6128 12.0
11 1 High 1 M 1.08 1.903 3.5051 9.6
11 0 High 1 M 1.61 1.845 3.7324 14.0
89 1 High 1 M 1.32 1.623 3.6532 14.0
;
The following PROC CAS statements use the cox action in the phreg action set to fit a Cox regression model to these data. The table parameter names the input data table to be analyzed. The class parameter specifies that variables C1–C3 are classification variables; this parameter corresponds to the CLASS statement in the PHSELECT procedure. The model parameter specifies the model: the depVar subparameter specifies the variable Time as the failure time variable, the censor subparameter specifies the variable Status as the censoring variable, the censVals subparameter lists the value 0 as the value of Status that represents a censored observation, and the effects subparameter lists the classification variables C1–C3 and continuous variables X1–X4 as explanatory variables. The itHist subparameter in the optimization parameter list produces a table that summarizes the steps of the optimization. The outputTables parameter outputs the parameter estimates to the mycas.pe data table.
proc cas;
phreg.cox
table={name='getStarted'},
class={'C1', 'C2', 'C3'},
model={depVar='Time',
censor='Status',
censVals={0},
effects={'C1', 'C2', 'C3', 'X1', 'X2', 'X3', 'X4'}},
optimization={itHist='summary'},
outputTables={names={parameterestimates='pe'}};
run;
The output from this analysis is displayed by default, and is presented in Output 20.1.1 through Output 20.1.8.
Output 20.1.1 displays the "Model Information" table. The cox action uses a quasi-Newton algorithm to maximize the partial likelihood to estimate the regression parameters. The classification variable C1–C3 are parameterized using GLM parameterization, which is the default.
Output 20.1.1: Model Information
| Model Information | |
|---|---|
| Data Source | GETSTARTED |
| Response Variable | Time |
| Censoring Variable | Status |
| Censoring Values | 0 |
| Optimization technique | Dual Quasi-Newton |
The "Number of Observations" table, displayed in Output 20.1.2, shows the breakdown of the censored and uncensored observations. Uncensored observations are also known as event observations. All 100 observations in the data table are used in the analysis: 26 are censored observations, and 74 are uncensored.
Output 20.1.2: Number of Observations
| Number of Observations | |||
|---|---|---|---|
| Description | Total | Event | Censored |
| Number of Observations Read | 100 | 74 | 26 |
| Number of Observations Used | 100 | 74 | 26 |
The classification variable C1 has four unique formatted levels, and each of the classification variables C2 and C3 has two formatted levels. They are displayed in the "Class Level Information" table in Output 20.1.3.
Output 20.1.3: Class Level Information
| Class Level Information | ||
|---|---|---|
| Class | Levels | Values |
| C1 | 4 | Critical High Low Medium |
| C2 | 2 | 0 1 |
| C3 | 2 | F M |
The "Iteration History" table is shown in Output 20.1.4. The quasi-Raphson algorithm converges after 12 iterations.
Output 20.1.4: Iteration History
| Iteration History | ||||
|---|---|---|---|---|
| Iteration | Evaluations | Objective Function | Change | Max Gradient |
| 0 | 4 | 272.56284984 | . | 65.17039 |
| 1 | 3 | 267.70594206 | 4.85690778 | 7.86724 |
| 2 | 2 | 261.80868056 | 5.89726150 | 4.723085 |
| 3 | 2 | 256.62059571 | 5.18808485 | 4.650619 |
| 4 | 2 | 255.59346125 | 1.02713446 | 1.0462 |
| 5 | 2 | 255.44142594 | 0.15203531 | 1.018105 |
| 6 | 3 | 255.40692196 | 0.03450398 | 0.353611 |
| 7 | 3 | 255.39461736 | 0.01230460 | 0.415741 |
| 8 | 3 | 255.39362671 | 0.00099065 | 0.074411 |
| 9 | 3 | 255.39339211 | 0.00023460 | 0.062435 |
| 10 | 3 | 255.39336653 | 0.00002558 | 0.004922 |
| 11 | 3 | 255.39336262 | 0.00000391 | 0.002273 |
| 12 | 3 | 255.39336237 | 0.00000026 | 0.000452 |
Output 20.1.5 displays the final convergence status of the optimization. The GCONV relative convergence criterion is satisfied.
Output 20.1.5: Convergence Status
| Convergence criterion (GCONV=1E-8) satisfied. |
Output 20.1.6 displays the "Dimensions" table for this model. This table summarizes some important sizes of various model components. For example, it shows that the design matrix has 12 columns: four columns for the effects that are associated with the classification variable
C1, two columns for each of the classification variables C2 and C3, and one column for each of the continuous variables X1–X4. However, the rank of the crossproducts matrix is only 9. Because the classification variables C1– C3 use GLM parameterization, there is one singularity in the crossproducts matrix of the model for each classification variable. Consequently, only nine parameters enter the optimization.
Output 20.1.6: Dimensions in Cox Regression
| Dimensions | |
|---|---|
| Number of Effects | 7 |
| Max Effect Columns | 4 |
| Columns in Design | 12 |
| Rank of Design | 9 |
The "Fit Statistics" table is shown in Output 20.1.7. The –2 log likelihood at the converged estimates is 510.72307. You can use this value to compare the model to nested model alternatives by means of a likelihood ratio test. To compare models that are not nested, you can use information criteria such as AIC (Akaike’s information criterion), AICC (Akaike’s bias-corrected information criterion), and SBC (Schwarz Bayesian information criterion). These criteria penalize the –2 log likelihood for the number of parameters.
Output 20.1.7: Fit Statistics
| Fit Statistics | |
|---|---|
| -2 Log Likelihood | 510.78672 |
| AIC (smaller is better) | 528.78672 |
| AICC (smaller is better) | 531.59922 |
| SBC (smaller is better) | 549.52331 |
The "Parameter Estimates" table in Output 20.1.8 shows that a number of parameters have fairly large p-values, indicating that one or more of the model effects might not be necessary.
Output 20.1.8: Parameter Estimates
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | Chi-Square | Pr > ChiSq |
| C1 Critical | 1 | 0.400493 | 0.489562 | 0.6692 | 0.4133 |
| C1 High | 1 | -0.990602 | 0.325145 | 9.2821 | 0.0023 |
| C1 Low | 1 | -0.665495 | 0.339148 | 3.8504 | 0.0497 |
| C1 Medium | 0 | 0 | . | . | . |
| C2 0 | 1 | 0.410704 | 0.398833 | 1.0604 | 0.3031 |
| C2 1 | 0 | 0 | . | . | . |
| C3 F | 1 | -0.172550 | 0.337940 | 0.2607 | 0.6096 |
| C3 M | 0 | 0 | . | . | . |
| X1 | 1 | 1.970488 | 0.524142 | 14.1335 | 0.0002 |
| X2 | 1 | 0.726605 | 0.415141 | 3.0634 | 0.0801 |
| X3 | 1 | 0.725390 | 0.585658 | 1.5341 | 0.2155 |
| X4 | 1 | -0.131226 | 0.057103 | 5.2810 | 0.0216 |
Finally, the "Task Timing" table in Output 20.1.9 shows the amount of time (in seconds) that the cox action spent on different tasks in the analysis.
Output 20.1.9: Task Timing
| Task Timing | ||
|---|---|---|
| Task | Seconds | Percent |
| Setup and Parsing | 0.02 | 12.76% |
| Levelization | 0.01 | 4.54% |
| Model Initialization | 0.00 | 1.41% |
| SSCP Computation | 0.00 | 0.47% |
| Model Fitting | 0.13 | 71.93% |
| Cleanup | 0.00 | 2.53% |
| Total | 0.19 | 100.00% |
Output 20.1.8 shows that the full model has some nonsignificant effects. You can perform forward selection on these data by using the following statements. Effects that provide the best improvement for the default selection criterion, SBC, are added until no more effects can improve the selection criterion. The method subparameter in the selection parameter enables you to choose the selection method, and the details subparameter produces all tables that are related to model selection. The ODS TRACE command displays the full pathnames of the output tables in the SAS log.
ods trace on;
proc cas;
phreg.cox
table={name='getStarted'},
class={'C1', 'C2', 'C3'},
model={depVar='Time',
censor='Status',
censVals={0},
effects={'C1', 'C2', 'C3', 'X1', 'X2', 'X3', 'X4'}},
selection={method='forward', details='all'};
run;
The model selection tables are shown in Output 20.1.10 through Output 20.1.12. Results from the selected model are shown in Output 20.1.13 and Output 20.1.14.
The "Selection Information" table in Output 20.1.10 summarizes the settings for the model selection. At each step, an effect is added to the model only if it produces the most significant improvement in the SBC. The forward selection stops three steps after the smallest SBC is obtained, or when all effects have been added to the model.
Output 20.1.10: Selection Information
| Selection Information | |
|---|---|
| Description | Value |
| Selection Method | Forward |
| Select Criterion | SBC |
| Stop Criterion | SBC |
| Effect Hierarchy Enforced | None |
| Stop Horizon | 3 |
For each step of the selection process, the details=all subparameter displays the effects that are candidates for entering the model along with their selection criterion (SBC). Output 20.1.11 displays this table for the first step; the other steps are not shown here.
Output 20.1.11: Step1 Entry Candidates
| Entry Candidates | ||
|---|---|---|
| Rank | Effect | SBC |
| 1 | X1 | 536.7462 |
| 2 | X4 | 539.8497 |
| 3 | C2 | 544.9948 |
| 4 | X3 | 548.2815 |
| 5 | X2 | 548.9490 |
| 6 | C3 | 549.1132 |
| 7 | C1 | 551.8649 |
The details=all subparameter also displays the dimensions, global test, fit statistics, and parameter estimates at each step of the selection process; these details are not shown here.
When the selection procedure is complete, the "Selection Summary" table in Output 20.1.12 shows the effects that were added to the model and the value of their selection criterion (and the choose and stop criteria, if they are specified). In Step 1, effect X1 made the most significant contribution to the model among the candidate effects, according to the SBC statistic. In Step 2, X4 made the most significant contribution when an effect was added to a model that contains X1. In the three subsequent steps, no effect that would reduce the SBC could be added to the model, so variable selection stopped because the stop horizon indicates that at most three steps beyond the minimum SBC value are to be taken (see Output 20.1.10) .
In Output 20.1.12, the "Selection Summary" table is followed by three small tables that summarize why the process stopped and which model is selected.
Output 20.1.12: Selection Summary Information
| Selection Summary | |||
|---|---|---|---|
| Step | Effect Entered | Number Effects In | SBC |
| 1 | X1 | 1 | 536.7462 |
| 2 | X4 | 2 | 535.1652* |
| 3 | C1 | 3 | 538.2917 |
| 4 | X2 | 4 | 539.2661 |
| 5 | X3 | 5 | 542.4842 |
| * Optimal Value Of Criterion | |||
| Selection stopped at a local minimum of the STOP criterion. |
| The model at step 2 is selected. |
| Selected Effects: | X1 X4 |
|---|
Output 20.1.13 displays information about the selected model. Notice that the –2 log-likelihood value in the "Fit Statistics" table is larger than the value for the full model in Output 20.1.7. This result is expected because the selected model contains only a subset of the parameters. Because the selected model is more parsimonious than the full model, the discrepancy between the –2 log likelihood and the information criteria is less severe than previously noted.
Output 20.1.13: Fit Statistics
| Dimensions | |
|---|---|
| Number of Effects | 2 |
| Max Effect Columns | 1 |
| Columns in Design | 2 |
| Rank of Design | 2 |
| Fit Statistics | |
|---|---|
| -2 Log Likelihood | 526.74445 |
| AIC (smaller is better) | 530.74445 |
| AICC (smaller is better) | 530.91346 |
| SBC (smaller is better) | 535.35258 |
The parameter estimates of the selected model are shown in Output 20.1.14. Notice that the effects are listed in the "Parameter Estimates" table in the order in which they were specified in the model parameter and not in the order in which they were added to the model.
Output 20.1.14: Parameter Estimates
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | Chi-Square | Pr > ChiSq |
| X1 | 1 | 1.605306 | 0.513811 | 9.7613 | 0.0018 |
| X4 | 1 | -0.123304 | 0.046697 | 6.9723 | 0.0083 |
Cox Regression
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 getStarted data to the comma-separated-value (CSV) file getStarted.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="getStarted.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 phreg action set, and then uses the cox action to fit a Cox regression model to the getStarted data table. The table parameter names the input data table to be analyzed. The class parameter specifies that the variables C1–C3 are classification variables; this parameter corresponds to the CLASS statement in the PHSELECT procedure. The model parameter specifies the model: the depVar subparameter specifies the variable Time as the response variable, the censor subparameter specifies the variable Status as the censoring variable, the censVals subparameter lists the value 0 as the value of Status that represents a censored observation, and the effects subparameter lists the three classification variables C1–C3 and the four continuous explanatory variables X1–X4. The itHist subparameter in the optimization parameter list produces a table that summarizes the steps of the optimization. The outputTables parameter outputs the fitted parameter estimates to the mycas.pe data table.
s:loadactionset{actionset="phreg"}
m=s:cox{
table='getStarted',
class={'C1', 'C2','C3'},
model={depVar='Time',
censor='Status',
censVals={0},
effects={'C1', 'C2', 'C3', 'X1', 'X2', 'X3', 'X4'}},
optimization={itHist='summary'},
outputTables={names={parameterestimates='pe'}} }
The following commands display the tables that are produced by this action call:
print(m.ModelInfo)
print(m.NObs)
print(m.ClassInfo)
print(m.IterHistory)
print(m.ConvergenceStatus)
print(m.Dimensions)
print(m.FitStatistics)
print(m.ParameterEstimates)
print(m.Timing)
The full model has a number of nonsignificant effects; see the CASL version of this example for details about the results of this analysis. You can perform forward selection on these data by using the following program. Effects that provide the best improvement for the default selection criterion, SBC, are added until no more effects can improve the selection criterion. The method subparameter in the selection parameter enables you to choose the selection method, and the details subparameter produces all tables that are related to model selection.
m=s:cox{
table='getStarted',
class={'C1','C2','C3'},
model={depVar='Time',
censor='Status',
censVals={0},
effects={'C1', 'C2','C3','X1', 'X2', 'X3', 'X4'}},
selection={method='forward', details='all'} }
The following commands display some of the tables that are produced by this action call:
print(m.SelectionInfo)
print(m["StepDetails.Step1.EntryCandidates"])
print(m["Summary.SelectionSummary"])
print(m["Summary.StopReason"])
print(m["Summary.SelectionReason"])
print(m["Summary.SelectedEffects"])
print(m["SelectedModel.Dimensions"])
print(m["SelectedModel.FitStatistics"])
print(m["SelectedModel.ParameterEstimates"])
The following command displays all the tables that are produced by this action call along with their full pathnames:
m
For details about the results of this analysis, see the CASL version of this example.
Cox Regression
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 getStarted data to the comma-separated-value (CSV) file getStarted.csv and then use the following code to load the CSV file into CAS:
s.upload_file('getStarted.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 phreg action set, and then uses the cox action to fit a Cox regression model to the getStarted data table. The table parameter names the input data table to be analyzed. The classvars parameter specifies that variables C1–C3 are classification variables; this parameter corresponds to the CLASS statement in the PHSELECT procedure. The model parameter specifies the model: the depVar subparameter specifies the variable Time as the response variable, the censor subparameter specifies the variable Status as the censoring variable, the censVals subparameter lists the value 0 as the value of Status that represents a censored observation, and the effects subparameter lists the three classification variables C1–C4 and four continuous explanatory variables X1–X4. The itHist subparameter in the optimization parameter list produces a table that summarizes the steps of the optimization. The outputTables parameter outputs the fitted parameter estimates to the mycas.pe data table.
s.loadactionset(actionset='phreg')
m=s.cox(
table='getStarted',
classVars={'C1', 'C2', 'C3'},
model={'depVar':'Time',
'censor':'Status',
'censVals':{0},
'effects':['C1', 'C2', 'C3', 'X1', 'X2', 'X3', 'X4']},
optimization={'itHist':'summary'},
outputTables={'names':{'parameterestimates':'pe'}} )
The following commands display the tables that are produced by this action call:
print(m.ModelInfo)
print(m.NObs)
print(m.ClassInfo)
print(m.IterHistory)
print(m.ConvergenceStatus)
print(m.Dimensions)
print(m.FitStatistics)
print(m.ParameterEstimates)
print(m.Timing)
The full model has many nonsignificant effects; see the CASL version of this example for details about the results of this analysis. You can perform forward selection on these data by using the following program. Effects that provide the best improvement for the default selection criterion, SBC, are added until no more effects can improve the selection criterion. The method subparameter in the selection parameter enables you to choose the selection method, and the details subparameter produces all tables that are related to model selection.
m=s.cox(
table='getStarted',
classVars={'C1','C2','C3'},
model={'depVar':'Time',
'censor':'Status',
'censVals':{0},
'effects':['C1', 'C2', 'C3', 'X1', 'X2', 'X3', 'X4']},
selection={'method':'forward','details':'all'})
The following commands display some of the tables that are produced by this action call:
print(m.SelectionInfo)
print(m["StepDetails.Step1.EntryCandidates"])
print(m["Summary.SelectionSummary"])
print(m["Summary.StopReason"])
print(m["Summary.SelectionReason"])
print(m["Summary.SelectedEffects"])
print(m["SelectedModel.Dimensions"])
print(m["SelectedModel.FitStatistics"])
print(m["SelectedModel.ParameterEstimates"])
The following command displays all the tables that are produced by this action call along with their full pathnames:
print(m)
For details about the results of this analysis, see the CASL version of this example.
Cox Regression
This section contains R 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 getStarted data to the comma-separated-value (CSV) file getStarted.csv and then use the following code to load the CSV file into CAS:
m <- cas.read.csv(s, "getStarted.csv", casOut=list(name="getStarted"))
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
The following code loads the phreg action set and then uses the lcox action to fit a cox regression model to the getStarted data table. The table parameter names the input data table to be analyzed. The class parameter specifies that the variables C1–C3 are classification variables; this parameter corresponds to the CLASS statement in the PHSELECT procedure. The model parameter specifies the model:the depVar subparameter specifies the variable Time as the response variable, the censor subparameter specifies the variable Status as the censoring variable, the cenVals subparameter list the values 0 as the value of Status that represents a censored observation, and the effects subparameter lists the three classification variables C1–C4 and four continuous explanatory variables, X1–X4. The itHist subparameter in the optimization parameter list produces a table that summarizes the steps of the optimization. The outputTables parameter outputs the fitted parameter estimates to the mycas.pe data table.
m <- cas.builtins.loadActionSet(s, actionset='phreg')
m <- cas.phreg.cox(s,
table='getStarted',
class=list('C1','C2','C3'),
model=list(depVar='Time',
censor='Status',
censVals=(0),
effects=list('C1', 'C2','C3','X1', 'X2', 'X3', 'X4')),
optimization=list(itHist='summary'),
outputTables=list(names=list(parameterestimates='pe'))
)
The following commands display the tables that are produced by this action call:
print(m$ModelInfo)
print(m$NObs)
print(m$ClassInfo)
print(m$IterHistory)
print(m$ConvergenceStatus)
print(m$Dimensions)
print(m$FitStatistics)
print(m$ParameterEstimates)
print(m$Timing)
The full model has many nonsignificant effects; see the CASL version of this example for details about the results of this analysis. You can perform forward selection on these data by using the following program. Effects that provide the best improvement for the default selection criterion, the Schwarz Bayesian information criterion, SBC, are added until no more effects can improve the selection criterion. The method subparameter in the selection parameter enables you to choose the selection method, and the details subparameter produces all tables that are related to model selection.
m <- cas.phreg.cox(s,
table='getStarted',
class=list('C1', 'C2','C3'),
model=list(depVar='Time',
censor='Status',
censVals=(0),
effects=list('C1', 'C2','C3','X1', 'X2', 'X3', 'X4')),
selection=list(method='forward',details='all')
)
The following commands display some of the tables that are produced by this action call:
print(m$SelectionInfo)
print(m$StepDetails.Step1.EntryCandidates)
print(m$Summary.SelectionSummary)
print(m$Summary.StopReason)
print(m$Summary.SelectionReason)
print(m$Summary.SelectedEffects)
print(m$SelectedModel.Dimensions)
print(m$SelectedModel.FitStatistics)
print(m$SelectedModel.ParameterEstimates)
The following command displays all the tables that are produced by this action call along with their full pathnames:
print(m)
For details about the results of this analysis, see the CASL version of this example.