主要内容

risk.validation.somersD

Compute Somers' D value

Since R2026a

    Description

    somersDValue = risk.validation.somersD(X,Y) calculates the Somers' D value for pairs (xi,yi), where xi and yi are the ith elements of X and Y, respectively.

    [somersDValue,Output] = risk.validation.somersD(X,Y) also returns a structure Output that contains summary metrics.

    example

    Examples

    collapse all

    Load the loss given default (LGD) data, which contains the expected and realized LGD grades for 200 defaulted customers, as well as the year the recovery process was closed.

    lgdData = readtable("LGDRatingGradeData.csv")
    lgdData=200×5 table
        ExpectedLGD    ExpectedLGDGrade    RealizedLGD    RealizedLGDGrade    RecoveryClosedYear
        ___________    ________________    ___________    ________________    __________________
    
          0.21067              4             0.11221              3                  2023       
          0.68432              8             0.90534             11                  2023       
           0.4815              6             0.35169              5                  2023       
          0.86389             10             0.91321             11                  2023       
          0.85797             10             0.84803             10                  2023       
          0.29985              4             0.24432              4                  2023       
          0.30411              5                   0              1                  2023       
          0.88206             10             0.65058              8                  2023       
            1.054             12             0.73065              9                  2023       
          0.96353             11             0.61439              8                  2023       
           0.3936              5            0.061432              2                  2023       
          0.55109              7             0.59951              7                  2023       
          0.75181              9             0.55973              7                  2023       
          0.78397              9             0.68201              8                  2023       
          0.40728              6             0.27822              4                  2023       
          0.61732              8             0.38996              5                  2023       
          ⋮
    
    

    The ExpectedLGD and RealizedLGD table variables contain values from 1 to 12, which correspond to 12 rating grades. The values in ExpectedLGDGrade were calculated based on the borrower's characteristics before the default event and are predictions for the rating grade at the end of the recovery period. RealizedLGDGrade contains the actual grades of the portfolios at the end of the observation period.

    Calculate the Somers' D value for the grades.

    [somersDValue,Output] = risk.validation.somersD(lgdData.ExpectedLGDGrade,lgdData.RealizedLGDGrade)
    somersDValue = 
    0.5857
    
    Output = struct with fields:
                  SomersD: 0.5857
          StandardErrorCI: 0.0418
        StandardErrorNull: 0.0431
                   PValue: 5.4755e-42
    
    

    The output includes the Somers' D value, which indicates that an association exists between the expected and realized grades. This result is consistent with the small p-value for the hypothesis test with the null hypothesis that no association exists between the expected and realized grades.

    Input Arguments

    collapse all

    First random variable, specified as a numeric or logical vector. X and Y must be the same size.

    Example: X=randi(2,100,1)-1

    Data Types: single | double | logical

    Second random variable, specified as a numeric or logical vector. Y and X must be the same size.

    Example: Y=binornd(5,0.25,100,1)

    Data Types: single | double | logical

    Output Arguments

    collapse all

    Somers' D value, returned as a scalar between -1 and 1. A value of -1 indicates that all pairs disagree and a value of 1 indicates that all pairs agree.

    Output metrics, returned as a structure with the following fields:

    • SomersD — Somers' D estimate, returned as a numeric scalar. This field represents the same value as SomersDValue.

    • StandardErrorCI — Asymptotic standard error for the Somers' D estimator, returned as a numeric scalar.

    • StandardErrorNull — Asymptotic standard error for the hypothesis test that no association exists between X and Y, returned as a numeric scalar. The somersD function uses StandardErrorNull to calculate the p-value for the test.

    • pValuep-value for the hypothesis test, returned as a numeric scalar.

    For more information about the Somers' D metric and its corresponding statistics, see More About.

    More About

    collapse all

    References

    [1] Basel Committee on Banking Supervision, “Studies on the Validation of the Internal Rating Systems.” May, 2005. https://www.bis.org/publ/bcbs_wp14.htm.

    [2] European Central Bank, “Instructions for reporting the validation results of internal models.” February, 2019. https://www.bankingsupervision.europa.eu/activities/internal_models/shared/pdf/instructions_validation_reporting_credit_risk.en.pdf.

    [3] Göktas, A., & Isçi, Ö. (2011). "A comparison of the most commonly used measures of association for doubly ordered square contingency tables via simulation." Metodoloski Zvezki, 8(1), 17–37.

    [4] Baesens, Bart, et al. "Credit Risk Analytics: Measurement Techniques, Applications, and Examples in SAS. 1st ed." Wiley, 2016.

    Version History

    Introduced in R2026a