**48.1****
****Computing a PLS Regression** (.NET, C#, CSharp, VB, Visual Basic, F#)

NMath Stats provides two classes for performing partial
least squares (PLS) regression, **PLS1**
and **PLS2**:

● **PLS1** is used when the responses, *Y*, in the model *Y=XB+E*
consist of a single variable. In this case *Y*
is a vector containing the *n* response
values.

● **PLS2** is used when the responses are multivariate.
In this case *Y* is a matrix composed
of *n* rows with each row containing
the *m* response variable values.

Computing a PLS regression is accomplished by simply
constructing a **PLS1** or **PLS2** instance. The basic parameters are:

● the matrix of predictor variables values

● the response
variable values (a vector for **PLS1**
and a matrix for **PLS2**)

● an integer specifying the number of factors or components

For example:

Code Example – C# partial least squares (PLS)

DoubleMatrix A = ...

DoubleVector y = = ...

int numComponents = 3;

var pls = new PLS1( A, y, numComponents );

Code Example – VB partial least squares (PLS)

Dim A As DoubleMatrix = ...

Dim Y As DoubleVector = ...

Dim NumComponents As Integer = 3

Dim PLS As New PLS1(A, Y, NumComponents)

You can also invoke the Calculate()
function on **PLS1** or **PLS2** to calculate a regression on an
existing instance:

Code Example – C# partial least squares (PLS)

pls.Calculate( A, y, numComponents );

Code Example – VB partial least squares (PLS)

PLS.Calculate(A, Y, NumComponents)