# NAG Library Routine Document

## 1Purpose

g02ldf calculates predictions given the output from an orthogonal scores PLS regression (g02laf or g02lbf) and g02lcf.

## 2Specification

Fortran Interface
 Subroutine g02ldf ( ip, my, orig, xbar, ybar, xstd, ystd, b, ldb, n, mz, isz, z, ldz, yhat,
 Integer, Intent (In) :: ip, my, orig, iscale, ldb, n, mz, isz(mz), ldz, ldyhat Integer, Intent (Inout) :: ifail Real (Kind=nag_wp), Intent (In) :: xbar(ip), ybar(my), xstd(ip), ystd(my), b(ldb,my), z(ldz,mz) Real (Kind=nag_wp), Intent (Inout) :: yhat(ldyhat,my)
#include nagmk26.h
 void g02ldf_ (const Integer *ip, const Integer *my, const Integer *orig, const double xbar[], const double ybar[], const Integer *iscale, const double xstd[], const double ystd[], const double b[], const Integer *ldb, const Integer *n, const Integer *mz, const Integer isz[], const double z[], const Integer *ldz, double yhat[], const Integer *ldyhat, Integer *ifail)

## 3Description

g02ldf calculates the predictions $\stackrel{^}{Y}$ of a PLS model given a set $Z$ of test data and a set $B$ of parameter estimates as returned by g02lcf.
If g02lcf returns parameter estimates for the original data scale, no further information is required.
If g02lcf returns parameter estimates for the centred, and possibly scaled, data, further information is required. The means of variables in the fitted model must be supplied. In the case of a PLS model fitted by using scaled data, the means and standard deviations of variables in the fitted model must also be supplied. These means and standard deviations are those returned by either g02laf and g02lbf.

None.

## 5Arguments

1:     $\mathbf{ip}$ – IntegerInput
On entry: the number of predictor variables in the fitted model. ip must take the same value as that supplied to g02laf or g02lbf to fit the model.
Constraint: ${\mathbf{ip}}>1$.
2:     $\mathbf{my}$ – IntegerInput
On entry: the number of response variables in the fitted model. my must take the same value as that supplied to g02laf or g02lbf to fit the model.
Constraint: ${\mathbf{my}}\ge 1$.
3:     $\mathbf{orig}$ – IntegerInput
On entry: indicates how parameter estimates are supplied.
${\mathbf{orig}}=1$
Parameter estimates are for the original data.
${\mathbf{orig}}=-1$
Parameter estimates are for the centred, and possibly scaled, data.
Constraint: ${\mathbf{orig}}=-1$ or $1$.
4:     $\mathbf{xbar}\left({\mathbf{ip}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: if ${\mathbf{orig}}=-1$, xbar must contain mean values of predictor variables in the model; otherwise xbar is not referenced.
5:     $\mathbf{ybar}\left({\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: if ${\mathbf{orig}}=-1$, ybar must contain the mean value of each response variable in the model; otherwise ybar is not referenced.
6:     $\mathbf{iscale}$ – IntegerInput
On entry: if ${\mathbf{orig}}=-1$, iscale must take the value supplied to either g02laf or g02lbf; otherwise iscale is not referenced.
Constraint: if ${\mathbf{orig}}=-1$, ${\mathbf{iscale}}=-1$, $1$ or $2$.
7:     $\mathbf{xstd}\left({\mathbf{ip}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: if ${\mathbf{orig}}=-1$ and ${\mathbf{iscale}}\ne -1$, xstd must contain the scalings of predictor variables in the model as returned from either g02laf or g02lbf; otherwise xstd is not referenced.
8:     $\mathbf{ystd}\left({\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: if ${\mathbf{orig}}=-1$ and ${\mathbf{iscale}}\ne -1$, ystd must contain the scalings of response variables as returned from either g02laf or g02lbf; otherwise ystd is not referenced.
9:     $\mathbf{b}\left({\mathbf{ldb}},{\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: if ${\mathbf{orig}}=-1$, b must contain the parameter estimate for the centred, and possibly scaled, data as returned by g02lcf; otherwise b must contain the parameter estimates for the original data as returned by g02lcf.
10:   $\mathbf{ldb}$ – IntegerInput
On entry: the first dimension of the array b as declared in the (sub)program from which g02ldf is called. If ${\mathbf{orig}}=-1$, ldb must be at least ip; otherwise b also contains the estimate for the intercept parameter and consequently ldb must be at least $1+{\mathbf{ip}}$.
Constraints:
• if ${\mathbf{orig}}=-1$, ${\mathbf{ldb}}\ge {\mathbf{ip}}$;
• if ${\mathbf{orig}}=1$, ${\mathbf{ldb}}\ge 1+{\mathbf{ip}}$.
11:   $\mathbf{n}$ – IntegerInput
On entry: $n$, the number of observations in the test data $Z$.
Constraint: ${\mathbf{n}}\ge 1$.
12:   $\mathbf{mz}$ – IntegerInput
On entry: the number of available predictor variables in the test data.
Constraint: ${\mathbf{mz}}\ge {\mathbf{ip}}$.
13:   $\mathbf{isz}\left({\mathbf{mz}}\right)$ – Integer arrayInput
On entry: indicates which predictor variables are to be included in the model. Predictor variables included from z must be in the same order as those included in the fitted model.
If ${\mathbf{isz}}\left(\mathit{j}\right)=1$, the $\mathit{j}$th predictor variable is included in the model, for $\mathit{j}=1,2,\dots ,{\mathbf{mz}}$, otherwise ${\mathbf{isz}}\left(j\right)=0$.
Constraints:
• ${\mathbf{isz}}\left(\mathit{j}\right)=0\text{​ or ​}1$, for $\mathit{j}=1,2,\dots ,{\mathbf{mz}}$;
• ${\sum }_{j}{\mathbf{isz}}\left(j\right)={\mathbf{ip}}$.
14:   $\mathbf{z}\left({\mathbf{ldz}},{\mathbf{mz}}\right)$ – Real (Kind=nag_wp) arrayInput
On entry: ${\mathbf{z}}\left(\mathit{i},\mathit{j}\right)$ contains the $\mathit{i}$th observation on the $\mathit{j}$th available predictor variable, for $\mathit{i}=1,2,\dots ,{\mathbf{n}}$ and $\mathit{j}=1,2,\dots ,{\mathbf{mz}}$.
15:   $\mathbf{ldz}$ – IntegerInput
On entry: the first dimension of the array z as declared in the (sub)program from which g02ldf is called.
Constraint: ${\mathbf{ldz}}\ge {\mathbf{n}}$.
16:   $\mathbf{yhat}\left({\mathbf{ldyhat}},{\mathbf{my}}\right)$ – Real (Kind=nag_wp) arrayOutput
On exit: ${\mathbf{yhat}}\left(i,j\right)$ contains the $i$th predicted value of the $j$th $y$-variable in the model.
17:   $\mathbf{ldyhat}$ – IntegerInput
On entry: the first dimension of the array yhat as declared in the (sub)program from which g02ldf is called.
Constraint: ${\mathbf{ldyhat}}\ge {\mathbf{n}}$.
18:   $\mathbf{ifail}$ – IntegerInput/Output
On entry: ifail must be set to $0$, $-1\text{​ or ​}1$. If you are unfamiliar with this argument you should refer to Section 3.4 in How to Use the NAG Library and its Documentation 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 argument, 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).

## 6Error Indicators and Warnings

If on entry ${\mathbf{ifail}}=0$ or $-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{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ip}}>1$.
On entry, ${\mathbf{iscale}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{orig}}=-1$, ${\mathbf{iscale}}=-1$, $1$ or $2$.
On entry, ${\mathbf{isz}}\left(j\right)=〈\mathit{\text{value}}〉$, $j=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{isz}}\left(j\right)=0\text{​ or ​}1$.
On entry, ${\mathbf{my}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{my}}\ge 1$.
On entry, ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{n}}\ge 1$.
On entry, ${\mathbf{orig}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{orig}}=-1$ or $1$.
${\mathbf{ifail}}=2$
On entry, ${\mathbf{ldb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{orig}}=-1$, ${\mathbf{ldb}}\ge {\mathbf{ip}}$.
On entry, ${\mathbf{ldb}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ip}}+1=〈\mathit{\text{value}}〉$.
Constraint: if ${\mathbf{orig}}=1$, ${\mathbf{ldb}}\ge 1+{\mathbf{ip}}$.
On entry, ${\mathbf{ldyhat}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldyhat}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{ldz}}=〈\mathit{\text{value}}〉$ and ${\mathbf{n}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{ldz}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{mz}}=〈\mathit{\text{value}}〉$ and ${\mathbf{ip}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{mz}}\ge {\mathbf{ip}}$.
${\mathbf{ifail}}=3$
On entry, the number of elements of isz equal to $1$ is not ip.
${\mathbf{ifail}}=-99$
See Section 3.9 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
See Section 3.8 in How to Use the NAG Library and its Documentation for further information.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.
See Section 3.7 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

## 8Parallelism and Performance

g02ldf makes calls to BLAS and/or LAPACK routines, which may be threaded within the vendor library used by this implementation. Consult the documentation for the vendor library for further information.
Please consult the X06 Chapter Introduction for information on how to control and interrogate the OpenMP environment used within this routine. Please also consult the Users' Note for your implementation for any additional implementation-specific information.

g02ldf allocates internally $3×{\mathbf{ip}}+{\mathbf{my}}$ elements of real storage.

## 10Example

This example reads in parameter estimates for a fitted PLS model and prediction data, and the PLS model predictions are calculated.

### 10.1Program Text

Program Text (g02ldfe.f90)

### 10.2Program Data

Program Data (g02ldfe.d)

### 10.3Program Results

Program Results (g02ldfe.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017