Regression Action Set
Modeling Binomial Response Data
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.Ingots—which consists of the number, r, of ingots not ready for rolling, out of n tested, for a number of combinations of heating time (Heat) and soaking time (Soak)—in your CAS session. This DATA step assumes that your CAS engine libref is named mycas, but you can substitute any appropriately defined CAS engine libref.
data mycas.Ingots;
input Heat Soak r n @@;
Obsnum= _n_;
datalines;
7 1.0 0 10 14 1.0 0 31 27 1.0 1 56 51 1.0 3 13
7 1.7 0 17 14 1.7 0 43 27 1.7 4 44 51 1.7 0 1
7 2.2 0 7 14 2.2 2 33 27 2.2 0 21 51 2.2 0 1
7 2.8 0 12 14 2.8 0 31 27 2.8 1 22 51 4.0 0 1
7 4.0 0 9 14 4.0 0 19 27 4.0 1 16
;
The following statements use events/trials syntax to model the binomial response. The events variable in this situation is r, and the trials variable is n. The dependency of the probability of not being ready for rolling is modeled as a function of heating time (Heat), soaking time (Soak), and their interaction. The association parameter displays ordinal measures of association between the observed responses and the predicted probabilities. The ctable parameter saves statistics to the mycas.Roc data table that are used to evaluate the predictive power of the model. The output parameter stores the linear predictors and the predicted probabilities in the mycas.Out data table along with the other variables from the input data table.
proc cas;
regression.logistic /
association="true",
ctable={casOut={name="Roc", replace="true"},
fpf="FPF", nocounts="true", tpf="TPF"},
model={depVars={{name="r"}},
effects={{vars={"Heat", "Soak"}},
{interaction="CROSS", vars={"Heat", "Soak"}}},
trial="n"},
output={casOut={name="Out", replace="true"},
copyVars={"Heat", "Soak"},
pred="Pred", xBeta="_XBETA_"},
table="Ingots";
run;
The "Model Information" table shows that the data are modeled as binomially distributed with a logit link function (Output 19.6.1). This is the default link function in the logistic action for binary and binomial data. The action estimates the parameters of the model by a Newton-Raphson algorithm.
Output 19.6.1: Model Information and Number of Observations
| Model Information | |
|---|---|
| Data Source | INGOTS |
| Response Variable (Events) | r |
| Response Variable (Trials) | n |
| Distribution | Binomial |
| Link Function | Logit |
| Optimization Technique | Newton-Raphson with Ridging |
The second table in Output 19.6.1 shows that all 19 observations in the input data table were used in the analysis and the "Response Profile" table shows that the total number of events and nonevents equals 12 and 375, respectively.
Output 19.6.2 displays the convergence status table for this run. The logistic action satisfies the gconv convergence criterion.
Output 19.6.2: Convergence Status
| Convergence criterion (GCONV=1E-8) satisfied. |
Output 19.6.3 displays the "Dimensions" table for the model. The design matrix of the model (the matrix) has four columns, which correspond to the intercept, the Heat effect, the Soak effect, and the interaction of the Heat and Soak effects. The model is nonsingular because the rank of the crossproducts matrix equals the number of columns in . All parameters are estimable, and all participate in the optimization.
Output 19.6.3: Dimensions in Binomial Logistic Regression
| Dimensions | |
|---|---|
| Columns in Design | 4 |
| Number of Effects | 4 |
| Max Effect Columns | 1 |
| Rank of Design | 4 |
| Parameters in Optimization | 4 |
Output 19.6.4 displays the "Fit Statistics" table for this run. Evaluated at the converged estimates, –2 times the value of the log-likelihood function equals 27.95689. Further fit statistics are also displayed, all of them in "smaller is better" form. The AIC, AICC, and SBC criteria are used to compare non-nested models and to penalize the model fit for the number of observations and parameters. You can use the –2 log-likelihood value to compare nested models by way of a likelihood ratio test.
Output 19.6.4: Fit Statistics
| Fit Statistics | |
|---|---|
| -2 Log Likelihood | 27.95689 |
| AIC (smaller is better) | 35.95689 |
| AICC (smaller is better) | 38.81403 |
| SBC (smaller is better) | 39.73464 |
Output 19.6.5 shows the test of the global hypothesis that the effects jointly do not affect the probability of ingot readiness. You can obtain the chi-square test statistic by comparing the –2 log-likelihood value of the model with covariates to the value in the intercept-only model. The test is significant, with a p-value of 0.0082. One or more of the effects in the model have a significant impact on the probability of ingot readiness.
Output 19.6.5: Null Test
| Testing Global Null Hypothesis: BETA=0 | |||
|---|---|---|---|
| Test | DF | Chi-Square | Pr > ChiSq |
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
The "Parameter Estimates" table in Output 19.6.6 displays the estimates and standard errors of the model effects.
Output 19.6.6: Parameter Estimates
| Parameter Estimates | |||||
|---|---|---|---|---|---|
| Parameter | DF | Estimate | Standard Error | Chi-Square | Pr > ChiSq |
| Intercept | 1 | -5.990191 | 1.666622 | 12.9183 | 0.0003 |
| Heat | 1 | 0.096339 | 0.047067 | 4.1896 | 0.0407 |
| Soak | 1 | 0.299574 | 0.755068 | 0.1574 | 0.6916 |
| Heat * Soak | 1 | -0.008840 | 0.025319 | 0.1219 | 0.7270 |
Output 19.6.7 displays the "Association Statistics" table, which is produced when you specify the association parameter. The table contains four measures of association for assessing the predictive ability of a model. For more information, see the section Association Statistics.
Output 19.6.7: Association of Observed Responses and Predicted Probabilities
| Association of Predicted Probabilities and Observed Responses | |
|---|---|
| Concordance Index (AUC) | 0.7706 |
| Somers' D | 0.5411 |
| Gamma | 0.5858 |
| Tau-a | 0.0326 |
| Pairs | 4500 |
| Percent Concordant | 73.2444 |
| Percent Discordant | 19.1333 |
| Percent Tied | 7.6222 |
You can construct the prediction equation of the model from the "Parameter Estimates" table. For example, an observation with Heat equal to 14 and Soak equal to 1.7 has the linear predictor
The probability that an ingot with these characteristics is not ready for rolling is
The logistic action computes these linear predictors and probabilities and stores them in the mycas.Out data table.
The following fetch action from the tables action set enables you to display Output 19.6.8, which shows the probability that an ingot with Heat equal to 14 and Soak equal to 1.7 is not ready for rolling:
proc cas;
table.fetch /
format="true",
index="false",
table={name="Out", where="14 = Heat and 1.7 = Soak"};
run;
Output 19.6.8: Predicted Probability for Heat=14 and Soak=1.7
| Selected Rows from Table OUT | |||
|---|---|---|---|
| Predicted Value | Linear Predictor | Heat | Soak |
| 0.0128363197 | -4.34255723 | 14 | 1.7 |
The ctable parameter computes statistics for binary response models (on the basis of classifying observations according to whether their predicted probabilities exceed certain values) and stores the results in the mycas.Roc data table. For more information, see the section Classification Table and ROC Curves.
You can use the mycas.Roc data table to display the ROC curve by using the SGPLOT procedure as follows:
ods graphics on;
proc sgplot data=mycas.Roc aspect=1 noautolegend;
title 'ROC Curve';
xaxis values=(0 to 1 by 0.25) grid offsetmin=.05 offsetmax=.05;
yaxis values=(0 to 1 by 0.25) grid offsetmin=.05 offsetmax=.05;
lineparm x=0 y=0 slope=1 / lineattrs=(color=ligr);
series x=FPF y=TPF;
inset 'Area under the curve=0.7706' / position=bottomright;
run;
Output 19.6.9: Receiver Operating Characteristics Curve

Binomial data are a form of grouped binary data in which "successes" in the underlying Bernoulli trials are totaled. You can thus unwind data for which you use the events/trials syntax and fit these data by using techniques for binary data.
The following DATA step expands the mycas.Ingots data table, which contains 12 events in 387 trials, into a data table that has 387 observations:
proc cas;
dataStep.runCode /
code="
data Ingots_binary;
set Ingots;
do i=1 to n;
if i <= r then y=1; else y = 0;
output;
end;
run;
",
single="no";
run;
The following statements fit the model that contains the Heat effect, the Soak effect, and their interaction to the data table. The event=’1’ response-variable subparameter in the model parameter ensures that the logistic action models the probability that the variable y takes the value 1.
proc cas;
regression.logistic /
model={depVars={{name="y", options={event="1"}}},
effects={{vars={"Heat", "Soak"}},
{interaction="CROSS", vars={"Heat", "Soak"}}}},
table={name="Ingots_binary"};
run;
Output 19.6.10 displays the "Model Information," "Number of Observations," and "Response Profile" tables. The data are now modeled as binary (Bernoulli distributed) with a logit link function. The "Response Profile" table shows that the binary response breaks down into 375 observations where y=0 and 12 observations where y=1.
Output 19.6.10: Model Information in Binary Model
| Model Information | |
|---|---|
| Data Source | INGOTS_BINARY |
| Response Variable | y |
| Distribution | Binary |
| Link Function | Logit |
| Optimization Technique | Newton-Raphson with Ridging |
Output 19.6.11 displays the result of the test of the global null hypothesis and the parameter estimates. These results match those in Output 19.6.5 and Output 19.6.6.
Output 19.6.11: Null Test and Parameter Estimates
| Testing Global Null Hypothesis: BETA=0 | |||
|---|---|---|---|
| Test | DF | Chi-Square | Pr > ChiSq |
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
Modeling Binomial Response Data
This section contains Lua code that performs the same analysis as shown in the CASL version of this example.
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 Ingots data to the comma-separated-value (CSV) file Ingots.csv and then use the following code to load the CSV file into CAS:
s:loadtable{casLib="casuser", path="Ingots.csv"}
For more information about coding in Lua, see Getting Started with SAS Viya for Lua and SAS Viya: System Programming Guide.
The following statements use events/trials syntax to model the binomial response. The events variable in this situation is r, and the trials variable is n. The dependency of the probability of not being ready for rolling is modeled as a function of heating time (Heat), soaking time (Soak), and their interaction. The association parameter displays ordinal measures of association between the observed responses and the predicted probabilities. The ctable parameter saves statistics to the Roc data table that are used to evaluate the predictive power of the model. The output parameter stores the linear predictors and the predicted probabilities in the Out data table along with the other variables from the input data table.
s:loadactionset{actionset="regression"}
s:regression.logistic {
table='Ingots',
model={depVars={{name='r'}},
effects={{vars={'Heat', 'Soak'}},
{vars={'Heat', 'Soak'}, interaction='CROSS'}},
trial='n'},
output={casOut={name='Out', replace=true},
copyVars={'Heat', 'Soak'},
pred='Pred', xBeta='_XBETA_'},
association=true,
ctable={casOut={name='Roc', replace=true},
nocounts=true, tpf='TPF', fpf='FPF'} }
The "Model Information" table shows that the data are modeled as binomially distributed with a logit link function (Output 19.6.12). This is the default link function in the logistic action for binary and binomial data. The action estimates the parameters of the model by a Newton-Raphson algorithm.
Output 19.6.12: Model Information and Number of Observations
| RowId | Description | Value |
|---|---|---|
| DATA | Data Source | INGOTS |
| EVENTVAR | Response Variable (Events) | r |
| TRIALVAR | Response Variable (Trials) | n |
| DIST | Distribution | Binomial |
| LINK | Link Function | Logit |
| TECH | Optimization Technique | Newton-Raphson with Ridging |
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 19 |
| NUSED | Number of Observations Used | 19 |
| OrderedValue | Outcome | Freq | Modeled |
|---|---|---|---|
| 1 | Event | 12 | * |
| 2 | Nonevent | 375 |
The second table in Output 19.6.12 shows that all 19 observations in the input data table were used in the analysis and the "Response Profile" table shows that the total number of events and nonevents equals 12 and 375, respectively.
Output 19.6.13 displays the convergence status table for this run. The logistic action satisfies the gconv convergence criterion.
Output 19.6.13: Convergence Status
| Reason | Status | MaxGradient | Separation |
|---|---|---|---|
| Convergence criterion (GCONV=1E-8) satisfied. | 0 | 5.42E-11 | 0 |
Output 19.6.14 displays the "Dimensions" table for the model. The design matrix of the model (the matrix) has four columns, which correspond to the intercept, the Heat effect, the Soak effect, and the interaction of the Heat and Soak effects. The model is nonsingular because the rank of the crossproducts matrix equals the number of columns in . All parameters are estimable, and all participate in the optimization.
Output 19.6.14: Dimensions in Binomial Logistic Regression
| RowId | Description | Value |
|---|---|---|
| NDESIGNCOLS | Columns in Design | 4 |
| NEFFECTS | Number of Effects | 4 |
| MAXEFCOLS | Max Effect Columns | 1 |
| DESIGNRANK | Rank of Design | 4 |
| OPTPARM | Parameters in Optimization | 4 |
Output 19.6.15 displays the "Fit Statistics" table for this run. Evaluated at the converged estimates, –2 times the value of the log-likelihood function equals 27.95689. Further fit statistics are also displayed, all of them in "smaller is better" form. The AIC, AICC, and SBC criteria are used to compare non-nested models and to penalize the model fit for the number of observations and parameters. You can use the –2 log-likelihood value to compare nested models by way of a likelihood ratio test.
Output 19.6.15: Fit Statistics
| RowId | Description | Value |
|---|---|---|
| M2LL | -2 Log Likelihood | 27.95689 |
| AIC | AIC (smaller is better) | 35.95689 |
| AICC | AICC (smaller is better) | 38.81403 |
| SBC | SBC (smaller is better) | 39.73464 |
Output 19.6.16 shows the test of the global hypothesis that the effects jointly do not affect the probability of ingot readiness. You can obtain the chi-square test statistic by comparing the –2 log-likelihood value of the model with covariates to the value in the intercept-only model. The test is significant, with a p-value of 0.0082. One or more of the effects in the model have a significant impact on the probability of ingot readiness.
Output 19.6.16: Null Test
| Test | DF | ChiSq | ProbChiSq |
|---|---|---|---|
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
The "Parameter Estimates" table in Output 19.6.17 displays the estimates and standard errors of the model effects.
Output 19.6.17: Parameter Estimates
| Effect | Parameter | ParmName | DF | Estimate | StdErr | ChiSq | ProbChiSq |
|---|---|---|---|---|---|---|---|
| Intercept | Intercept | Intercept | 1 | -5.990191 | 1.666622 | 12.9183 | 0.0003 |
| Heat | Heat | Heat | 1 | 0.096339 | 0.047067 | 4.1896 | 0.0407 |
| Soak | Soak | Soak | 1 | 0.299574 | 0.755068 | 0.1574 | 0.6916 |
| Heat*Soak | Heat * Soak | Heat___Soak | 1 | -0.008840 | 0.025319 | 0.1219 | 0.7270 |
Output 19.6.18 displays the "Association Statistics" table, which is produced when you specify the association parameter. The table contains four measures of association for assessing the predictive ability of a model. For more information, see the section Association Statistics.
Output 19.6.18: Association of Observed Responses and Predicted Probabilities
| RowId | Description | Value |
|---|---|---|
| C | Concordance Index (AUC) | 0.7706 |
| SOMERSD | Somers' D | 0.5411 |
| GAMMA | Gamma | 0.5858 |
| TAUA | Tau-a | 0.0326 |
| PAIRS | Pairs | 4500 |
| CONCORD | Percent Concordant | 73.2444 |
| DISCORD | Percent Discordant | 19.1333 |
| TIED | Percent Tied | 7.6222 |
You can construct the prediction equation of the model from the "Parameter Estimates" table. For example, an observation with Heat equal to 14 and Soak equal to 1.7 has the linear predictor
The probability that an ingot with these characteristics is not ready for rolling is
The logistic action computes these linear predictors and probabilities and stores them in the Out data table.
The following fetch action from the tables action set enables you to display Output 19.6.19, which shows the probability that an ingot with Heat equal to 14 and Soak equal to 1.7 is not ready for rolling:
s:table_fetch{table={name='Out', where='14 = Heat and 1.7 = Soak'}, index=false, format=true}
Output 19.6.19: Predicted Probability for Heat=14 and Soak=1.7
| Pred | _XBETA_ | Heat | Soak |
|---|---|---|---|
| 0.0128363197 | -4.34255723 | 14 | 1.7 |
The ctable parameter computes statistics for binary response models (on the basis of classifying observations according to whether their predicted probabilities exceed certain values) and stores the results in the Roc data table. For more information, see the section Classification Table and ROC Curves.
The Roc data table contains information you can use to produce an ROC curve like the following:
Output 19.6.20: Receiver Operating Characteristics Curve

Binomial data are a form of grouped binary data in which "successes" in the underlying Bernoulli trials are totaled. You can thus unwind data for which you use the events/trials syntax and fit these data by using techniques for binary data.
The following DATA step expands the Ingots data table, which contains 12 events in 387 trials, into a data table that has 387 observations:
s:dataStep_runCode{single='no', code=[[
data Ingots_binary;
set Ingots;
do i=1 to n;
if i <= r then y=1; else y = 0;
output;
end;
run;
]] }
The following statements fit the model that contains the Heat effect, the Soak effect, and their interaction to the data table. The event=’1’ response-variable subparameter in the model parameter ensures that the logistic action models the probability that the variable y takes the value 1.
s:regression_logistic {
table={name='Ingots_binary'},
model={depVars={{name='y', options={event='1'}}},
effects={{vars={'Heat', 'Soak'}},
{vars={'Heat', 'Soak'}, interaction='CROSS'}}}}
Output 19.6.21 displays the "Model Information," "Number of Observations," and "Response Profile" tables. The data are now modeled as binary (Bernoulli distributed) with a logit link function. The "Response Profile" table shows that the binary response breaks down into 375 observations where y=0 and 12 observations where y=1.
Output 19.6.21: Model Information in Binary Model
| RowId | Description | Value |
|---|---|---|
| DATA | Data Source | INGOTS_BINARY |
| RESPONSEVAR | Response Variable | y |
| DIST | Distribution | Binary |
| LINK | Link Function | Logit |
| TECH | Optimization Technique | Newton-Raphson with Ridging |
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 387 |
| NUSED | Number of Observations Used | 387 |
| OrderedValue | Outcome | y | Freq | Modeled |
|---|---|---|---|---|
| 1 | 0 | 0 | 375 | |
| 2 | 1 | 1 | 12 | * |
Output 19.6.22 displays the result of the test of the global null hypothesis and the parameter estimates. These results match those in Output 19.6.16 and Output 19.6.17.
Output 19.6.22: Null Test and Parameter Estimates
| Test | DF | ChiSq | ProbChiSq |
|---|---|---|---|
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
| Effect | Parameter | ParmName | DF | Estimate | StdErr | ChiSq | ProbChiSq |
|---|---|---|---|---|---|---|---|
| Intercept | Intercept | Intercept | 1 | -5.990191 | 1.666622 | 12.9183 | 0.0003 |
| Heat | Heat | Heat | 1 | 0.096339 | 0.047067 | 4.1896 | 0.0407 |
| Soak | Soak | Soak | 1 | 0.299574 | 0.755068 | 0.1574 | 0.6916 |
| Heat*Soak | Heat * Soak | Heat___Soak | 1 | -0.008840 | 0.025319 | 0.1219 | 0.7270 |
Modeling Binomial Response Data
This section contains Python code that performs the same analysis as shown in the CASL version of this example.
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 Ingots data to the comma-separated-value (CSV) file Ingots.csv and then use the following code to load the CSV file into CAS:
s.upload_file('Ingots.csv')
For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following statements use events/trials syntax to model the binomial response. The events variable in this situation is r, and the trials variable is n. The dependency of the probability of not being ready for rolling is modeled as a function of heating time (Heat), soaking time (Soak), and their interaction. The association parameter displays ordinal measures of association between the observed responses and the predicted probabilities. The ctable parameter saves statistics to the Roc data table that are used to evaluate the predictive power of the model. The output parameter stores the linear predictors and the predicted probabilities in the Out data table along with the other variables from the input data table.
s.loadactionset(actionset='regression')
s.regression.logistic(
association='true',
ctable=dict(casOut=dict(name='Roc', replace='true'),
fpf='FPF', nocounts='true', tpf='TPF'),
model=dict(depVars=[dict(name='r')],
effects=[dict(vars=['Heat', 'Soak']),
dict(interaction='CROSS', vars=['Heat', 'Soak'])],
trial='n'),
output=dict(casOut=dict(name='Out', replace='true'),
copyVars=['Heat', 'Soak'],
pred='Pred', xBeta='_XBETA_'),
table='Ingots')
The "Model Information" table shows that the data are modeled as binomially distributed with a logit link function (Output 19.6.23). This is the default link function in the logistic action for binary and binomial data. The action estimates the parameters of the model by a Newton-Raphson algorithm.
Output 19.6.23: Model Information and Number of Observations
| RowId | Description | Value |
|---|---|---|
| DATA | Data Source | INGOTS |
| EVENTVAR | Response Variable (Events) | r |
| TRIALVAR | Response Variable (Trials) | n |
| DIST | Distribution | Binomial |
| LINK | Link Function | Logit |
| TECH | Optimization Technique | Newton-Raphson with Ridging |
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 19 |
| NUSED | Number of Observations Used | 19 |
| OrderedValue | Outcome | Freq | Modeled |
|---|---|---|---|
| 1 | Event | 12 | * |
| 2 | Nonevent | 375 |
The second table in Output 19.6.23 shows that all 19 observations in the input data table were used in the analysis and the "Response Profile" table shows that the total number of events and nonevents equals 12 and 375, respectively.
Output 19.6.24 displays the convergence status table for this run. The logistic action satisfies the gconv convergence criterion.
Output 19.6.24: Convergence Status
| Reason | Status | MaxGradient | Separation |
|---|---|---|---|
| Convergence criterion (GCONV=1E-8) satisfied. | 0 | 5.42E-11 | 0 |
Output 19.6.25 displays the "Dimensions" table for the model. The design matrix of the model (the matrix) has four columns, which correspond to the intercept, the Heat effect, the Soak effect, and the interaction of the Heat and Soak effects. The model is nonsingular because the rank of the crossproducts matrix equals the number of columns in . All parameters are estimable, and all participate in the optimization.
Output 19.6.25: Dimensions in Binomial Logistic Regression
| RowId | Description | Value |
|---|---|---|
| NDESIGNCOLS | Columns in Design | 4 |
| NEFFECTS | Number of Effects | 4 |
| MAXEFCOLS | Max Effect Columns | 1 |
| DESIGNRANK | Rank of Design | 4 |
| OPTPARM | Parameters in Optimization | 4 |
Output 19.6.26 displays the "Fit Statistics" table for this run. Evaluated at the converged estimates, –2 times the value of the log-likelihood function equals 27.95689. Further fit statistics are also displayed, all of them in "smaller is better" form. The AIC, AICC, and SBC criteria are used to compare non-nested models and to penalize the model fit for the number of observations and parameters. You can use the –2 log-likelihood value to compare nested models by way of a likelihood ratio test.
Output 19.6.26: Fit Statistics
| RowId | Description | Value |
|---|---|---|
| M2LL | -2 Log Likelihood | 27.95689 |
| AIC | AIC (smaller is better) | 35.95689 |
| AICC | AICC (smaller is better) | 38.81403 |
| SBC | SBC (smaller is better) | 39.73464 |
Output 19.6.27 shows the test of the global hypothesis that the effects jointly do not affect the probability of ingot readiness. You can obtain the chi-square test statistic by comparing the –2 log-likelihood value of the model with covariates to the value in the intercept-only model. The test is significant, with a p-value of 0.0082. One or more of the effects in the model have a significant impact on the probability of ingot readiness.
Output 19.6.27: Null Test
| Test | DF | ChiSq | ProbChiSq |
|---|---|---|---|
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
The "Parameter Estimates" table in Output 19.6.28 displays the estimates and standard errors of the model effects.
Output 19.6.28: Parameter Estimates
| Effect | Parameter | ParmName | DF | Estimate | StdErr | ChiSq | ProbChiSq |
|---|---|---|---|---|---|---|---|
| Intercept | Intercept | Intercept | 1 | -5.990191 | 1.666622 | 12.9183 | 0.0003 |
| Heat | Heat | Heat | 1 | 0.096339 | 0.047067 | 4.1896 | 0.0407 |
| Soak | Soak | Soak | 1 | 0.299574 | 0.755068 | 0.1574 | 0.6916 |
| Heat*Soak | Heat * Soak | Heat___Soak | 1 | -0.008840 | 0.025319 | 0.1219 | 0.7270 |
Output 19.6.29 displays the "Association Statistics" table, which is produced when you specify the association parameter. The table contains four measures of association for assessing the predictive ability of a model. For more information, see the section Association Statistics.
Output 19.6.29: Association of Observed Responses and Predicted Probabilities
| RowId | Description | Value |
|---|---|---|
| C | Concordance Index (AUC) | 0.7706 |
| SOMERSD | Somers' D | 0.5411 |
| GAMMA | Gamma | 0.5858 |
| TAUA | Tau-a | 0.0326 |
| PAIRS | Pairs | 4500 |
| CONCORD | Percent Concordant | 73.2444 |
| DISCORD | Percent Discordant | 19.1333 |
| TIED | Percent Tied | 7.6222 |
You can construct the prediction equation of the model from the "Parameter Estimates" table. For example, an observation with Heat equal to 14 and Soak equal to 1.7 has the linear predictor
The probability that an ingot with these characteristics is not ready for rolling is
The logistic action computes these linear predictors and probabilities and stores them in the Out data table.
The following fetch action from the tables action set enables you to display Output 19.6.30, which shows the probability that an ingot with Heat equal to 14 and Soak equal to 1.7 is not ready for rolling:
s.table.fetch(
format='true',
index='false',
table=dict(name='Out', where='14 = Heat and 1.7 = Soak'))
Output 19.6.30: Predicted Probability for Heat=14 and Soak=1.7
| Pred | _XBETA_ | Heat | Soak |
|---|---|---|---|
| 0.0128363197 | -4.34255723 | 14 | 1.7 |
The ctable parameter computes statistics for binary response models (on the basis of classifying observations according to whether their predicted probabilities exceed certain values) and stores the results in the Roc data table. For more information, see the section Classification Table and ROC Curves.
The Roc data table contains information you can use to produce an ROC curve like the following:
Output 19.6.31: Receiver Operating Characteristics Curve

Binomial data are a form of grouped binary data in which "successes" in the underlying Bernoulli trials are totaled. You can thus unwind data for which you use the events/trials syntax and fit these data by using techniques for binary data.
The following DATA step expands the Ingots data table, which contains 12 events in 387 trials, into a data table that has 387 observations:
s.datastep.runcode(
code='''
data Ingots_binary;
set Ingots;
do i=1 to n;
if i <= r then y=1; else y = 0;
output;
end;
run;
''',
single='no')
The following statements fit the model that contains the Heat effect, the Soak effect, and their interaction to the data table. The event=’1’ response-variable subparameter in the model parameter ensures that the logistic action models the probability that the variable y takes the value 1.
s.regression.logistic(
model=dict(depVars=[dict(name='y', options=dict(event='1'))],
effects=[dict(vars=['Heat', 'Soak']),
dict(interaction='CROSS', vars=['Heat', 'Soak'])]),
table=dict(name='Ingots_binary'))
Output 19.6.32 displays the "Model Information," "Number of Observations," and "Response Profile" tables. The data are now modeled as binary (Bernoulli distributed) with a logit link function. The "Response Profile" table shows that the binary response breaks down into 375 observations where y=0 and 12 observations where y=1.
Output 19.6.32: Model Information in Binary Model
| RowId | Description | Value |
|---|---|---|
| DATA | Data Source | INGOTS_BINARY |
| RESPONSEVAR | Response Variable | y |
| DIST | Distribution | Binary |
| LINK | Link Function | Logit |
| TECH | Optimization Technique | Newton-Raphson with Ridging |
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 387 |
| NUSED | Number of Observations Used | 387 |
| OrderedValue | Outcome | y | Freq | Modeled |
|---|---|---|---|---|
| 1 | 0 | 0 | 375 | |
| 2 | 1 | 1 | 12 | * |
Output 19.6.33 displays the result of the test of the global null hypothesis and the parameter estimates. These results match those in Output 19.6.27 and Output 19.6.28.
Output 19.6.33: Null Test and Parameter Estimates
| Test | DF | ChiSq | ProbChiSq |
|---|---|---|---|
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
| Effect | Parameter | ParmName | DF | Estimate | StdErr | ChiSq | ProbChiSq |
|---|---|---|---|---|---|---|---|
| Intercept | Intercept | Intercept | 1 | -5.990191 | 1.666622 | 12.9183 | 0.0003 |
| Heat | Heat | Heat | 1 | 0.096339 | 0.047067 | 4.1896 | 0.0407 |
| Soak | Soak | Soak | 1 | 0.299574 | 0.755068 | 0.1574 | 0.6916 |
| Heat*Soak | Heat * Soak | Heat___Soak | 1 | -0.008840 | 0.025319 | 0.1219 | 0.7270 |
Modeling Binomial Response Data
This section contains R code that performs the same analysis as shown in the CASL version of this example.
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 Ingots data to the comma-separated-value (CSV) file Ingots.csv and then use the following code to load the CSV file into CAS:
m <- cas.read.csv(s, "Ingots.csv", casOut=list(name="Ingots"))
For more information about coding in R, see Getting Started with SAS Viya for R and SAS Viya: System Programming Guide.
The following statements use events/trials syntax to model the binomial response. The events variable in this situation is r, and the trials variable is n. The dependency of the probability of not being ready for rolling is modeled as a function of heating time (Heat), soaking time (Soak), and their interaction. The association parameter displays ordinal measures of association between the observed responses and the predicted probabilities. The ctable parameter saves statistics to the Roc data table that are used to evaluate the predictive power of the model. The output parameter stores the linear predictors and the predicted probabilities in the Out data table along with the other variables from the input data table.
m <- cas.builtins.loadActionSet(s, actionset='regression')
cas.regression.logistic(s,
association='true',
ctable=list(casOut=list(name='Roc', replace='true'),
fpf='FPF', nocounts='true', tpf='TPF'),
model=list(depVars=list(list(name='r')),
effects=list(list(vars=c('Heat', 'Soak')),
list(interaction='CROSS', vars=c('Heat', 'Soak'))),
trial='n'),
output=list(casOut=list(name='Out', replace='true'),
copyVars=c('Heat', 'Soak'),
pred='Pred', xBeta='_XBETA_'),
table='Ingots')
The "Model Information" table shows that the data are modeled as binomially distributed with a logit link function (Output 19.6.34). This is the default link function in the logistic action for binary and binomial data. The action estimates the parameters of the model by a Newton-Raphson algorithm.
Output 19.6.34: Model Information and Number of Observations
| RowId | Description | Value |
|---|---|---|
| DATA | Data Source | INGOTS |
| EVENTVAR | Response Variable (Events) | r |
| TRIALVAR | Response Variable (Trials) | n |
| DIST | Distribution | Binomial |
| LINK | Link Function | Logit |
| TECH | Optimization Technique | Newton-Raphson with Ridging |
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 19 |
| NUSED | Number of Observations Used | 19 |
| OrderedValue | Outcome | Freq | Modeled |
|---|---|---|---|
| 1 | Event | 12 | * |
| 2 | Nonevent | 375 |
The second table in Output 19.6.34 shows that all 19 observations in the input data table were used in the analysis and the "Response Profile" table shows that the total number of events and nonevents equals 12 and 375, respectively.
Output 19.6.35 displays the convergence status table for this run. The logistic action satisfies the gconv convergence criterion.
Output 19.6.35: Convergence Status
| Reason | Status | MaxGradient | Separation |
|---|---|---|---|
| Convergence criterion (GCONV=1E-8) satisfied. | 0 | 5.42E-11 | 0 |
Output 19.6.36 displays the "Dimensions" table for the model. The design matrix of the model (the matrix) has four columns, which correspond to the intercept, the Heat effect, the Soak effect, and the interaction of the Heat and Soak effects. The model is nonsingular because the rank of the crossproducts matrix equals the number of columns in . All parameters are estimable, and all participate in the optimization.
Output 19.6.36: Dimensions in Binomial Logistic Regression
| RowId | Description | Value |
|---|---|---|
| NDESIGNCOLS | Columns in Design | 4 |
| NEFFECTS | Number of Effects | 4 |
| MAXEFCOLS | Max Effect Columns | 1 |
| DESIGNRANK | Rank of Design | 4 |
| OPTPARM | Parameters in Optimization | 4 |
Output 19.6.37 displays the "Fit Statistics" table for this run. Evaluated at the converged estimates, –2 times the value of the log-likelihood function equals 27.95689. Further fit statistics are also displayed, all of them in "smaller is better" form. The AIC, AICC, and SBC criteria are used to compare non-nested models and to penalize the model fit for the number of observations and parameters. You can use the –2 log-likelihood value to compare nested models by way of a likelihood ratio test.
Output 19.6.37: Fit Statistics
| RowId | Description | Value |
|---|---|---|
| M2LL | -2 Log Likelihood | 27.95689 |
| AIC | AIC (smaller is better) | 35.95689 |
| AICC | AICC (smaller is better) | 38.81403 |
| SBC | SBC (smaller is better) | 39.73464 |
Output 19.6.38 shows the test of the global hypothesis that the effects jointly do not affect the probability of ingot readiness. You can obtain the chi-square test statistic by comparing the –2 log-likelihood value of the model with covariates to the value in the intercept-only model. The test is significant, with a p-value of 0.0082. One or more of the effects in the model have a significant impact on the probability of ingot readiness.
Output 19.6.38: Null Test
| Test | DF | ChiSq | ProbChiSq |
|---|---|---|---|
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
The "Parameter Estimates" table in Output 19.6.39 displays the estimates and standard errors of the model effects.
Output 19.6.39: Parameter Estimates
| Effect | Parameter | ParmName | DF | Estimate | StdErr | ChiSq | ProbChiSq |
|---|---|---|---|---|---|---|---|
| Intercept | Intercept | Intercept | 1 | -5.990191 | 1.666622 | 12.9183 | 0.0003 |
| Heat | Heat | Heat | 1 | 0.096339 | 0.047067 | 4.1896 | 0.0407 |
| Soak | Soak | Soak | 1 | 0.299574 | 0.755068 | 0.1574 | 0.6916 |
| Heat*Soak | Heat * Soak | Heat___Soak | 1 | -0.008840 | 0.025319 | 0.1219 | 0.7270 |
Output 19.6.40 displays the "Association Statistics" table, which is produced when you specify the association parameter. The table contains four measures of association for assessing the predictive ability of a model. For more information, see the section Association Statistics.
Output 19.6.40: Association of Observed Responses and Predicted Probabilities
| RowId | Description | Value |
|---|---|---|
| C | Concordance Index (AUC) | 0.7706 |
| SOMERSD | Somers' D | 0.5411 |
| GAMMA | Gamma | 0.5858 |
| TAUA | Tau-a | 0.0326 |
| PAIRS | Pairs | 4500 |
| CONCORD | Percent Concordant | 73.2444 |
| DISCORD | Percent Discordant | 19.1333 |
| TIED | Percent Tied | 7.6222 |
You can construct the prediction equation of the model from the "Parameter Estimates" table. For example, an observation with Heat equal to 14 and Soak equal to 1.7 has the linear predictor
The probability that an ingot with these characteristics is not ready for rolling is
The logistic action computes these linear predictors and probabilities and stores them in the Out data table.
The following fetch action from the tables action set enables you to display Output 19.6.41, which shows the probability that an ingot with Heat equal to 14 and Soak equal to 1.7 is not ready for rolling:
cas.table.fetch(s,
format='true',
index='false',
table=list(name='Out', where='14 = Heat and 1.7 = Soak'))
Output 19.6.41: Predicted Probability for Heat=14 and Soak=1.7
| Pred | _XBETA_ | Heat | Soak |
|---|---|---|---|
| 0.0128363197 | -4.34255723 | 14 | 1.7 |
The ctable parameter computes statistics for binary response models (on the basis of classifying observations according to whether their predicted probabilities exceed certain values) and stores the results in the Roc data table. For more information, see the section Classification Table and ROC Curves.
The Roc data table contains information you can use to produce an ROC curve like the following:
Output 19.6.42: Receiver Operating Characteristics Curve

Binomial data are a form of grouped binary data in which "successes" in the underlying Bernoulli trials are totaled. You can thus unwind data for which you use the events/trials syntax and fit these data by using techniques for binary data.
The following DATA step expands the Ingots data table, which contains 12 events in 387 trials, into a data table that has 387 observations:
cas.dataStep.runCode(s,
code='
data Ingots_binary;
set Ingots;
do i=1 to n;
if i <= r then y=1; else y = 0;
output;
end;
run;
',
single='no')
The following statements fit the model that contains the Heat effect, the Soak effect, and their interaction to the data table. The event=’1’ response-variable subparameter in the model parameter ensures that the logistic action models the probability that the variable y takes the value 1.
cas.regression.logistic(s,
model=list(depVars=list(list(name='y', options=list(event='1'))),
effects=list(list(vars=c('Heat', 'Soak')),
list(interaction='CROSS', vars=c('Heat', 'Soak')))),
table=list(name='Ingots_binary'))
Output 19.6.43 displays the "Model Information," "Number of Observations," and "Response Profile" tables. The data are now modeled as binary (Bernoulli distributed) with a logit link function. The "Response Profile" table shows that the binary response breaks down into 375 observations where y=0 and 12 observations where y=1.
Output 19.6.43: Model Information in Binary Model
| RowId | Description | Value |
|---|---|---|
| DATA | Data Source | INGOTS_BINARY |
| RESPONSEVAR | Response Variable | y |
| DIST | Distribution | Binary |
| LINK | Link Function | Logit |
| TECH | Optimization Technique | Newton-Raphson with Ridging |
| RowId | Description | Value |
|---|---|---|
| NREAD | Number of Observations Read | 387 |
| NUSED | Number of Observations Used | 387 |
| OrderedValue | Outcome | y | Freq | Modeled |
|---|---|---|---|---|
| 1 | 0 | 0 | 375 | |
| 2 | 1 | 1 | 12 | * |
Output 19.6.44 displays the result of the test of the global null hypothesis and the parameter estimates. These results match those in Output 19.6.38 and Output 19.6.39.
Output 19.6.44: Null Test and Parameter Estimates
| Test | DF | ChiSq | ProbChiSq |
|---|---|---|---|
| Likelihood Ratio | 3 | 11.7663 | 0.0082 |
| Effect | Parameter | ParmName | DF | Estimate | StdErr | ChiSq | ProbChiSq |
|---|---|---|---|---|---|---|---|
| Intercept | Intercept | Intercept | 1 | -5.990191 | 1.666622 | 12.9183 | 0.0003 |
| Heat | Heat | Heat | 1 | 0.096339 | 0.047067 | 4.1896 | 0.0407 |
| Soak | Soak | Soak | 1 | 0.299574 | 0.755068 | 0.1574 | 0.6916 |
| Heat*Soak | Heat * Soak | Heat___Soak | 1 | -0.008840 | 0.025319 | 0.1219 | 0.7270 |