G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02LAF

Note:  before using this routine, please read the Users' Note for your implementation to check the interpretation of bold italicised terms and other implementation-dependent details.

## 1  Purpose

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

## 2  Specification

 SUBROUTINE G02LAF ( N, MX, X, LDX, ISX, IP, MY, Y, LDY, XBAR, YBAR, ISCALE, XSTD, YSTD, MAXFAC, XRES, LDXRES, YRES, LDYRES, W, LDW, P, LDP, T, LDT, C, LDC, U, LDU, XCV, YCV, LDYCV, IFAIL)
 INTEGER N, MX, LDX, ISX(MX), IP, MY, LDY, ISCALE, MAXFAC, LDXRES, LDYRES, LDW, LDP, LDT, LDC, LDU, LDYCV, IFAIL REAL (KIND=nag_wp) X(LDX,MX), Y(LDY,MY), XBAR(IP), YBAR(MY), XSTD(IP), YSTD(MY), XRES(LDXRES,IP), YRES(LDYRES,MY), W(LDW,MAXFAC), P(LDP,MAXFAC), T(LDT,MAXFAC), C(LDC,MAXFAC), U(LDU,MAXFAC), XCV(MAXFAC), YCV(LDYCV,MY)

## 3  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 = t1 p1T Y^1 = t1 c1T , with ​ t1T t1 = 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 = t1T X1 c1T = t1T Y1 .$
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-1 Yi = Yi-1 - Y^ i-1 , i=2,3,…,k ,$
and with orthogonal scores:
 $tiT tj = 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.

## 5  Parameters

1:     N – INTEGERInput
On entry: $n$, the number of observations.
Constraint: ${\mathbf{N}}>1$.
2:     MX – INTEGERInput
On entry: the number of predictor variables.
Constraint: ${\mathbf{MX}}>1$.
3:     X(LDX,MX) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{X}}\left(\mathit{i},\mathit{j}\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}}$.
4:     LDX – INTEGERInput
On entry: the first dimension of the array X as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDX}}\ge {\mathbf{N}}$.
5:     ISX(MX) – INTEGER arrayInput
On entry: indicates which predictor variables are to be included in the model.
${\mathbf{ISX}}\left(j\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\right)=0$
Otherwise.
Constraint: the sum of elements in ISX must equal IP.
6:     IP – INTEGERInput
On entry: $m$, the number of predictor variables in the model.
Constraint: $1<{\mathbf{IP}}\le {\mathbf{MX}}$.
7:     MY – INTEGERInput
On entry: $r$, the number of response variables.
Constraint: ${\mathbf{MY}}\ge 1$.
8:     Y(LDY,MY) – REAL (KIND=nag_wp) arrayInput
On entry: ${\mathbf{Y}}\left(\mathit{i},\mathit{j}\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}}$.
9:     LDY – INTEGERInput
On entry: the first dimension of the array Y as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDY}}\ge {\mathbf{N}}$.
10:   XBAR(IP) – REAL (KIND=nag_wp) arrayOutput
On exit: mean values of predictor variables in the model.
11:   YBAR(MY) – REAL (KIND=nag_wp) arrayOutput
On exit: the mean value of each response variable.
12:   ISCALE – INTEGERInput
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$.
13:   XSTD(IP) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if ${\mathbf{ISCALE}}=2$, ${\mathbf{XSTD}}\left(\mathit{j}\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.
14:   YSTD(MY) – REAL (KIND=nag_wp) arrayInput/Output
On entry: if ${\mathbf{ISCALE}}=2$, ${\mathbf{YSTD}}\left(\mathit{j}\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.
15:   MAXFAC – INTEGERInput
On entry: $k$, the number of latent variables to calculate.
Constraint: $1\le {\mathbf{MAXFAC}}\le {\mathbf{IP}}$.
16:   XRES(LDXRES,IP) – REAL (KIND=nag_wp) arrayOutput
On exit: the predictor variables' residual matrix ${X}_{k}$.
17:   LDXRES – INTEGERInput
On entry: the first dimension of the array XRES as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDXRES}}\ge {\mathbf{N}}$.
18:   YRES(LDYRES,MY) – REAL (KIND=nag_wp) arrayOutput
On exit: the residuals for each response variable, ${Y}_{k}$.
19:   LDYRES – INTEGERInput
On entry: the first dimension of the array YRES as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDYRES}}\ge {\mathbf{N}}$.
20:   W(LDW,MAXFAC) – REAL (KIND=nag_wp) arrayOutput
On exit: the $\mathit{j}$th column of $W$ contains the $x$-weights ${w}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{MAXFAC}}$.
21:   LDW – INTEGERInput
On entry: the first dimension of the array W as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDW}}\ge {\mathbf{IP}}$.
22:   P(LDP,MAXFAC) – REAL (KIND=nag_wp) arrayOutput
On exit: the $\mathit{j}$th column of $P$ contains the $x$-loadings ${p}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{MAXFAC}}$.
23:   LDP – INTEGERInput
On entry: the first dimension of the array P as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDP}}\ge {\mathbf{IP}}$.
24:   T(LDT,MAXFAC) – REAL (KIND=nag_wp) arrayOutput
On exit: the $\mathit{j}$th column of $T$ contains the $x$-scores ${t}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{MAXFAC}}$.
25:   LDT – INTEGERInput
On entry: the first dimension of the array T as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDT}}\ge {\mathbf{N}}$.
26:   C(LDC,MAXFAC) – REAL (KIND=nag_wp) arrayOutput
On exit: the $\mathit{j}$th column of $C$ contains the $y$-loadings ${c}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{MAXFAC}}$.
27:   LDC – INTEGERInput
On entry: the first dimension of the array C as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDC}}\ge {\mathbf{MY}}$.
28:   U(LDU,MAXFAC) – REAL (KIND=nag_wp) arrayOutput
On exit: the $\mathit{j}$th column of $U$ contains the $y$-scores ${u}_{\mathit{j}}$, for $\mathit{j}=1,2,\dots ,{\mathbf{MAXFAC}}$.
29:   LDU – INTEGERInput
On entry: the first dimension of the array U as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDU}}\ge {\mathbf{N}}$.
30:   XCV(MAXFAC) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{XCV}}\left(\mathit{j}\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}}$.
31:   YCV(LDYCV,MY) – REAL (KIND=nag_wp) arrayOutput
On exit: ${\mathbf{YCV}}\left(\mathit{i},\mathit{j}\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}}$.
32:   LDYCV – INTEGERInput
On entry: the first dimension of the array YCV as declared in the (sub)program from which G02LAF is called.
Constraint: ${\mathbf{LDYCV}}\ge {\mathbf{MAXFAC}}$.
33:   IFAIL – INTEGERInput/Output
On entry: IFAIL must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this parameter you should refer to Section 3.3 in the Essential Introduction for details.
For environments where it might be inappropriate to halt program execution when an error is detected, the value $-1\text{​ or ​}1$ is recommended. If the output of error messages is undesirable, then the value $1$ is recommended. Otherwise, if you are not familiar with this parameter, the recommended value is $0$. When the value $-\mathbf{1}\text{​ or ​}\mathbf{1}$ is used it is essential to test the value of IFAIL on exit.
On exit: ${\mathbf{IFAIL}}={\mathbf{0}}$ unless the routine detects an error or a warning has been flagged (see Section 6).

## 6  Error Indicators and Warnings

If on entry ${\mathbf{IFAIL}}={\mathbf{0}}$ or $-{\mathbf{1}}$, explanatory error messages are output on the current error message unit (as defined by X04AAF).
Errors or warnings detected by the routine:
${\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{LDX}}<{\mathbf{N}}$, or ${\mathbf{IP}}<2$ or ${\mathbf{IP}}>{\mathbf{MX}}$, or ${\mathbf{LDY}}<{\mathbf{N}}$, or ${\mathbf{MAXFAC}}<1$ or ${\mathbf{MAXFAC}}>{\mathbf{IP}}$, or ${\mathbf{LDXRES}}<{\mathbf{N}}$, or ${\mathbf{LDYRES}}<{\mathbf{N}}$, or ${\mathbf{LDW}}<{\mathbf{IP}}$, or ${\mathbf{LDP}}<{\mathbf{IP}}$, or ${\mathbf{LDC}}<{\mathbf{MY}}$, or ${\mathbf{LDT}}<{\mathbf{N}}$, or ${\mathbf{LDU}}<{\mathbf{N}}$, or ${\mathbf{LDYCV}}<{\mathbf{MAXFAC}}$.
${\mathbf{IFAIL}}=3$
IP does not equal the sum of elements in ISX.

## 7  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.

G02LAF 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)$.

## 9  Example

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

### 9.1  Program Text

Program Text (g02lafe.f90)

### 9.2  Program Data

Program Data (g02lafe.d)

### 9.3  Program Results

Program Results (g02lafe.r)