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_contab_binary_service (g11sb)

## Purpose

nag_contab_binary_service (g11sb) is a service function which may be used prior to calling nag_contab_binary (g11sa) to calculate the frequency distribution of a set of dichotomous score patterns.

## Syntax

[ns, x, irl, ifail] = g11sb(x, 'ip', ip, 'n', n)
[ns, x, irl, ifail] = nag_contab_binary_service(x, 'ip', ip, 'n', n)
Note: the interface to this routine has changed since earlier releases of the toolbox:
 At Mark 22: n was made optional

## Description

When each of $n$ individuals responds to each of $p$ dichotomous variables the data assumes the form of the matrix $X$ defined below
 $X= x11 x12 … x1p x21 x22 … x2p ⋮ ⋮ ⋮ xn1 xn2 … xnp = x̲1 x̲2 ⋮ x̲n ,$
where the $x$ take the value of $0$ or $1$ and ${\underline{x}}_{\mathit{l}}=\left({x}_{\mathit{l}1},{x}_{\mathit{l}2},\dots ,{x}_{\mathit{l}p}\right)$, for $\mathit{l}=1,2,\dots ,n$, denotes the score pattern of the $l$th individual. nag_contab_binary_service (g11sb) calculates the number of different score patterns, $s$, and the frequency with which each occurs. This information can then be passed to nag_contab_binary (g11sa).

None.

## Parameters

### Compulsory Input Parameters

1:     $\mathrm{x}\left(\mathit{ldx},{\mathbf{ip}}\right)$ – logical array
ldx, the first dimension of the array, must satisfy the constraint $\mathit{ldx}\ge {\mathbf{n}}$.
${\mathbf{x}}\left(\mathit{i},\mathit{j}\right)$ must be set equal to true if ${x}_{\mathit{i}\mathit{j}}=1$, and false if ${x}_{\mathit{i}\mathit{j}}=0$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,p$.

### Optional Input Parameters

1:     $\mathrm{ip}$int64int32nag_int scalar
Default: the second dimension of the array x.
$p$, the number of dichotomous variables.
Constraint: ${\mathbf{ip}}\ge 3$.
2:     $\mathrm{n}$int64int32nag_int scalar
Default: the first dimension of the array x.
$n$, the number of individuals in the sample.
Constraint: ${\mathbf{n}}\ge 7$.

### Output Parameters

1:     $\mathrm{ns}$int64int32nag_int scalar
The number of different score patterns, $s$.
2:     $\mathrm{x}\left(\mathit{ldx},{\mathbf{ip}}\right)$ – logical array
The first $s$ rows of x contain the $s$ different score patterns.
3:     $\mathrm{irl}\left({\mathbf{n}}\right)$int64int32nag_int array
The frequency with which the $\mathit{l}$th row of x occurs, for $\mathit{l}=1,2,\dots ,s$.
4:     $\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$
 On entry, ${\mathbf{ip}}<3$, or ${\mathbf{n}}<7$, or $\mathit{ldx}<{\mathbf{n}}$.
${\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

Exact.

The time taken by nag_contab_binary_service (g11sb) is small and increases with $n$.

## Example

This example counts the frequencies of different score patterns in the following list:
 Score Patterns 000 010 111 000 001 000 000 110 001 011
```function g11sb_example

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

x = [false, false, false;
false, true,  false;
true,  true,  true;
false, false, false;
false, false, true;
false, false, false;
false, false, false;
true,  true,  false;
false, false, true;
false, true,  true];

[ns, x, irl, ifail] = g11sb(x);

% Display results
fprintf('Frequency     Score pattern\n\n');
for i = 1:ns
fprintf('%5d            ', irl(i));
fprintf('%2d', x(i,:));
fprintf('\n');
end

```
```g11sb example results

Frequency     Score pattern

4             0 0 0
1             0 1 0
1             1 1 1
2             0 0 1
1             1 1 0
1             0 1 1
```

Chapter Contents
Chapter Introduction
NAG Toolbox

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