The SDL Component Suite is an industry leading collection of components supporting scientific and engineering computing. Please visit the SDL Web site for more information....



How to use TMLRModel


The class TMLRModel implements multiple linear regression (MLR) technique and supports multilinear regression (MLR), linear discriminant analysis (LDA) and ridge regression (RR). The distinction between these methods is controled by the property ModelType.

In order to create and use the regression model you have first to load the training data into the array properties XData and YData. By default, XData and YData are 1x1-matrices which have to be resized before loading the data. The matrix XData contains the independent variables ("descriptors"), with the rows being the objects and the columns being the variables. The response variables have to be loaded into the vector YData. There are a few additional parameters which you have to set as well: ForceZeroIcpt controls the inclusion of an intercept, the property LDAThreshold has to specify the classifier threshold for LDA models, and the property Lambda controls the regularization of ridge regression models.

After setting up the model parameters and loading the data into XData and YData, the model can be calculated by calling the method CalculateModel. This will fill in the regression coefficients (property RegCoeffs) as well a bunch of other matrices which contain additional information on the particular model:

tStat the t statistics of the regression coefficents
pValue the p values of the regression coefficents
FStat the F statistic for the global hypothesis
FitR2 the goodness of fit
StdDevRes the standard deviation of the residuals
Residuals the residuals
GetAnovaPars all kind of parameters obtained by the ANOVA of the results
CooksD Cook's distance indicating outliers

If you establish an LDA model (ModelType = rmLDA) a few additional parameters are calculated which specify the quality of the LDA classifier:

LDAV1, LDAV2 the two dichotomous values found in YData
BestROC the optimimum threshold based on the ROC curve
ROCThresh the associated thresholds of the ROC curve
ROCFPRate, ROCTPRate the false positive and true positive rates of the classifier

If the model has been computed successfully, you can use it to predict response values of unknown samples by calling the method ApplyModel. A calculated model can be stored on disk by the method StoreModel and loaded from disk by LoadModel.

Following is a sample code torso showing the principal usage of the MLR model (it is assumed that the number of objects and the number of independent variables are contained in the variables no_of_objects and no_of_input_vars, respectively):

var
  MLRMod : TMLRModel;

   ...
   ...
MLRMod := TMLRModel.Create(nil);       // create the MLR model instance
MLRMod.ModelType := rmMLR;             // plain multilinear regression
MLRMod.ForceZeroIcpt := false;         // including the intercept
                                       // resize the data matrices
MLRMod.XData.Resize(no_of_input_vars, no_of_objects);
MLRMod.YData.NrOfElem := no_of_objects;
for iy:=1 to no_of_objects do
  begin
  for ix:=1 to no_of_input_vars do
    MLRMod.XData[ix,iy] := ...         // copy the independent data
  MLRMod.YData[ix] := ...              // copy the response data
  end;

MLRMod.CalculateModel;                 // now calculate the model

// at this point apply the model or otherwise process  the results

MLRMod.Free;                           // finally free up the memory
   ...
   ...
Alternatively, the TMLRModel component could be taken from the component palette and put on a form. In this case the Create and Free method must not be called (they are called automatically when the form is created or destroyed).


Last Update: 2023-Dec-05