Main Content


Create specified LGD model object type



lgdModel = fitLGDModel(data,ModelType) creates a loss given default (LGD) model object specified by data and ModelType. fitLGDModel takes in credit data in table form and fits a LGD model. ModelType is supported for Regression or Tobit.


lgdModel = fitLGDModel(___,Name,Value) specifies options using one or more name-value pair arguments in addition to the input arguments in the previous syntax. The available optional name-value pair arguments depend on the specified ModelType.


collapse all

This example shows how to use fitLGDModel to create a Regression model for loss given default (LGD).

Load LGD Data

Load the LGD data.

load LGDData.mat
ans=8×4 table
      LTV        Age         Type           LGD   
    _______    _______    ___________    _________

    0.89101    0.39716    residential     0.032659
    0.70176     2.0939    residential      0.43564
    0.72078     2.7948    residential    0.0064766
    0.37013      1.237    residential     0.007947
    0.36492     2.5818    residential            0
      0.796     1.5957    residential      0.14572
    0.60203     1.1599    residential     0.025688
    0.92005    0.50253    investment      0.063182

Create Regression LGD Model

Use fitLGDModel to create a Regression model using the data.

lgdModel = fitLGDModel(data,'regression',...
        'Description','Example LGD regression model.',...
        'PredictorVars',{'LTV' 'Age' 'Type'},...
  Regression with properties:

    ResponseTransform: "logit"
    BoundaryTolerance: 1.0000e-05
              ModelID: "Example"
          Description: "Example LGD regression model."
      UnderlyingModel: [1x1 classreg.regr.CompactLinearModel]
        PredictorVars: ["LTV"    "Age"    "Type"]
          ResponseVar: "LGD"

Display the underlying model. The underlying model's response variable is the logit transformation of the LGD response data. Use the 'ResponseTransform' and 'BoundaryTolerance' arguments to modify the transformation.

Compact linear regression model:
    LGD_logit ~ 1 + LTV + Age + Type

Estimated Coefficients:
                       Estimate       SE        tStat       pValue  
                       ________    ________    _______    __________

    (Intercept)        -5.1939      0.28351     -18.32     1.203e-71
    LTV                 3.3217      0.33058     10.048    1.9484e-23
    Age                -1.4953     0.068658    -21.779    1.0596e-98
    Type_investment     1.3813      0.19406     7.1178    1.3259e-12

Number of observations: 3487, Error degrees of freedom: 3483
Root Mean Squared Error: 4.3
R-squared: 0.195,  Adjusted R-Squared: 0.194
F-statistic vs. constant model: 281, p-value = 2.32e-163

Predict LGD

For LGD prediction, the LGD model applies the inverse transformation so the predictions are in the LGD scale, not in the transformed scale used to fit the underlying model.

predictedLGD = predict(lgdModel,data);
title('Predicted LGD Histogram')
xlabel('Predicted LGD')

Figure contains an axes. The axes with title Predicted LGD Histogram contains an object of type histogram.

Validate LGD Model

For model validation, use modelDiscrimination, modelDiscriminationPlot, modelAccuracy, and modelAccuracyPlot.

For example, use modelDiscriminationPlot to plot the ROC curve.


Figure contains an axes. The axes with title ROC Example, AUROC = 0.68987 contains an object of type line. This object represents Example.

Use modelAccuracyPlot to show a scatter plot of the predictions.


Figure contains an axes. The axes with title Scatter Example, R-Squared: 0.063213 contains 2 objects of type scatter, line. These objects represent Data, Fit.

Input Arguments

collapse all

Data for loss given default, specified as a table.

Data Types: table

Type of PD model, specified as a scalar string or character vector. Use one of following values:

  • Regression — Transform the LGD response variable and fit a linear regression model.

  • Tobit — Fit a Tobit regression model.

Data Types: string | char

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: lgdModel = fitLGDModel(data,'regression','PredictorVars',{'LTV' 'Age','Type'},'ResponseVar','LGD','ResponseTransform','probit','BoundaryTolerance',1e-6)

The available name-value pair arguments depend on the value you specify for ModelType.

Name-Value Pair Arguments for Model Objects

Output Arguments

collapse all

Loss given default model, returned as an lgdModel object. Supported classes are Regression and Tobit.


[1] Baesens, Bart, Daniel Roesch, and Harald Scheule. Credit Risk Analytics: Measurement Techniques, Applications, and Examples in SAS. Wiley, 2016.

[2] Bellini, Tiziano. IFRS 9 and CECL Credit Risk Modelling and Validation: A Practical Guide with Examples Worked in R and SAS. San Diego, CA: Elsevier, 2019.

Introduced in R2021a