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

Results from regression.logistic

Model Information
Data SourceINGOTS
Response Variable (Events)r
Response Variable (Trials)n
DistributionBinomial
Link FunctionLogit
Optimization TechniqueNewton-Raphson with Ridging

Number of Observations Read19
Number of Observations Used19

Response Profile
Ordered
Value
Binary OutcomeTotal
Frequency
1Event12
2Nonevent375


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 bold upper X 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 bold upper X. All parameters are estimable, and all participate in the optimization.

Output 19.6.3: Dimensions in Binomial Logistic Regression

Dimensions
Columns in Design4
Number of Effects4
Max Effect Columns1
Rank of Design4
Parameters in Optimization4


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 Likelihood27.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
TestDFChi-SquarePr > ChiSq
Likelihood Ratio311.76630.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
ParameterDFEstimateStandard
Error
Chi-SquarePr > ChiSq
Intercept1-5.9901911.66662212.91830.0003
Heat10.0963390.0470674.18960.0407
Soak10.2995740.7550680.15740.6916
Heat * Soak1-0.0088400.0253190.12190.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' D0.5411
Gamma0.5858
Tau-a0.0326
Pairs4500
Percent Concordant73.2444
Percent Discordant19.1333
Percent Tied7.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

Results from table.fetch

Selected Rows from Table OUT
Predicted ValueLinear PredictorHeatSoak
0.0128363197-4.34255723141.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

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

Results from regression.logistic

Model Information
Data SourceINGOTS_BINARY
Response Variabley
DistributionBinary
Link FunctionLogit
Optimization TechniqueNewton-Raphson with Ridging

Number of Observations Read387
Number of Observations Used387

Response Profile
Ordered
Value
yTotal
Frequency
10375
2112

Probability modeled is y = 1.



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
TestDFChi-SquarePr > ChiSq
Likelihood Ratio311.76630.0082

Parameter Estimates
ParameterDFEstimateStandard
Error
Chi-SquarePr > ChiSq
Intercept1-5.9901911.66662212.91830.0003
Heat10.0963390.0470674.18960.0407
Soak10.2995740.7550680.15740.6916
Heat * Soak1-0.0088400.0253190.12190.7270


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

RowIdDescriptionValue
DATAData SourceINGOTS
EVENTVARResponse Variable (Events)r
TRIALVARResponse Variable (Trials)n
DISTDistributionBinomial
LINKLink FunctionLogit
TECHOptimization TechniqueNewton-Raphson with Ridging

RowIdDescriptionValue
NREADNumber of Observations Read19
NUSEDNumber of Observations Used19

OrderedValueOutcomeFreqModeled
1Event12*
2Nonevent375 


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

ReasonStatusMaxGradientSeparation
Convergence criterion (GCONV=1E-8) satisfied.05.42E-110


Output 19.6.14 displays the "Dimensions" table for the model. The design matrix of the model (the bold upper X 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 bold upper X. All parameters are estimable, and all participate in the optimization.

Output 19.6.14: Dimensions in Binomial Logistic Regression

RowIdDescriptionValue
NDESIGNCOLSColumns in Design4
NEFFECTSNumber of Effects4
MAXEFCOLSMax Effect Columns1
DESIGNRANKRank of Design4
OPTPARMParameters in Optimization4


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

RowIdDescriptionValue
M2LL-2 Log Likelihood27.95689
AICAIC (smaller is better)35.95689
AICCAICC (smaller is better)38.81403
SBCSBC (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

TestDFChiSqProbChiSq
Likelihood Ratio311.76630.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

EffectParameterParmNameDFEstimateStdErrChiSqProbChiSq
InterceptInterceptIntercept1-5.9901911.66662212.91830.0003
HeatHeatHeat10.0963390.0470674.18960.0407
SoakSoakSoak10.2995740.7550680.15740.6916
Heat*SoakHeat * SoakHeat___Soak1-0.0088400.0253190.12190.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

RowIdDescriptionValue
CConcordance Index (AUC)0.7706
SOMERSDSomers' D0.5411
GAMMAGamma0.5858
TAUATau-a0.0326
PAIRSPairs4500
CONCORDPercent Concordant73.2444
DISCORDPercent Discordant19.1333
TIEDPercent Tied7.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_HeatSoak
0.0128363197-4.34255723141.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

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

RowIdDescriptionValue
DATAData SourceINGOTS_BINARY
RESPONSEVARResponse Variabley
DISTDistributionBinary
LINKLink FunctionLogit
TECHOptimization TechniqueNewton-Raphson with Ridging

RowIdDescriptionValue
NREADNumber of Observations Read387
NUSEDNumber of Observations Used387

OrderedValueOutcomeyFreqModeled
100375 
21112*


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

TestDFChiSqProbChiSq
Likelihood Ratio311.76630.0082

EffectParameterParmNameDFEstimateStdErrChiSqProbChiSq
InterceptInterceptIntercept1-5.9901911.66662212.91830.0003
HeatHeatHeat10.0963390.0470674.18960.0407
SoakSoakSoak10.2995740.7550680.15740.6916
Heat*SoakHeat * SoakHeat___Soak1-0.0088400.0253190.12190.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

RowIdDescriptionValue
DATAData SourceINGOTS
EVENTVARResponse Variable (Events)r
TRIALVARResponse Variable (Trials)n
DISTDistributionBinomial
LINKLink FunctionLogit
TECHOptimization TechniqueNewton-Raphson with Ridging

RowIdDescriptionValue
NREADNumber of Observations Read19
NUSEDNumber of Observations Used19

OrderedValueOutcomeFreqModeled
1Event12*
2Nonevent375 


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

ReasonStatusMaxGradientSeparation
Convergence criterion (GCONV=1E-8) satisfied.05.42E-110


Output 19.6.25 displays the "Dimensions" table for the model. The design matrix of the model (the bold upper X 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 bold upper X. All parameters are estimable, and all participate in the optimization.

Output 19.6.25: Dimensions in Binomial Logistic Regression

RowIdDescriptionValue
NDESIGNCOLSColumns in Design4
NEFFECTSNumber of Effects4
MAXEFCOLSMax Effect Columns1
DESIGNRANKRank of Design4
OPTPARMParameters in Optimization4


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

RowIdDescriptionValue
M2LL-2 Log Likelihood27.95689
AICAIC (smaller is better)35.95689
AICCAICC (smaller is better)38.81403
SBCSBC (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

TestDFChiSqProbChiSq
Likelihood Ratio311.76630.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

EffectParameterParmNameDFEstimateStdErrChiSqProbChiSq
InterceptInterceptIntercept1-5.9901911.66662212.91830.0003
HeatHeatHeat10.0963390.0470674.18960.0407
SoakSoakSoak10.2995740.7550680.15740.6916
Heat*SoakHeat * SoakHeat___Soak1-0.0088400.0253190.12190.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

RowIdDescriptionValue
CConcordance Index (AUC)0.7706
SOMERSDSomers' D0.5411
GAMMAGamma0.5858
TAUATau-a0.0326
PAIRSPairs4500
CONCORDPercent Concordant73.2444
DISCORDPercent Discordant19.1333
TIEDPercent Tied7.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_HeatSoak
0.0128363197-4.34255723141.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

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

RowIdDescriptionValue
DATAData SourceINGOTS_BINARY
RESPONSEVARResponse Variabley
DISTDistributionBinary
LINKLink FunctionLogit
TECHOptimization TechniqueNewton-Raphson with Ridging

RowIdDescriptionValue
NREADNumber of Observations Read387
NUSEDNumber of Observations Used387

OrderedValueOutcomeyFreqModeled
100375 
21112*


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

TestDFChiSqProbChiSq
Likelihood Ratio311.76630.0082

EffectParameterParmNameDFEstimateStdErrChiSqProbChiSq
InterceptInterceptIntercept1-5.9901911.66662212.91830.0003
HeatHeatHeat10.0963390.0470674.18960.0407
SoakSoakSoak10.2995740.7550680.15740.6916
Heat*SoakHeat * SoakHeat___Soak1-0.0088400.0253190.12190.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

RowIdDescriptionValue
DATAData SourceINGOTS
EVENTVARResponse Variable (Events)r
TRIALVARResponse Variable (Trials)n
DISTDistributionBinomial
LINKLink FunctionLogit
TECHOptimization TechniqueNewton-Raphson with Ridging

RowIdDescriptionValue
NREADNumber of Observations Read19
NUSEDNumber of Observations Used19

OrderedValueOutcomeFreqModeled
1Event12*
2Nonevent375 


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

ReasonStatusMaxGradientSeparation
Convergence criterion (GCONV=1E-8) satisfied.05.42E-110


Output 19.6.36 displays the "Dimensions" table for the model. The design matrix of the model (the bold upper X 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 bold upper X. All parameters are estimable, and all participate in the optimization.

Output 19.6.36: Dimensions in Binomial Logistic Regression

RowIdDescriptionValue
NDESIGNCOLSColumns in Design4
NEFFECTSNumber of Effects4
MAXEFCOLSMax Effect Columns1
DESIGNRANKRank of Design4
OPTPARMParameters in Optimization4


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

RowIdDescriptionValue
M2LL-2 Log Likelihood27.95689
AICAIC (smaller is better)35.95689
AICCAICC (smaller is better)38.81403
SBCSBC (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

TestDFChiSqProbChiSq
Likelihood Ratio311.76630.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

EffectParameterParmNameDFEstimateStdErrChiSqProbChiSq
InterceptInterceptIntercept1-5.9901911.66662212.91830.0003
HeatHeatHeat10.0963390.0470674.18960.0407
SoakSoakSoak10.2995740.7550680.15740.6916
Heat*SoakHeat * SoakHeat___Soak1-0.0088400.0253190.12190.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

RowIdDescriptionValue
CConcordance Index (AUC)0.7706
SOMERSDSomers' D0.5411
GAMMAGamma0.5858
TAUATau-a0.0326
PAIRSPairs4500
CONCORDPercent Concordant73.2444
DISCORDPercent Discordant19.1333
TIEDPercent Tied7.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_HeatSoak
0.0128363197-4.34255723141.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

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

RowIdDescriptionValue
DATAData SourceINGOTS_BINARY
RESPONSEVARResponse Variabley
DISTDistributionBinary
LINKLink FunctionLogit
TECHOptimization TechniqueNewton-Raphson with Ridging

RowIdDescriptionValue
NREADNumber of Observations Read387
NUSEDNumber of Observations Used387

OrderedValueOutcomeyFreqModeled
100375 
21112*


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

TestDFChiSqProbChiSq
Likelihood Ratio311.76630.0082

EffectParameterParmNameDFEstimateStdErrChiSqProbChiSq
InterceptInterceptIntercept1-5.9901911.66662212.91830.0003
HeatHeatHeat10.0963390.0470674.18960.0407
SoakSoakSoak10.2995740.7550680.15740.6916
Heat*SoakHeat * SoakHeat___Soak1-0.0088400.0253190.12190.7270


Last updated: October 29, 2020