NAG C Library Function Document

nag_rand_subsamp_xyw (g05pwc)

1
Purpose

nag_rand_subsamp_xyw (g05pwc) generates a dataset suitable for use with repeated random sub-sampling validation.

2
Specification

#include <nag.h>
#include <nagg05.h>
void  nag_rand_subsamp_xyw (Integer nt, Integer n, Integer m, Nag_DataByObsOrVar sordx, double x[], Integer pdx, double y[], double w[], Integer state[], NagError *fail)

3
Description

Let Xo denote a matrix of n observations on m variables and yo and wo each denote a vector of length n. For example, Xo might represent a matrix of independent variables, yo the dependent variable and wo the associated weights in a weighted regression.
nag_rand_subsamp_xyw (g05pwc) generates a series of training datasets, denoted by the matrix, vector, vector triplet Xt,yt,wt of nt observations, and validation datasets, denoted Xv,yv,wv with nv 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 sub-sampling validation.
One of the initialization functions nag_rand_init_repeatable (g05kfc) (for a repeatable sequence if computed sequentially) or nag_rand_init_nonrepeatable (g05kgc) (for a non-repeatable sequence) must be called prior to the first call to nag_rand_subsamp_xyw (g05pwc).

4
References

None.

5
Arguments

1:     nt IntegerInput
On entry: nt, the number of observations in the training dataset.
Constraint: 1ntn.
2:     n IntegerInput
On entry: n, the number of observations.
Constraint: n1.
3:     m IntegerInput
On entry: m, the number of variables.
Constraint: m1.
4:     sordx Nag_DataByObsOrVarInput
On entry: determines how variables are stored in x.
Constraint: sordx=Nag_DataByVar or Nag_DataByObs.
5:     x[dim] doubleInput/Output
Note: the dimension, dim, of the array x must be at least
  • pdx×m when sordx=Nag_DataByVar;
  • pdx×n when sordx=Nag_DataByObs.
The way the data is stored in x is defined by sordx.
If sordx=Nag_DataByVar, x[j-1×pdx+i-1] contains the ith observation for the jth variable, for i=1,2,,n and j=1,2,,m.
If sordx=Nag_DataByObs, x[i-1×pdx+j-1] contains the ith observation for the jth variable, for i=1,2,,n and j=1,2,,m.
On entry: x must hold Xo, the values of X for the original dataset. This may be the same x as returned by a previous call to nag_rand_subsamp_xyw (g05pwc).
On exit: values of X for the training and validation datasets, with Xt held in observations 1 to nt and Xv in observations nt+1 to n.
6:     pdx IntegerInput
On entry: the stride separating row elements in the two-dimensional data stored in the array x.
Constraints:
  • if sordx=Nag_DataByObs, pdxm;
  • otherwise pdxn.
7:     y[dim] doubleInput/Output
Note: the dimension, dim, of the array y must be at least
  • n, when yis notNULL;
  • otherwise y is not referenced and may be NULL.
If the original dataset does not include yo then y must be set to NULL.
On entry: y must hold yo, the values of y for the original dataset. This may be the same y as returned by a previous call to nag_rand_subsamp_xyw (g05pwc).
On exit: values of y for the training and validation datasets, with yt held in elements 1 to nt and yv in elements nt+1 to n.
8:     w[dim] doubleInput/Output
Note: the dimension, dim, of the array w must be at least
  • n, when wis notNULL;
  • otherwise w is not referenced and may be NULL.
If the original dataset does not include wo then w must be set to NULL.
On entry: w must hold wo, the values of w for the original dataset. This may be the same w as returned by a previous call to nag_rand_subsamp_xyw (g05pwc).
On exit: values of w for the training and validation datasets, with wt held in elements 1 to nt and wv in elements nt+1 to n.
9:     state[dim] IntegerCommunication Array
Note: the dimension, 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:   fail NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6
Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_ARRAY_SIZE
On entry, pdx=value and m=value.
Constraint: if sordx=Nag_DataByObs, pdxm.
On entry, pdx=value and n=value.
Constraint: if sordx=Nag_DataByVar, pdxn.
NE_BAD_PARAM
On entry, argument value had an illegal value.
NE_INT
On entry, m=value.
Constraint: m1.
On entry, n=value.
Constraint: n1.
NE_INT_2
On entry, nt=value and n=value.
Constraint: 1ntn.
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 2.7.6 in How to Use the NAG Library and its Documentation 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 2.7.5 in How to Use the NAG Library and its Documentation for further information.

7
Accuracy

Not applicable.

8
Further Comments

nag_rand_subsamp_xyw (g05pwc) will be computationality more efficient if each observation in x is contiguous, that is sordx=Nag_DataByObs.

9
Example

This example uses nag_rand_subsamp_xyw (g05pwc) to facilitate repeated random sub-sampling cross-validation.
A set of simulated data is randomly split into a training and validation datasets. nag_glm_binomial (g02gbc) is used to fit a logistic regression model to each training dataset and then nag_glm_predict (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.

9.1
Program Text

Program Text (g05pwce.c)

9.2
Program Data

Program Data (g05pwce.d)

9.3
Program Results

Program Results (g05pwce.r)