NAG CL Interface
g05pwc (subsamp_xyw)
1
Purpose
g05pwc generates a dataset suitable for use with repeated random subsampling validation.
2
Specification
void 
g05pwc (Integer nt,
Integer n,
Integer m,
Nag_DataByObsOrVar sordx,
double x[],
Integer pdx,
double y[],
double w[],
Integer state[],
NagError *fail) 

The function may be called by the names: g05pwc or nag_rand_subsamp_xyw.
3
Description
Let ${X}_{o}$ denote a matrix of $n$ observations on $m$ variables and ${y}_{o}$ and ${w}_{o}$ each denote a vector of length $n$. For example, ${X}_{o}$ might represent a matrix of independent variables, ${y}_{o}$ the dependent variable and ${w}_{o}$ the associated weights in a weighted regression.
g05pwc generates a series of training datasets, denoted by the matrix, vector, vector triplet $\left({X}_{t},{y}_{t},{w}_{t}\right)$ of ${n}_{t}$ observations, and validation datasets, denoted $\left({X}_{v},{y}_{v},{w}_{v}\right)$ with ${n}_{v}$ observations. These training and validation datasets are generated by randomly assigning each observation to either the training dataset or the validation dataset.
The resulting datasets are suitable for use with repeated random subsampling validation.
One of the initialization functions
g05kfc (for a repeatable sequence if computed sequentially) or
g05kgc (for a nonrepeatable sequence) must be called prior to the first call to
g05pwc.
4
References
None.
5
Arguments

1:
$\mathbf{nt}$ – Integer
Input

On entry: ${n}_{t}$, the number of observations in the training dataset.
Constraint:
$1\le {\mathbf{nt}}\le {\mathbf{n}}$.

2:
$\mathbf{n}$ – Integer
Input

On entry: $n$, the number of observations.
Constraint:
${\mathbf{n}}\ge 1$.

3:
$\mathbf{m}$ – Integer
Input

On entry: $m$, the number of variables.
Constraint:
${\mathbf{m}}\ge 1$.

4:
$\mathbf{sordx}$ – Nag_DataByObsOrVar
Input

On entry: determines how variables are stored in
x.
Constraint:
${\mathbf{sordx}}=\mathrm{Nag\_DataByVar}$ or $\mathrm{Nag\_DataByObs}$.

5:
$\mathbf{x}\left[\mathit{dim}\right]$ – double
Input/Output

Note: the dimension,
dim, of the array
x
must be at least
 ${\mathbf{pdx}}\times {\mathbf{m}}$ when
${\mathbf{sordx}}=\mathrm{Nag\_DataByVar}$;
 ${\mathbf{pdx}}\times {\mathbf{n}}$ when
${\mathbf{sordx}}=\mathrm{Nag\_DataByObs}$.
The way the data is stored in
x is defined by
sordx.
If ${\mathbf{sordx}}=\mathrm{Nag\_DataByVar}$, ${\mathbf{x}}\left[\left(\mathit{j}1\right)\times {\mathbf{pdx}}+\mathit{i}1\right]$ contains the $\mathit{i}$th observation for the $\mathit{j}$th variable, for $i=1,2,\dots ,{\mathbf{n}}$ and $j=1,2,\dots ,{\mathbf{m}}$.
If ${\mathbf{sordx}}=\mathrm{Nag\_DataByObs}$, ${\mathbf{x}}\left[\left(\mathit{i}1\right)\times {\mathbf{pdx}}+\mathit{j}1\right]$ contains the $\mathit{i}$th observation for the $\mathit{j}$th variable, for $i=1,2,\dots ,{\mathbf{n}}$ and $j=1,2,\dots ,{\mathbf{m}}$.
On entry:
x must hold
${X}_{o}$, the values of
$X$ for the original dataset. This may be the same
x as updated by a previous call to
g05pwc.
On exit: values of $X$ for the training and validation datasets, with ${X}_{t}$ held in observations $1$ to ${\mathbf{nt}}$ and ${X}_{v}$ in observations ${\mathbf{nt}}+1$ to ${\mathbf{n}}$.

6:
$\mathbf{pdx}$ – Integer
Input

On entry: the stride separating row elements in the twodimensional data stored in the array
x.
Constraints:
 if ${\mathbf{sordx}}=\mathrm{Nag\_DataByObs}$, ${\mathbf{pdx}}\ge {\mathbf{m}}$;
 otherwise ${\mathbf{pdx}}\ge {\mathbf{n}}$.

7:
$\mathbf{y}\left[\mathit{dim}\right]$ – double
Input/Output

Note: the dimension,
dim, of the array
y
must be at least
 ${\mathbf{n}}$, when ${\mathbf{y}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$;
 otherwise ${\mathbf{y}}$ is not referenced and may be NULL.
If the original dataset does not include
${y}_{o}$ then
y must be set to
NULL.
On entry:
y must hold
${y}_{o}$, the values of
$y$ for the original dataset. This may be the same
y as updated by a previous call to
g05pwc.
On exit: values of $y$ for the training and validation datasets, with ${y}_{t}$ held in elements $1$ to ${\mathbf{nt}}$ and ${y}_{v}$ in elements ${\mathbf{nt}}+1$ to ${\mathbf{n}}$.

8:
$\mathbf{w}\left[\mathit{dim}\right]$ – double
Input/Output

Note: the dimension,
dim, of the array
w
must be at least
 ${\mathbf{n}}$, when ${\mathbf{w}}\phantom{\rule{0.25em}{0ex}}\text{is not}\phantom{\rule{0.25em}{0ex}}\mathbf{NULL}$;
 otherwise ${\mathbf{w}}$ is not referenced and may be NULL.
If the original dataset does not include
${w}_{o}$ then
w must be set to
NULL.
On entry:
w must hold
${w}_{o}$, the values of
$w$ for the original dataset. This may be the same
w as updated by a previous call to
g05pwc.
On exit: values of $w$ for the training and validation datasets, with ${w}_{t}$ held in elements $1$ to ${\mathbf{nt}}$ and ${w}_{v}$ in elements ${\mathbf{nt}}+1$ to ${\mathbf{n}}$.

9:
$\mathbf{state}\left[\mathit{dim}\right]$ – Integer
Communication Array
Note: the dimension,
$\mathit{dim}$, of this array is dictated by the requirements of associated functions that must have been previously called. This array MUST be the same array passed as argument
state in the previous call to
nag_rand_init_repeatable (g05kfc) or
nag_rand_init_nonrepeatable (g05kgc).
On entry: contains information on the selected base generator and its current state.
On exit: contains updated information on the state of the generator.

10:
$\mathbf{fail}$ – NagError *
Input/Output

The NAG error argument (see
Section 7 in the Introduction to the NAG Library CL Interface).
6
Error Indicators and Warnings
 NE_ALLOC_FAIL

Dynamic memory allocation failed.
See
Section 3.1.2 in the Introduction to the NAG Library CL Interface for further information.
 NE_ARRAY_SIZE

On entry, ${\mathbf{pdx}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{m}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: if ${\mathbf{sordx}}=\mathrm{Nag\_DataByObs}$, ${\mathbf{pdx}}\ge {\mathbf{m}}$.
On entry, ${\mathbf{pdx}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: if ${\mathbf{sordx}}=\mathrm{Nag\_DataByVar}$, ${\mathbf{pdx}}\ge {\mathbf{n}}$.
 NE_BAD_PARAM

On entry, argument $\u2329\mathit{\text{value}}\u232a$ had an illegal value.
 NE_INT

On entry, ${\mathbf{m}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{m}}\ge 1$.
On entry, ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: ${\mathbf{n}}\ge 1$.
 NE_INT_2

On entry, ${\mathbf{nt}}=\u2329\mathit{\text{value}}\u232a$ and ${\mathbf{n}}=\u2329\mathit{\text{value}}\u232a$.
Constraint: $1\le {\mathbf{nt}}\le {\mathbf{n}}$.
 NE_INTERNAL_ERROR

An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact
NAG for assistance.
See
Section 7.5 in the Introduction to the NAG Library CL Interface for further information.
 NE_INVALID_STATE

On entry,
state vector has been corrupted or not initialized.
 NE_NO_LICENCE

Your licence key may have expired or may not have been installed correctly.
See
Section 8 in the Introduction to the NAG Library CL Interface for further information.
7
Accuracy
Not applicable.
8
Parallelism and Performance
g05pwc is threaded by NAG for parallel execution in multithreaded implementations of the NAG Library.
g05pwc 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 function. Please also consult the
Users' Note for your implementation for any additional implementationspecific information.
g05pwc will be computationality more efficient if each observation in
x is contiguous, that is
${\mathbf{sordx}}=\mathrm{Nag\_DataByObs}$.
10
Example
This example uses g05pwc to facilitate repeated random subsampling crossvalidation.
A set of simulated data is randomly split into a training and validation datasets.
g02gbc is used to fit a logistic regression model to each training dataset and then
g02gpc is used to predict the response for the observations in the validation dataset. This process is repeated
$10$ times.
The counts of true and false positives and negatives along with the sensitivity and specificity is then reported.
10.1
Program Text
10.2
Program Data
10.3
Program Results