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:
Mark 22: n has been made optional
.

## Description

When each of n$n$ individuals responds to each of p$p$ dichotomous variables the data assumes the form of the matrix X$X$ defined below
X =
 [ x11 x12 … x1p x21 x22 … x2p ⋮ ⋮ ⋮ xn1 xn2 … xnp ]
=
 [ x ̲ 1 x ̲ 2 ⋮ x ̲ n ]
,
$X=[ x11 x12 … x1p x21 x22 … x2p ⋮ ⋮ ⋮ xn1 xn2 … xnp ]=[ x̲1 x̲2 ⋮ x̲n ] ,$
where the x$x$ take the value of 0$0$ or 1$1$ and x ̲ l = (xl1,xl2,,xlp)${\underline{x}}_{\mathit{l}}=\left({x}_{\mathit{l}1},{x}_{\mathit{l}2},\dots ,{x}_{\mathit{l}p}\right)$, for l = 1,2,,n$\mathit{l}=1,2,\dots ,n$, denotes the score pattern of the l$l$th individual. nag_contab_binary_service (g11sb) calculates the number of different score patterns, s$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:     x(ldx,ip) – logical array
ldx, the first dimension of the array, must satisfy the constraint ldxn$\mathit{ldx}\ge {\mathbf{n}}$.
x(i,j)${\mathbf{x}}\left(\mathit{i},\mathit{j}\right)$ must be set equal to true if xij = 1${x}_{\mathit{i}\mathit{j}}=1$, and false if xij = 0${x}_{\mathit{i}\mathit{j}}=0$, for i = 1,2,,n$\mathit{i}=1,2,\dots ,n$ and j = 1,2,,p$\mathit{j}=1,2,\dots ,p$.

### Optional Input Parameters

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

ldx

### Output Parameters

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

## Accuracy

Exact.

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

## Example

```function nag_contab_binary_service_example
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, xOut, irl, ifail] = nag_contab_binary_service(x)
```
```

ns =

6

xOut =

0     0     0
0     1     0
1     1     1
0     0     1
1     1     0
0     1     1
0     0     0
1     1     0
0     0     1
0     1     1

irl =

4
1
1
2
1
1
0
1
0
1

ifail =

0

```
```function g11sb_example
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, xOut, irl, ifail] = g11sb(x)
```
```

ns =

6

xOut =

0     0     0
0     1     0
1     1     1
0     0     1
1     1     0
0     1     1
0     0     0
1     1     0
0     0     1
0     1     1

irl =

4
1
1
2
1
1
0
1
0
1

ifail =

0

```