g01af performs the analysis of a two-way contingency table or classification. If , and the total number of objects classified is or fewer, then the probabilities for Fisher's exact test are computed. Otherwise, a test statistic is computed (with Yates' correction when ), which under the assumption of no association between the classifications has approximately a chi-square distribution with degrees of freedom.
Syntax
C# |
---|
public static void g01af( int m, int n, int[,] nobs, ref int num, double[,] pred, out double chis, double[] p, out int npos, out int ndf, out int m1, out int n1, out int ifail ) |
Visual Basic |
---|
Public Shared Sub g01af ( _ m As Integer, _ n As Integer, _ nobs As Integer(,), _ ByRef num As Integer, _ pred As Double(,), _ <OutAttribute> ByRef chis As Double, _ p As Double(), _ <OutAttribute> ByRef npos As Integer, _ <OutAttribute> ByRef ndf As Integer, _ <OutAttribute> ByRef m1 As Integer, _ <OutAttribute> ByRef n1 As Integer, _ <OutAttribute> ByRef ifail As Integer _ ) |
Visual C++ |
---|
public: static void g01af( int m, int n, array<int,2>^ nobs, int% num, array<double,2>^ pred, [OutAttribute] double% chis, array<double>^ p, [OutAttribute] int% npos, [OutAttribute] int% ndf, [OutAttribute] int% m1, [OutAttribute] int% n1, [OutAttribute] int% ifail ) |
F# |
---|
static member g01af : m : int * n : int * nobs : int[,] * num : int byref * pred : float[,] * chis : float byref * p : float[] * npos : int byref * ndf : int byref * m1 : int byref * n1 : int byref * ifail : int byref -> unit |
Parameters
- m
- Type: System..::..Int32On entry: , one more than the number of rows of the frequency matrix.Constraint: .
- n
- Type: System..::..Int32On entry: , one more than the number of columns of the frequency matrix.Constraint: .
- nobs
- Type: array<System..::..Int32,2>[,](,)[,][,]An array of size [dim1, n]Note: dim1 must satisfy the constraint:On entry: the elements , for and , must contain the frequencies for the two-way classification. The th row and the th column of nobs need not be set.On exit: contains the following information:
- , for and , contain the frequencies for the two-way classification after ‘shrinkage’ has taken place (see [Description]).
- , for , contain the total frequencies in the remaining rows, .
- , for , contain the total frequencies in the remaining columns, .
- , contains the total frequency, .
If any ‘shrinkage’ has occurred, then all other cells contain no useful information.Constraint: , for and .
- num
- Type: System..::..Int32%On entry: the value assigned to num must determine whether automatic ‘shrinkage’ is required when any , as outlined in [Description](i).If , shrinkage is required, otherwise shrinkage is not required.
- pred
- Type: array<System..::..Double,2>[,](,)[,][,]An array of size [dim1, n]Note: dim1 must satisfy the constraint:On exit: the elements , where and contain the expected frequencies, corresponding to the observed frequencies , except in the case when Fisher's exact test for a classification is to be used, when pred is not used. No other elements are utilized.
- chis
- Type: System..::..Double%On exit: the value of the test statistic, , except when Fisher's exact test for a classification is used in which case it is unspecified.
- p
- Type: array<System..::..Double>[]()[][]An array of size []p is used only when Fisher's exact test for a classification is to be used.On exit: the first num elements contain the probabilities associated with the various possible frequency tables, , for , the remainder are unspecified.
- npos
- Type: System..::..Int32%npos is used only when Fisher's exact test for a classification is to be used.On exit: holds the probability associated with the given table of frequencies.
- ndf
- Type: System..::..Int32%On exit: the value of ndf gives the number of degrees of freedom for the chi-square distribution, ; when Fisher's exact test is used .
- m1
- Type: System..::..Int32%On exit: the number of rows of the two-way classification, after any ‘shrinkage’, .
- n1
- Type: System..::..Int32%On exit: the number of columns of the two-way classification, after any ‘shrinkage’, .
- ifail
- Type: System..::..Int32%On exit: unless the method detects an error or a warning has been flagged (see [Error Indicators and Warnings]).
Description
The data consist of the frequencies for the two-way classification, denoted by , for and with .
A check is made to see whether any row or column of the matrix of frequencies consists entirely of zeros, and if so, the matrix of frequencies is reduced by omitting that row or column. Suppose the final size of the matrix is by (), and let
- , the total frequency for the th row, for ,
- , the total frequency for the th column, for , and
- , the total frequency.
There are two situations:
(i) | If and/or , or and , then the matrix of expected frequencies, denoted by , for and , and the test statistic, , are computed, where
Under the assumption that there is no association between the two classifications, will have approximately a chi-square distribution with degrees of freedom.
An option exists which allows for further ‘shrinkage’ of the matrix of frequencies in the case where for the ()th cell. If this is the case, then row or column will be combined with the adjacent row or column with smaller total. Row is selected for combination if . This ‘shrinking’ process is continued until for all cells (). |
||||||
(ii) | If and , the probabilities to enable Fisher's exact test to be made are computed.
The matrix of frequencies may be rearranged so that is the smallest marginal (i.e., column and row) total, and . Under the assumption of no association between the classifications, the probability of obtaining entries in cell is computed where
|
References
None.
Error Indicators and Warnings
Errors or warnings detected by the method:
Some error messages may refer to parameters that are dropped from this interface
(LDNOB, LDPRED) In these
cases, an error in another parameter has usually caused an incorrect value to be inferred.
- The number of rows or columns of nobs is less than , possibly after shrinkage.
- At least one frequency is negative, or all frequencies are zero.
Accuracy
The method used is believed to be stable.
Parallelism and Performance
None.
Further Comments
The time taken by g01af will increase with m and n, except when Fisher's exact test is to be used, in which case it increases with size of the marginal and total frequencies.
If, on exit, , or alternatively ndf is and , the probabilities for use in Fisher's exact test for a classification will be calculated, and not the test statistic with approximately a chi-square distribution.
Example
In the example program, NPROB determines the number of two-way classifications to be analysed. For each classification the frequencies are read, g01af called, and information given on how much ‘shrinkage’ has taken place. If Fisher's exact test is to be used, the given frequencies and the array of probabilities associated with the possible frequency tables are printed. Otherwise, if the chi-square test is to be used, the given and expected frequencies, and the test statistic with its degrees of freedom are printed. In the example, there is one classification, with shrinkage not requested.
Example program (C#): g01afe.cs