Nonlinear Models Action Set

Binomial Model

In the example "Probit Model with Likelihood Function" in the chapter "The NLIN Procedure" in SAS/STAT User's Guide, cancer remission is modeled by expressing the maximum likelihood function for a binary distribution as a nonlinear least squares optimization. The following statements provide an equivalent formulation of this model that uses nlmod action and specifies the binary distribution explicitly:

data mycas.Remiss;
   input remiss cell smear infil li blast temp;
   label remiss = 'complete remission';
   datalines;
 1 0.8  .83 .66 1.9 1.10   .996
 1 0.9  .36 .32 1.4 0.74   .992
 0 0.8  .88 .70 0.8 0.176  .982
 0 1    .87 .87 0.7 1.053  .986
 1 0.9  .75 .68 1.3 0.519  .980
 0 1    .65 .65 0.6 0.519  .982
 1 0.95 .97 .92 1   1.23   .992
 0 0.95 .87 .83 1.9 1.354 1.020
 0 1    .45 .45 0.8 0.322  .999
 0 0.95 .36 .34 0.5 0     1.038
 0 0.85 .39 .33 0.7 0.279  .988
 0 0.7  .76 .53 1.2 0.146  .982
 0 0.8  .46 .37 0.4 0.38  1.006
 0 0.2  .39 .08 0.8 0.114  .990
 0 1    .90 .90 1.1 1.037  .990
 1 1    .84 .84 1.9 2.064 1.020
 0 0.65 .42 .27 0.5 0.114 1.014
 0 1    .75 .75 1   1.322 1.004
 0 0.5  .44 .22 0.6 0.114  .990
 1 1    .63 .63 1.1 1.072  .986
 0 1    .33 .33 0.4 0.176 1.010
 0 0.9  .93 .84 0.6 1.591 1.020
 1 1    .58 .58 1   0.531 1.002
 0 0.95 .32 .30 1.6 0.886  .988
 1 1    .60 .60 1.7 0.964  .990
 1 1    .69 .69 0.9 0.398  .986
 0 1    .73 .73 0.7 0.398  .986
 ;
proc cas;
   nonlinear.nlmod
      table='remiss',
      parms={{name='int',vals=-10},
             {name='a',vals=-2},
             {name='b',vals=-1},
             {name='c',vals=6}},
      nlmodCode='linp = int + a*cell + b*li + c*temp;
                 p = probnorm(linp);',
      model={depvar='remiss',
             dist='binary',
             distparms='1-p'};
run;

The table parameter names the input data table. The parms parameter specifies the initial values of the model parameters int, a, b, and c. The nlmodCode parameter specifies the nonlinear part of the model by using the programming statements. The model parameter specifies the model: the depVar subparameter specifies the variable remiss as the response variable; the dist subparameter specifies that the response variable has a binary type of distribution, indicating that the maximum likelihood approach is used to fit the model; and the distparms subparameter specifies the distribution parameters.

The output from this analysis is displayed by default. A few of the output tables are shown in Output 16.2.1 through Output 16.2.5.

The "Specifications" table (Output 16.2.1) indicates that the response variable remiss has a binary distribution and that the Newton-Raphson with ridging optimization technique is used to minimize the negative log likelihood.

Output 16.2.1: Model Specifications

Results from nonlinear.nlmod

Specifications
Data SourceREMISS
Dependent Variableremiss
DistributionBinary
Optimization TechniqueNewton-Raphson with Ridging


Starting with the initial values shown in the table in Output 16.2.2, the nlmod action uses Newton-Raphson with ridging optimization and produces the "Iteration History" table in Output 16.2.3.

Output 16.2.2: Starting Values of Parameter Estimates and Negative Log Likelihood

Initial Parameter Values
theta1theta2Objective
0020723.96


The "Iteration History" table records the history of the minimization of the negative log likelihood (Output 16.2.3). For each iteration of the Newton-Raphson with ridging optimization, values are listed for the number of function calls, the negative log likelihood, the difference from the previous iteration, and the absolute value of the largest gradient.

Output 16.2.3: Iteration History

Iteration History
IterationEvaluationsObjective
Function
ChangeMaximum
Gradient
0516.218491791 4.449991
121.18269365815.035798130.665597
220.44822987450.734463780.068514
320.41775185730.030478020.019942
420.40755423180.010197630.006817
520.40559283010.001961400.001154
620.40555839340.000034440.000022
720.40555838490.000000015.621E-9


Unlike the previous example, this example produces no analysis-of-variance table for this model. Fit statistics based on the value of the likelihood function are displayed in Output 16.2.4.

The final maximized value of the log likelihood as well as the Akaike’s information criterion (AIC), its small-sample bias-corrected version (AICC), and the Bayesian information criterion (BIC) in "smaller is better" form appear in the "Fit Statistics" table (Output 16.2.4). You can use these statistics to compare different nonlinear models.

Output 16.2.4: Nonlinear Likelihood Function Statistics

Fit Statistics
-2 Log Likelihood21.9002
AIC (smaller is better)29.9002
AICC (smaller is better)31.7183
BIC (smaller is better)35.0835


Parameter estimates and the confidence intervals for the binary distribution model are displayed in Output 16.2.5.

Output 16.2.5: Parameter Estimates and Approximate 95% Confidence Intervals

Parameter Estimates
ParameterEstimateStandard
Error
DFt ValueApprox
Pr > |t|
Approximate 95% Confidence
Limits
LowerUpper
int-36.754832.360727-1.140.2660-103.229.6439
a-5.62984.637627-1.210.2353-15.14543.8858
b-2.25130.979027-2.300.0294-4.2599-0.2426
c45.181534.9095271.290.2065-26.4469116.8


Binomial Model

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 remiss data to the comma-separated-value (CSV) file remiss.csv and then use the following code to load the CSV file into CAS:

s:loadtable{casLib="casuser", path="remiss.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 nonlinear action set and then uses the nlmod action in the nonlinear action set to fit a probit model to the data table remiss:

s:loadactionset{actionset='nonlinear'}
m=s:nlmod{table={name='remiss'},
      parms={{name='int',vals=-10},
             {name='a',vals=-2},
             {name='b',vals=-1},
             {name='c',vals=6}},
      nlmodCode='linp = int + a*cell + b*li + c*temp; \z
                 p = probnorm(linp);',
      model={depvar='remiss',
             dist='binary',
             distparms='1-p'} }

The table parameter names the input data table. The parms parameter specifies the initial values of the model parameters int, a, b, and c. The nlmodCode parameter specifies the nonlinear part of the model by using the programming statements. The model parameter specifies the model: the depVar subparameter specifies the variable remiss as the response variable; the dist subparameter specifies that the response variable has a binary type of distribution, indicating that the maximum likelihood approach is used to fit the model; and the distparms subparameter specifies the distribution parameters.

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

print(m.Specifications)
print(m.Parameters)
print(m.IterHistory)
print(m.FitStatistics)
print(m.ParameterEstimates)
print(m.Timing)

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

Binomial Model

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 remiss data to the comma-separated-value (CSV) file remiss.csv and then use the following code to load the CSV file into CAS:

s.upload_file('remiss.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 nonlinear action set and then uses the nlmod action in the nonlinear action set to fit a probit model to the data table remiss:

s.loadactionset(actionset='nonlinear')
m=s.nlmod(table='remiss',
      parms=[{'name':'int','vals':-10},
             {'name':'a','vals':-2},
             {'name':'b','vals':-1},
             {'name':'c','vals':6}],
      nlmodCode="""linp = int + a*cell + b*li + c*temp;
                 p = probnorm(linp);""",
      model={'depvar':'remiss',
             'dist':'binary',
             'distparms':'1-p'} )

The table parameter names the input data table. The parms parameter specifies the initial values of the model parameters int, a, b, and c. The nlmodCode parameter specifies the nonlinear part of the model by using the programming statements. The model parameter specifies the model: the depVar subparameter specifies the variable remiss as the response variable; the dist subparameter specifies that the response variable has a binary type of distribution, indicating that the maximum likelihood approach is used to fit the model; and the distparms subparameter specifies the distribution parameters.

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

print(m.Specifications)
print(m.Parameters)
print(m.IterHistory)
print(m.FitStatistics)
print(m.ParameterEstimates)
print(m.Timing)

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.

Binomial Model

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 remiss data to the comma-separated-value (CSV) file remiss.csv and then use the following code to load the CSV file into CAS:

m <- cas.read.csv(s, "remiss.csv", casOut=list(name="remiss"))

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 nonlinear action set and then uses the nlmod action in the nonlinear action set to fit a probit model to the data table remiss:

m <- cas.builtins.loadActionSet(s, actionset='nonlinear')
m <- cas.nonlinear.nlmod(s,
      table='remiss',
      parms=list(list(name='int',vals=-10),
             list(name='a',vals=-2),
             list(name='b',vals=-1),
             list(name='c',vals=6)),
      nlmodCode='linp = int + a*cell + b*li + c*temp;
                 p = probnorm(linp);',
      model=list(depvar='remiss',
             dist='binary',
             distparms='1-p') )

The table parameter names the input data table. The parms parameter specifies the initial values of the model parameters int, a, b, and c. The nlmodCode parameter specifies the nonlinear part of the model by using the programming statements. The model parameter specifies the model: the depVar subparameter specifies the variable remiss as the response variable; the dist subparameter specifies that the response variable has a binary type of distribution, indicating that the maximum likelihood approach is used to fit the model; and the distparms subparameter specifies the distribution parameters.

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

print(m$Specifications)
print(m$Parameters)
print(m$IterHistory)
print(m$FitStatistics)
print(m$ParameterEstimates)
print(m$Timing)

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.

Last updated: September 17, 2026