Integer type:  int32  int64  nag_int  show int32  show int32  show int64  show int64  show nag_int  show nag_int

Chapter Contents
Chapter Introduction
NAG Toolbox

# NAG Toolbox: nag_correg_pls_pred (g02ld)

## Purpose

nag_correg_pls_pred (g02ld) calculates predictions given the output from an orthogonal scores PLS regression (nag_correg_pls_svd (g02la) or nag_correg_pls_wold (g02lb)) and nag_correg_pls_fit (g02lc).

## Syntax

[yhat, ifail] = g02ld(orig, xbar, ybar, iscale, xstd, ystd, b, isz, z, 'ip', ip, 'my', my, 'n', n, 'mz', mz)
[yhat, ifail] = nag_correg_pls_pred(orig, xbar, ybar, iscale, xstd, ystd, b, isz, z, 'ip', ip, 'my', my, 'n', n, 'mz', mz)

## Description

nag_correg_pls_pred (g02ld) 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 nag_correg_pls_fit (g02lc).
If nag_correg_pls_fit (g02lc) returns parameter estimates for the original data scale, no further information is required.
If nag_correg_pls_fit (g02lc) 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 nag_correg_pls_svd (g02la) and nag_correg_pls_wold (g02lb).

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{orig}$int64int32nag_int scalar
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$.
2:     $\mathrm{xbar}\left({\mathbf{ip}}\right)$ – double array
If ${\mathbf{orig}}=-1$, xbar must contain mean values of predictor variables in the model; otherwise xbar is not referenced.
3:     $\mathrm{ybar}\left({\mathbf{my}}\right)$ – double array
If ${\mathbf{orig}}=-1$, ybar must contain the mean value of each response variable in the model; otherwise ybar is not referenced.
4:     $\mathrm{iscale}$int64int32nag_int scalar
If ${\mathbf{orig}}=-1$, iscale must take the value supplied to either nag_correg_pls_svd (g02la) or nag_correg_pls_wold (g02lb); otherwise iscale is not referenced.
Constraint: if ${\mathbf{orig}}=-1$, ${\mathbf{iscale}}=-1$, $1$ or $2$.
5:     $\mathrm{xstd}\left({\mathbf{ip}}\right)$ – double array
If ${\mathbf{orig}}=-1$ and ${\mathbf{iscale}}\ne -1$, xstd must contain the scalings of predictor variables in the model as returned from either nag_correg_pls_svd (g02la) or nag_correg_pls_wold (g02lb); otherwise xstd is not referenced.
6:     $\mathrm{ystd}\left({\mathbf{my}}\right)$ – double array
If ${\mathbf{orig}}=-1$ and ${\mathbf{iscale}}\ne -1$, ystd must contain the scalings of response variables as returned from either nag_correg_pls_svd (g02la) or nag_correg_pls_wold (g02lb); otherwise ystd is not referenced.
7:     $\mathrm{b}\left(\mathit{ldb},{\mathbf{my}}\right)$ – double array
ldb, the first dimension of the array, must satisfy the constraint
• if ${\mathbf{orig}}=-1$, $\mathit{ldb}\ge {\mathbf{ip}}$;
• if ${\mathbf{orig}}=1$, $\mathit{ldb}\ge 1+{\mathbf{ip}}$.
If ${\mathbf{orig}}=-1$, b must contain the parameter estimate for the centred, and possibly scaled, data as returned by nag_correg_pls_fit (g02lc); otherwise b must contain the parameter estimates for the original data as returned by nag_correg_pls_fit (g02lc).
8:     $\mathrm{isz}\left({\mathbf{mz}}\right)$int64int32nag_int array
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}}$.
9:     $\mathrm{z}\left(\mathit{ldz},{\mathbf{mz}}\right)$ – double array
ldz, the first dimension of the array, must satisfy the constraint $\mathit{ldz}\ge {\mathbf{n}}$.
${\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}}$.

### Optional Input Parameters

1:     $\mathrm{ip}$int64int32nag_int scalar
Default: the dimension of the arrays xbar, xstd. (An error is raised if these dimensions are not equal.)
The number of predictor variables in the fitted model. ip must take the same value as that supplied to nag_correg_pls_svd (g02la) or nag_correg_pls_wold (g02lb) to fit the model.
Constraint: ${\mathbf{ip}}>1$.
2:     $\mathrm{my}$int64int32nag_int scalar
Default: the dimension of the arrays ybar, ystd and the second dimension of the array b. (An error is raised if these dimensions are not equal.)
The number of response variables in the fitted model. my must take the same value as that supplied to nag_correg_pls_svd (g02la) or nag_correg_pls_wold (g02lb) to fit the model.
Constraint: ${\mathbf{my}}\ge 1$.
3:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array z.
$n$, the number of observations in the test data $Z$.
Constraint: ${\mathbf{n}}\ge 1$.
4:     $\mathrm{mz}$int64int32nag_int scalar
Default: the dimension of the array isz and the second dimension of the array z. (An error is raised if these dimensions are not equal.)
The number of available predictor variables in the test data.
Constraint: ${\mathbf{mz}}\ge {\mathbf{ip}}$.

### Output Parameters

1:     $\mathrm{yhat}\left(\mathit{ldyhat},{\mathbf{my}}\right)$ – double array
${\mathbf{yhat}}\left(i,j\right)$ contains the $i$th predicted value of the $j$th $y$-variable in the model.
2:     $\mathrm{ifail}$int64int32nag_int scalar
${\mathbf{ifail}}={\mathbf{0}}$ unless the function detects an error (see Error Indicators and Warnings).

## Error Indicators and Warnings

Errors or warnings detected by the function:
${\mathbf{ifail}}=1$
Constraint: if ${\mathbf{orig}}=-1$, ${\mathbf{iscale}}=-1$, $1$ or $2$.
Constraint: ${\mathbf{ip}}>1$.
Constraint: ${\mathbf{isz}}\left(j\right)=0\text{​ or ​}1$.
Constraint: ${\mathbf{my}}\ge 1$.
Constraint: ${\mathbf{n}}\ge 1$.
Constraint: ${\mathbf{orig}}=-1$ or $1$.
${\mathbf{ifail}}=2$
Constraint: if ${\mathbf{orig}}=1$, $\mathit{ldb}\ge 1+{\mathbf{ip}}$.
Constraint: if ${\mathbf{orig}}=-1$, $\mathit{ldb}\ge {\mathbf{ip}}$.
Constraint: $\mathit{ldyhat}\ge {\mathbf{n}}$.
Constraint: $\mathit{ldz}\ge {\mathbf{n}}$.
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$
${\mathbf{ifail}}=-399$
Your licence key may have expired or may not have been installed correctly.
${\mathbf{ifail}}=-999$
Dynamic memory allocation failed.

## Accuracy

Not applicable.

nag_correg_pls_pred (g02ld) allocates internally $3×{\mathbf{ip}}+{\mathbf{my}}$ elements of double storage.

## Example

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

fprintf('g02ld example results\n\n');

n = 15;
z = zeros(n,n);
z(:,1:8) = ...
[-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701,  1.9607, -1.6324;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701,  1.9607, -1.6324;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701,  0.0744, -1.7333;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701,  0.0744, -1.7333;
-2.6931, -2.5271, -1.2871, 2.8369,  1.4092, -3.1398,  0.0744, -1.7333;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701, -4.7548,  3.6521;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701,  0.0744, -1.7333;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701,  2.4064,  1.7438;
-2.6931, -2.5271, -1.2871, 0.0744, -1.7333,  0.0902,  0.0744, -1.7333;
2.2261, -5.3648,  0.3049, 3.0777,  0.3891, -0.0701,  0.0744, -1.7333;
-4.1921, -1.0285, -0.9801, 3.0777,  0.3891, -0.0701,  0.0744, -1.7333;
-4.9217,  1.2977,  0.4473, 3.0777,  0.3891, -0.0701,  0.0744, -1.7333;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701,  2.2261, -5.3648;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701, -4.9217,  1.2977;
-2.6931, -2.5271, -1.2871, 3.0777,  0.3891, -0.0701, -4.1921, -1.0285];
z(:,9:n) = ...
[ 0.5746,  1.9607, -1.6324, 0.5740,  2.8369,  1.4092, -3.1398;
0.5746,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.0902,  1.9607, -1.6324, 0.5746,  2.8369,  1.4092, -3.1398;
0.0902,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.0902,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.8524,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.0902,  0.0744, -1.7333, 0.0902, -1.2201,  0.8829,  2.2253;
1.1057,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.0902,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.0902,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.0902,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.0902,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
0.3049,  2.2261, -5.3648, 0.3049,  2.8369,  1.4092, -3.1398;
0.4473,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398;
-0.9801,  0.0744, -1.7333, 0.0902,  2.8369,  1.4092, -3.1398];

% Means and scalings
orig = int64(-1);
xbar = [-2.6137; -2.3614; -1.0449;  2.8614;  0.3156;
-0.2641; -0.3146; -1.1221;  0.2401;  0.4694;
-1.9619;  0.1691;  2.5664;  1.3741; -2.7821];
ybar = [0.452];
iscale = int64(1);
xstd = [ 1.4956;  1.3233;  0.5829;  0.7735;  0.6247;
0.7966;  2.4113;  2.0421;  0.4678;  0.8197;
0.9420;  0.1735;  1.0475;  0.1359;  1.3853];
ystd = [0.9062];

b    = [-0.1383;  0.0572; -0.1906;  0.1238;  0.0591;
0.0936; -0.2842;  0.4713;  0.2661; -0.0914;
0.1226; -0.0488;  0.0332;  0.0332; -0.0332];
isz = ones(n, 1, 'int64');

% Calculate predictions
[yhat, ifail] = g02ld( ...
orig, xbar, ybar, iscale, xstd, ystd, b, isz, z);

% Display results
disp('Predicted values');
disp(yhat);

```
```g02ld example results

Predicted values
0.2132
0.5152
0.1437
0.4459
0.1716
2.4809
0.0964
1.4475
-0.1546
-0.5492
0.5393
0.2686
-1.1332
1.7975
0.4973

```

Chapter Contents
Chapter Introduction
NAG Toolbox

© The Numerical Algorithms Group Ltd, Oxford, UK. 2009–2015