Main Content

risk.validation.groupNumberByQuantile

Group array elements by quantile

Since R2025a

    Description

    groupNum = groupNumberByQuantile(data,QuantileType) assigns each element in data to a group number for a specified quantile type, and returns the group numbers. data can represent quantities such as credit scores, probability of default (PD), or loss given default (LGD) estimates.

    example

    groupNum = groupNumberByQuantile(data,numGroups) specifies a custom number of desired groups with approximately the same number of observations in each group.

    Note

    The number of observations in each group depends on the contents of data and is not guaranteed to be the same across all groups.

    Examples

    collapse all

    Group credit data by quantile by using the groupNumberByQuantile function. In this example, you use the credit validation data set, which includes a table, ScorecardValidationData, that contains probability of default (PD) values and their corresponding default status.

    Load and display the credit validation data.

    load CreditValidationData.mat
    head(ScorecardValidationData)
        CreditScore      PD       Default
        ___________    _______    _______
    
          579.86       0.14182       0   
          563.65       0.17143       0   
          549.52       0.20106       0   
          546.25       0.20845       0   
          485.34       0.37991       0   
          482.07       0.39065       0   
          579.86       0.14182       1   
          451.73         0.494       0   
    

    Extract the variable PD from the table ScorecardValidationData and use this variable for the input argument, data.

    data = ScorecardValidationData.PD;

    Group the elements of PD by quintiles by using the groupNumberByQuantile function with the fully qualified namespace risk.validation and return the group numbers.

    QuantileType = "quintiles";
    groupNum = risk.validation.groupNumberByQuantile(data,QuantileType)
    groupNum = 360×1
    
         1
         1
         1
         1
         4
         4
         1
         5
         1
         4
         2
         3
         1
         3
         5
          ⋮
    
    

    Input Arguments

    collapse all

    Data observations, specified as a numeric vector containing values that indicate quantities such as credit scores, PD, or LGD estimates.

    Quantile type, specified as string scalar. You can choose from the following quantile types:

    • "quartiles" — Four groups

    • "quintiles" — Five groups

    • "deciles" — Ten groups

    • "demideciles" — Twenty groups

    Number of desired groups, specified as a positive numeric scalar.

    Note

    You must specify either a quantile type or a number of groups when you use groupNumberByQuantile. Although numGroups=10 is equivalent to specifying "deciles” as the quantile type, numGroups allows you to request any number of groups, whereas QuantileType supports the more common groupings.

    Output Arguments

    collapse all

    Group number for each value in data, returned as a numeric vector.

    Version History

    Introduced in R2025a