g11 Chapter Contents
g11 Chapter Introduction
NAG Library Manual

# NAG Library Function Documentnag_binary_factor_service (g11sbc)

## 1  Purpose

nag_binary_factor_service (g11sbc) is a service function which may be used prior to calling nag_binary_factor (g11sac) to calculate the frequency distribution of a set of dichotomous score patterns.

## 2  Specification

 #include #include
 void nag_binary_factor_service (Nag_OrderType order, Integer p, Integer n, Integer *ns, Nag_Boolean x[], Integer pdx, Integer irl[], NagError *fail)

## 3  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_binary_factor_service (g11sbc) calculates the number of different score patterns, $s$, and the frequency with which each occurs. This information can then be passed to nag_binary_factor (g11sac).

None.

## 5  Arguments

1:     orderNag_OrderTypeInput
On entry: the order argument specifies the two-dimensional storage scheme being used, i.e., row-major ordering or column-major ordering. C language defined storage is specified by ${\mathbf{order}}=\mathrm{Nag_RowMajor}$. See Section 3.2.1.3 in the Essential Introduction for a more detailed explanation of the use of this argument.
Constraint: ${\mathbf{order}}=\mathrm{Nag_RowMajor}$ or $\mathrm{Nag_ColMajor}$.
2:     pIntegerInput
On entry: $p$, the number of dichotomous variables.
Constraint: ${\mathbf{p}}\ge 3$.
3:     nIntegerInput
On entry: $n$, the number of individuals in the sample.
Constraint: ${\mathbf{n}}\ge 7$.
4:     nsInteger *Output
On exit: the number of different score patterns, $s$.
5:     x[$\mathit{dim}$]Nag_BooleanInput/Output
Note: the dimension, dim, of the array x must be at least
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{pdx}}×{\mathbf{p}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• $\mathrm{max}\phantom{\rule{0.125em}{0ex}}\left(1,{\mathbf{n}}×{\mathbf{pdx}}\right)$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
Where ${\mathbf{X}}\left(i,j\right)$ appears in this document, it refers to the array element
• ${\mathbf{x}}\left[\left(j-1\right)×{\mathbf{pdx}}+i-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_ColMajor}$;
• ${\mathbf{x}}\left[\left(i-1\right)×{\mathbf{pdx}}+j-1\right]$ when ${\mathbf{order}}=\mathrm{Nag_RowMajor}$.
On entry: ${\mathbf{X}}\left(\mathit{i},\mathit{j}\right)$ must be set equal to Nag_TRUE if ${x}_{\mathit{i}\mathit{j}}=1$, and Nag_FALSE if ${x}_{\mathit{i}\mathit{j}}=0$, for $\mathit{i}=1,2,\dots ,n$ and $\mathit{j}=1,2,\dots ,p$.
On exit: the first $s$ rows of x contain the $s$ different score patterns.
6:     pdxIntegerInput
On entry: the stride separating row or column elements (depending on the value of order) in the array x.
Constraints:
• if ${\mathbf{order}}=\mathrm{Nag_ColMajor}$, ${\mathbf{pdx}}\ge {\mathbf{n}}$;
• if ${\mathbf{order}}=\mathrm{Nag_RowMajor}$, ${\mathbf{pdx}}\ge {\mathbf{p}}$.
7:     irl[n]IntegerOutput
On exit: the frequency with which the $\mathit{l}$th row of x occurs, for $\mathit{l}=1,2,\dots ,s$.
8:     failNagError *Input/Output
The NAG error argument (see Section 3.6 in the Essential Introduction).

## 6  Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
On entry, argument $⟨\mathit{\text{value}}⟩$ had an illegal value.
NE_INT
On entry, ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{n}}\ge 7$.
On entry, ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{p}}\ge 3$.
On entry, ${\mathbf{pdx}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdx}}>0$.
NE_INT_2
On entry, ${\mathbf{pdx}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{n}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{n}}$.
On entry, ${\mathbf{pdx}}=⟨\mathit{\text{value}}⟩$ and ${\mathbf{p}}=⟨\mathit{\text{value}}⟩$.
Constraint: ${\mathbf{pdx}}\ge {\mathbf{p}}$.
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.

Exact.

## 8  Parallelism and Performance

Not applicable.

The time taken by nag_binary_factor_service (g11sbc) is small and increases with $n$.

## 10  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

### 10.1  Program Text

Program Text (g11sbce.c)

### 10.2  Program Data

Program Data (g11sbce.d)

### 10.3  Program Results

Program Results (g11sbce.r)