Main Content

risk.validation.makeResponseBinary

Discretize continuous response variable

Since R2025a

    Description

    BinaryResponse = risk.validation.makeResponseBinary(ContinuousResponse) discretizes a continuous response variable by returning a value of 1 for elements that are greater than or equal to the mean value, and 0 otherwise. ContinuousResponse contains numeric values that represent quantities such as observed loss given default (LGD) values. You can use this function for preprocessing your data whenever you need a binary representation of a continuous variable.

    BinaryResponse = risk.validation.makeResponseBinary(ContinuousResponse,Name=Value) specifies optional name-value arguments that you can use to customize the discretization. For example, BinaryResponse = risk.validation.makeResponseBinary(ContinuousResponse,Threshold="median") uses a median threshold to discretize a continuous response variable.

    example

    Examples

    collapse all

    Use the makeResponseBinary function to discretize a continuous response variable and return the binary response. In this example, you use the credit validation data set, which includes a table, LGDModelsValidationData, that contains observed LGD data that you can use with this function.

    Load and display the credit validation data.

    load CreditValidationData.mat
    head(LGDModelsValidationData)
        RegressionLGD    TobitLGD    ObservedLGD
        _____________    ________    ___________
    
          0.0083013      0.15786      0.072437  
          0.0034909      0.13122             0  
          0.0019643      0.11273             0  
           0.041439      0.22448      0.038687  
           0.015978      0.18818       0.52643  
            0.27081      0.35565       0.17372  
           0.024934      0.20432       0.12477  
           0.034829       0.2326      0.079027  
    

    Extract the variable ObservedLGD and use it as the input to the makeResonseBinary function with the fully qualified namespace risk.validation. Use the Threshold name-value argument to specify a median threshold for the discretization method. You can then display the resulting binary response, where values of 1 represent LGD values that exceed the threshold.

    LGDValues = LGDModelsValidationData.ObservedLGD;
    ContinuousResponse = LGDValues;
    BinaryResponse = risk.validation.makeResponseBinary(ContinuousResponse,Threshold="median");
    head(BinaryResponse)
         1
         0
         0
         1
         1
         1
         1
         1
    

    Use the binary response to compute a discrimination metric for one of the variables in LGDModelsValidationData. For example, calculate the area under the curve for the RegressionLGD variable by using the risk.validation.areaUnderCurve function. Use RegressionLGD for the input variable Score.

    Score = LGDModelsValidationData.RegressionLGD;
    [aucValue,Output] = risk.validation.areaUnderCurve(Score,BinaryResponse,SortDirection="ascending")
    aucValue = 
    0.2902
    
    Output = struct with fields:
        AreaUnderCurve: 0.2902
               Metrics: [349×3 table]
    
    

    Input Arguments

    collapse all

    Continuous response variable, specified as a numeric vector. ContinuousResponse contains numeric values that represent quantities such as observed LGD values.

    Name-Value Arguments

    collapse all

    Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

    Example: BinaryResponse = risk.validation.makeResponseBinary(LGDValues,Threshold="median")

    Threshold value, specified as "mean", "median", or a numeric scalar. The function compares each value in ContinuousResponse to Threshold to determine the binary response.

    Comparison operator, specified as a string scalar. You can choose from the following comparison operators:

    • "ge" — Greater than or equal to

    • "gt" — Greater than

    • "le" — Less than or equal to

    • "lt" — Less than

    • "eq" — Equal to

    • "ne" — Not equal to

    For example, if you specify "gt" as the comparison operator and "mean" as the threshold for observed LGD values, the binary response values are 1 for elements where the LGD exceeds the mean value, and 0 otherwise.

    Output Arguments

    collapse all

    Binary response, returned as a numeric vector, where each value represents the comparison of each element of a continuous response variable against a threshold.

    Version History

    Introduced in R2025a