For a set of
observations classified by two variables, with
and
levels respectively, a two-way table of frequencies with
rows and
columns can be computed.
To measure the association between the two classification variables two statistics that can be used are, the Pearson
statistic,
, and the likelihood ratio test statistic,
, where
are the fitted values from the model that assumes the effects due to the classification variables are additive, i.e., there is no association. These values are the expected cell frequencies and are given by
Under the hypothesis of no association between the two classification variables, both these statistics have, approximately, a
-distribution with
degrees of freedom. This distribution is arrived at under the assumption that the expected cell frequencies,
, are not too small. For a discussion of this point see
Everitt (1977). He concludes by saying, ‘... in the majority of cases the chi-square criterion may be used for tables with expectations in excess of
in the smallest cell’.
In the case of the
table, i.e.,
and
, the
approximation can be improved by using Yates' continuity correction factor. This decreases the absolute value of
by
. For
tables with a small value of
the exact probabilities from Fisher's test are computed. These are based on the hypergeometric distribution and are computed using
nag_stat_prob_hypergeom (g01bl). A two tail probability is computed as
, where
and
are the upper and lower one-tail probabilities from the hypergeometric distribution.
For the accuracy of the probabilities for Fisher's exact test see
nag_stat_prob_hypergeom (g01bl).
The function
nag_stat_contingency_table (g01af) allows for the automatic amalgamation of rows and columns. In most circumstances this is not recommended; see
Everitt (1977).
Multidimensional contingency tables can be analysed using log-linear models fitted by
nag_correg_glm_binomial (g02gb).
The data below, taken from
Everitt (1977), is from
patients with brain tumours. The row classification variable is the site of the tumour: frontal lobes, temporal lobes and other cerebral areas. The column classification variable is the type of tumour: benign, malignant and other cerebral tumours.
The data is read in and the statistics computed and printed.
function g11aa_example
fprintf('g11aa example results\n\n');
nrow = int64(3);
nobst = [int64(23), 9, 6;
21, 4, 3;
34, 24, 17];
[expt, chist, prob, chi, g, df, ifail] = ...
g11aa(nrow, nobst);
fprintf('Probability = %9.4f\n', prob);
fprintf('Pearson Chi-square statistic = %8.3f\n', chi);
fprintf('Likelihood ratio test statistic = %8.3f\n', g);
fprintf('Degrees of freedom = %4.0f\n', df);