The SEVSELECT Procedure

Custom Objective Functions

You can use a series of programming statements that use variables in the DATA= data table to assign a value to an objective function symbol. You must specify the objective function symbol by using the OBJECTIVE= option in the PROC SEVSELECT statement.

The objective function can be programmed such that it applies to any distribution that is used in the model. For that purpose, PROC SEVSELECT recognizes the following keyword functions in the programming statements:

_PDF_(x)

evaluates the probability density function (PDF) of a distribution at the current value of a data table variable x.

_CDF_(x)

evaluates the cumulative distribution function (CDF) of a distribution at the current value of a data table variable x.

_SDF_(x)

evaluates the survival distribution function (SDF) of a distribution at the current value of a data table variable x.

_LOGPDF_(x)

evaluates the natural logarithm of the PDF of a distribution at the current value of a data table variable x.

_LOGCDF_(x)

evaluates the natural logarithm of the CDF of a distribution at the current value of a data table variable x.

_LOGSDF_(x)

evaluates the natural logarithm of the SDF of a distribution at the current value of a data table variable x.

_EDF_(x)

evaluates the empirical distribution function (EDF) estimate at the current value of a data table variable x. Internally, PROC SEVSELECT computes the estimate by using the SVRTUTIL_EDF function as described in the section Predefined Utility Functions. The EDF estimate that the SVRTUTIL_EDF function requires is computed by using a subset of observations in the current BY group or a subset of the input data table if you do not specify the BY statement. The subset of observations is randomly chosen on each worker node by using the values that you specify in the INITSAMPLE option.

_EMPLIMMOMENT_(k, u)


evaluates the empirical limited moment of order k at the current value of a data table variable u that represents the upper limit of the limited moment. The order k can also be a data table variable. Internally, PROC SEVSELECT computes the moment by using the SVRTUTIL_EMPLIMMOMENT function as described in the section Predefined Utility Functions. The EDF estimate that the SVRTUTIL_EMPLIMMOMENT function requires is computed by using a subset of observations in the current BY group or a subset of the input data table if you do not specify the BY statement. The subset of observations is randomly chosen on each worker node by using the values that you specify in the INITSAMPLE option.

_LIMMOMENT_(k, u)


evaluates the limited moment of order k at the current value of a data table variable u that represents the upper limit of the limited moment. The order k can be a data table variable or a constant. Internally, for each candidate distribution, PROC SEVSELECT computes the moment by using the LIMMOMENT function as described in the section Predefined Utility Functions.

All the preceding functions are right-hand-side functions. They act as placeholders for distribution-specific functions, with the exception of _EDF_ and _EMPLIMMOMENT_ functions.

As an example, suppose that the data table mycas.Test contains a response variable Y and a left-truncation threshold variable T. The following statements use the values in this data table to fit a model with distribution D such that the parameters of the model minimize the value of the objective function symbol MYOBJ:

options cmplib=(work.mydist);
proc sevselect data=mycas.test objective=myobj;
    loss y / lt=t;

    myobj = -_LOGPDF_(y);
    if (not(missing(t))) then
        myobj = myobj + log(1-_CDF_(t));

    dist d;
run;

You designate the symbol MYOBJ as an objective function symbol by using the OBJECTIVE= option in the PROC SEVSELECT statement. The response variable Y and left-truncation variable T are specified in the LOSS statement. The distribution D is specified in the DIST statement. The remaining statements constitute a program that computes the value of the MYOBJ symbol.

Let the distribution D have the parameters P1 and P2. To estimate the model for this distribution, PROC SEVSELECT internally converts the generic program to the following program specific to distribution D:

myobj = -D_LOGPDF(y, p1, p2);
if (not(missing(t))) then
    myobj = myobj + log(1-D_CDF(t, p1, p2));

Note that the generic keyword functions _LOGPDF_ and _CDF_ have been replaced by the distribution-specific functions D_LOGPDF and D_CDF, respectively, and the argument list of each is expanded to include the distribution parameters. You must have defined the D_LOGPDF and D_CDF functions previously; they are assumed to be available in the library Work.Mydist that you specify in the CMPLIB= option.

The program is executed for each observation in the data table mycas.Test to compute the value of MYOBJ by using the values of variables Y and T in that observation and internally computed values of the model parameters P1 and P2. The values of MYOBJ are then added over all the observations of the data table or over all the observations of the current BY group if you specify the BY statement. The resulting aggregate value is the value of the objective function, and it is supplied to the optimizer. If the optimizer requires derivatives of the objective function, then PROC SEVSELECT automatically differentiates MYOBJ with respect to the parameters P1 and P2. The optimizer iterates through various combinations of the values of P1 and P2; in each iteration, it computes a new value of the objective function and the needed derivatives of it, until it finds a combination that minimizes the objective function.

Note the following points when you define your own program to compute the custom objective function:

  • The value of the objective function is always minimized by PROC SEVSELECT. If you want to maximize the value of a certain objective, then add a statement that assigns the negated value of the maximization objective to the objective function symbol that you specify in the OBJECTIVE= option. Minimization of the negated objective is equivalent to maximization of the original objective.

  • The contributions of individual observations are always added together to compute the overall objective function in a given iteration of the optimizer. If you specify the WEIGHT statement, then the contribution of each observation is weighted by multiplying it by the normalized value of the weight variable for that observation.

  • If you are fitting multiple distributions in one PROC SEVSELECT step and you use any of the keyword functions in your program, then it is recommended that you not explicitly use the parameters of any of the specified distributions in your programming statements.

  • If you use a specific keyword function in your programming statements, then the corresponding distribution functions must be defined in a library that you specify in the CMPLIB= system option or in Sashelp.Svrtdist, the predefined functions library. In the preceding example, it is assumed that the functions D_LOGPDF and D_CDF are defined in the library Work.Mydist, which you specify in the CMPLIB= option.

  • You can use most DATA step statements and functions in your program. The DATA step file and the data set I/O statements (for example, INPUT, FILE, SET, and MERGE) are not available. However, some PUT statement functionality is supported. For more information, see the section "PROC FCMP and DATA Step Differences" in SAS Visual Data Management and Utility Procedures Guide. In addition to the differences that are listed in that section, the following differences exist:

    • You can use only numeric-valued variables in PROC SEVSELECT programming statements. This restriction also implies that you cannot use SAS functions or call routines that require character-valued arguments, unless you pass those arguments as constant (literal) strings or characters.

    • You cannot use functions that create lagged versions of a variable in PROC SEVSELECT programming statements. If you need lagged versions, then you can use a DATA step before the PROC SEVSELECT step to add those versions to the input data table.

  • When you are writing your programming statements, avoid defining variables that begin with an underscore (_), because they might conflict with internal variables that PROC SEVSELECT creates.

Custom Objective Functions and Regression Effects

If you specify regression effects by using the SCALEMODEL statement, then PROC SEVSELECT automatically adds a statement before your programming statements to compute the value of the scale parameter or the log-transformed scale parameter of the distribution by using the values of the regression variables and internally created regression parameters. For example, if your specification of the SCALEMODEL statement results in three regression effects, x1, x2, and x3, then for a model that contains the distribution D with scale parameter S, PROC SEVSELECT adds to the beginning of your program a statement that is equivalent to the following statement:

 S = _SEVTHETA0 * exp(_SEVBETA1 * x1 + _SEVBETA2 * x2 + _SEVBETA3 * x3);

If a model contains a distribution D1 with a log-transformed scale parameter M, PROC SEVSELECT adds to the beginning of your program a statement that is equivalent to the following statement:

 M = _SEVTHETA0 + _SEVBETA1 * x1 + _SEVBETA2 * x2 + _SEVBETA3 * x3;

The internal symbols _SEVTHETA0, _SEVBETA1, _SEVBETA2, and _SEVBETA3 represent the regression parameters that are associated with the intercept and the regression effects x1, x2, and x3, respectively.

Because the names of the internal regression parameter symbols start with the prefix _SEV, if you use a variable in your program whose name begins with _SEV, then PROC SEVSELECT writes an error message to the SAS log and stops processing.

Last updated: June 14, 2018