g02la fits an orthogonal scores partial least squares (PLS) regression by using singular value decomposition.

# Syntax

C#
```public static void g02la(
int n,
int mx,
double[,] x,
int[] isx,
int ip,
int my,
double[,] y,
double[] xbar,
double[] ybar,
int iscale,
double[] xstd,
double[] ystd,
int maxfac,
double[,] xres,
double[,] yres,
double[,] w,
double[,] p,
double[,] t,
double[,] c,
double[,] u,
double[] xcv,
double[,] ycv,
out int ifail
)```
Visual Basic
```Public Shared Sub g02la ( _
n As Integer, _
mx As Integer, _
x As Double(,), _
isx As Integer(), _
ip As Integer, _
my As Integer, _
y As Double(,), _
xbar As Double(), _
ybar As Double(), _
iscale As Integer, _
xstd As Double(), _
ystd As Double(), _
maxfac As Integer, _
xres As Double(,), _
yres As Double(,), _
w As Double(,), _
p As Double(,), _
t As Double(,), _
c As Double(,), _
u As Double(,), _
xcv As Double(), _
ycv As Double(,), _
<OutAttribute> ByRef ifail As Integer _
)```
Visual C++
```public:
static void g02la(
int n,
int mx,
array<double,2>^ x,
array<int>^ isx,
int ip,
int my,
array<double,2>^ y,
array<double>^ xbar,
array<double>^ ybar,
int iscale,
array<double>^ xstd,
array<double>^ ystd,
int maxfac,
array<double,2>^ xres,
array<double,2>^ yres,
array<double,2>^ w,
array<double,2>^ p,
array<double,2>^ t,
array<double,2>^ c,
array<double,2>^ u,
array<double>^ xcv,
array<double,2>^ ycv,
[OutAttribute] int% ifail
)```
F#
```static member g02la :
n : int *
mx : int *
x : float[,] *
isx : int[] *
ip : int *
my : int *
y : float[,] *
xbar : float[] *
ybar : float[] *
iscale : int *
xstd : float[] *
ystd : float[] *
maxfac : int *
xres : float[,] *
yres : float[,] *
w : float[,] *
p : float[,] *
t : float[,] *
c : float[,] *
u : float[,] *
xcv : float[] *
ycv : float[,] *
ifail : int byref -> unit
```

#### Parameters

n
Type: System..::..Int32
On entry: $n$, the number of observations.
Constraint: ${\mathbf{n}}>1$.
mx
Type: System..::..Int32
On entry: the number of predictor variables.
Constraint: ${\mathbf{mx}}>1$.
x
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, mx]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On entry: ${\mathbf{x}}\left[\mathit{i}-1,\mathit{j}-1\right]$ must contain the $\mathit{i}$th observation on the $\mathit{j}$th predictor variable, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{mx}}$.
isx
Type: array<System..::..Int32>[]()[][]
An array of size [mx]
On entry: indicates which predictor variables are to be included in the model.
${\mathbf{isx}}\left[j-1\right]=1$
The $j$th predictor variable (with variates in the $j$th column of $X$) is included in the model.
${\mathbf{isx}}\left[j-1\right]=0$
Otherwise.
Constraint: the sum of elements in isx must equal ip.
ip
Type: System..::..Int32
On entry: $m$, the number of predictor variables in the model.
Constraint: $1<{\mathbf{ip}}\le {\mathbf{mx}}$.
my
Type: System..::..Int32
On entry: $r$, the number of response variables.
Constraint: ${\mathbf{my}}\ge 1$.
y
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, my]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On entry: ${\mathbf{y}}\left[\mathit{i}-1,\mathit{j}-1\right]$ must contain the $\mathit{i}$th observation for the $\mathit{j}$th response variable, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{my}}$.
xbar
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On exit: mean values of predictor variables in the model.
ybar
Type: array<System..::..Double>[]()[][]
An array of size [my]
On exit: the mean value of each response variable.
iscale
Type: System..::..Int32
On entry: indicates how predictor variables are scaled.
${\mathbf{iscale}}=1$
Data are scaled by the standard deviation of variables.
${\mathbf{iscale}}=2$
Data are scaled by user-supplied scalings.
${\mathbf{iscale}}=-1$
No scaling.
Constraint: ${\mathbf{iscale}}=-1$, $1$ or $2$.
xstd
Type: array<System..::..Double>[]()[][]
An array of size [ip]
On entry: if ${\mathbf{iscale}}=2$, ${\mathbf{xstd}}\left[\mathit{j}-1\right]$ must contain the user-supplied scaling for the $\mathit{j}$th predictor variable in the model, for $\mathit{j}=1,2,\dots ,{\mathbf{ip}}$. Otherwise xstd need not be set.
On exit: if ${\mathbf{iscale}}=1$, standard deviations of predictor variables in the model. Otherwise xstd is not changed.
ystd
Type: array<System..::..Double>[]()[][]
An array of size [my]
On entry: if ${\mathbf{iscale}}=2$, ${\mathbf{ystd}}\left[\mathit{j}-1\right]$ must contain the user-supplied scaling for the $\mathit{j}$th response variable in the model, for $\mathit{j}=1,2,\dots ,{\mathbf{my}}$. Otherwise ystd need not be set.
On exit: if ${\mathbf{iscale}}=1$, the standard deviation of each response variable. Otherwise ystd is not changed.
maxfac
Type: System..::..Int32
On entry: $k$, the number of latent variables to calculate.
Constraint: $1\le {\mathbf{maxfac}}\le {\mathbf{ip}}$.
xres
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, ip]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On exit: the predictor variables' residual matrix ${X}_{k}$.
yres
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, my]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On exit: the residuals for each response variable, ${Y}_{k}$.
w
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, maxfac]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{ip}}$
On exit: the $\mathit{j}$th column of $W$ contains the $x$-weights ${w}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{maxfac}}$.
p
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, maxfac]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{ip}}$
On exit: the $\mathit{j}$th column of $P$ contains the $x$-loadings ${p}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{maxfac}}$.
t
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, maxfac]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On exit: the $\mathit{j}$th column of $T$ contains the $x$-scores ${t}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{maxfac}}$.
c
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, maxfac]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{my}}$
On exit: the $\mathit{j}$th column of $C$ contains the $y$-loadings ${c}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{maxfac}}$.
u
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, maxfac]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{n}}$
On exit: the $\mathit{j}$th column of $U$ contains the $y$-scores ${u}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{maxfac}}$.
xcv
Type: array<System..::..Double>[]()[][]
An array of size [maxfac]
On exit: ${\mathbf{xcv}}\left[\mathit{j}-1\right]$ contains the cumulative percentage of variance in the predictor variables explained by the first $\mathit{j}$ factors, for $\mathit{j}=1,2,\dots ,{\mathbf{maxfac}}$.
ycv
Type: array<System..::..Double,2>[,](,)[,][,]
An array of size [dim1, my]
Note: dim1 must satisfy the constraint: $\mathrm{dim1}\ge {\mathbf{maxfac}}$
On exit: ${\mathbf{ycv}}\left[\mathit{i}-1,\mathit{j}-1\right]$ is the cumulative percentage of variance of the $\mathit{j}$th response variable explained by the first $\mathit{i}$ factors, for $\mathit{i}=1,2,\dots ,{\mathbf{maxfac}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{my}}$.
ifail
Type: System..::..Int32%
On exit: ${\mathbf{ifail}}={0}$ unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).

# Description

Let ${X}_{1}$ be the mean-centred $n$ by $m$ data matrix $X$ of $n$ observations on $m$ predictor variables. Let ${Y}_{1}$ be the mean-centred $n$ by $r$ data matrix $Y$ of $n$ observations on $r$ response variables.
The first of the $k$ factors PLS methods extract from the data predicts both ${X}_{1}$ and ${Y}_{1}$ by regressing on ${t}_{1}$ a column vector of $n$ scores:
 $X^1=t1p1TY^1=t1c1T,with ​t1Tt1=1,$
where the column vectors of $m$ $x$-loadings ${p}_{1}$ and $r$ $y$-loadings ${c}_{1}$ are calculated in the least squares sense:
 $p1T=t1TX1c1T=t1TY1.$
The $x$-score vector ${t}_{1}={X}_{1}{w}_{1}$ is the linear combination of predictor data ${X}_{1}$ that has maximum covariance with the $y$-scores ${u}_{1}={Y}_{1}{c}_{1}$, where the $x$-weights vector ${w}_{1}$ is the normalised first left singular vector of ${X}_{1}^{\mathrm{T}}{Y}_{1}$.
The method extracts subsequent PLS factors by repeating the above process with the residual matrices:
 $Xi=Xi-1-X^i-1Yi=Yi-1-Y^i-1, i=2,3,…,k,$
and with orthogonal scores:
 $tiTtj=0, j=1,2,…,i-1.$
Optionally, in addition to being mean-centred, the data matrices ${X}_{1}$ and ${Y}_{1}$ may be scaled by standard deviations of the variables. If data are supplied mean-centred, the calculations are not affected within numerical accuracy.

None.

# Error Indicators and Warnings

Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface (LDX, LDY, LDXRES, LDYRES, LDW, LDP, LDT, LDC, LDU, LDYCV) In these cases, an error in another parameter has usually caused an incorrect value to be inferred.
${\mathbf{ifail}}=1$
 On entry, ${\mathbf{n}}<2$, or ${\mathbf{mx}}<2$, or an element of ${\mathbf{isx}}\ne 0$ or $1$, or ${\mathbf{my}}<1$, or ${\mathbf{iscale}}\ne -1$, $1$ or $2$.
${\mathbf{ifail}}=2$
 On entry, ${\mathbf{ip}}<2$ or ${\mathbf{ip}}>{\mathbf{mx}}$, or ${\mathbf{maxfac}}<1$ or ${\mathbf{maxfac}}>{\mathbf{ip}}$,
${\mathbf{ifail}}=3$
ip does not equal the sum of elements in isx.
${\mathbf{ifail}}=-9000$
An error occured, see message report.
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-4000$
Invalid dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-8000$
Negative dimension for array $〈\mathit{\text{value}}〉$
${\mathbf{ifail}}=-6000$
Invalid Parameters $〈\mathit{\text{value}}〉$

# Accuracy

The computed singular value decomposition is nearly the exact singular value decomposition for a nearby matrix $\left(A+E\right)$, where
 $E2=OεA2,$
and $\epsilon$ is the machine precision.

# Parallelism and Performance

None.

g02la allocates internally $2mr+A+\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(3\left(A+B\right),5A\right)+r$ elements of real storage, where $A=\mathrm{min}\phantom{\rule{0.125em}{0ex}}\left(m,r\right)$ and $B=\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(m,r\right)$.

# Example

This example reads in data from an experiment to measure the biological activity in a chemical compound, and a PLS model is estimated.

Example program (C#): g02lae.cs

Example program data: g02lae.d

Example program results: g02lae.r