G02 Chapter Contents
G02 Chapter Introduction
NAG Library Manual

# NAG Library Routine DocumentG02LDF

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

G02LDF calculates predictions given the output from an orthogonal scores PLS regression (G02LAF or G02LBF) and G02LCF.

## 2  Specification

 SUBROUTINE G02LDF ( IP, MY, ORIG, XBAR, YBAR, ISCALE, XSTD, YSTD, B, LDB, N, MZ, ISZ, Z, LDZ, YHAT, LDYHAT, IFAIL)
 INTEGER IP, MY, ORIG, ISCALE, LDB, N, MZ, ISZ(MZ), LDZ, LDYHAT, IFAIL REAL (KIND=nag_wp) XBAR(IP), YBAR(MY), XSTD(IP), YSTD(MY), B(LDB,MY), Z(LDZ,MZ), YHAT(LDYHAT,MY)

## 3  Description

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.

## 5  Parameters

1:     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:     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:     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:     XBAR(IP) – 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:     YBAR(MY) – 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:     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:     XSTD(IP) – 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:     YSTD(MY) – 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:     B(LDB,MY) – 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:   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:   N – INTEGERInput
On entry: $n$, the number of observations in the test data $Z$.
Constraint: ${\mathbf{N}}\ge 1$.
12:   MZ – INTEGERInput
On entry: the number of available predictor variables in the test data.
Constraint: ${\mathbf{MZ}}\ge {\mathbf{IP}}$.
13:   ISZ(MZ) – 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:   Z(LDZ,MZ) – 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:   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:   YHAT(LDYHAT,MY) – 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:   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:   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{IP}}\le 1$, or ${\mathbf{MY}}<1$, or ${\mathbf{ORIG}}\ne -1$ or $1$, or ${\mathbf{ORIG}}=-1$ and ${\mathbf{ISCALE}}\ne -1$, $1$ or $2$, or ${\mathbf{N}}<1$, or an element of ${\mathbf{ISZ}}\ne 0$ or $1$.
${\mathbf{IFAIL}}=2$
 On entry, ${\mathbf{ORIG}}=-1$ and ${\mathbf{LDB}}<{\mathbf{IP}}$, or ${\mathbf{ORIG}}=1$ and ${\mathbf{LDB}}<1+{\mathbf{IP}}$, or ${\mathbf{MZ}}<{\mathbf{IP}}$, or ${\mathbf{LDZ}}<{\mathbf{N}}$, or ${\mathbf{LDYHAT}}<{\mathbf{N}}$.
${\mathbf{IFAIL}}=3$
The sum of elements in ISZ does not equal IP.

## 7  Accuracy

Not applicable.

G02LDF allocates internally $3×{\mathbf{IP}}+{\mathbf{MY}}$ elements of real storage.

## 9  Example

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

### 9.1  Program Text

Program Text (g02ldfe.f90)

### 9.2  Program Data

Program Data (g02ldfe.d)

### 9.3  Program Results

Program Results (g02ldfe.r)