**12.2****
****Error Checking** (.NET, C#, CSharp, VB, Visual Basic, F#)

After computing a PLS regression, always check the IsGood property to ensure that there were no errors in performing the calculation. If IsGood returns the false, the Message property will contain a message indicating the nature of the error. For example, the following code checks that the calculation succeeded, and if not, prints out the error message and returns:

Code Example – C# partial least squares (PLS)

if (pls.IsGood) { Console.WriteLine("Success"); } else { Console.WriteLine("PLS calculation failed: " + pls.Message); return; }

One common source of calculation failure occurs when
the number of components specified for the calculation is greater than
the rank of *X*, the matrix of predictor
variables. If this occurs, try decreasing the number of components for
the regression until the calculation succeeds. You can also use Cross
Validation (Section 12.6) to determine the optimal number
of components.

If the calculation fails due to the non-convergence of the Iterative Power Method for computing dominant eigenvectors, you may want to adjust the maximum number of iterations and/or the tolerance for this method (Section 12.5).