Tests in contingency tables as regression tests

Tests in contingency tables as regression tests

Economics Letters 105 (2009) 189–192 Contents lists available at ScienceDirect Economics Letters j o u r n a l h o m e p a g e : w w w. e l s ev i e...

183KB Sizes 3 Downloads 182 Views

Economics Letters 105 (2009) 189–192

Contents lists available at ScienceDirect

Economics Letters j o u r n a l h o m e p a g e : w w w. e l s ev i e r. c o m / l o c a t e / e c o l e t

Tests in contingency tables as regression tests Stanislav Anatolyev ⁎, Grigory Kosenok New Economic School, Moscow, Russia

a r t i c l e

i n f o

Article history: Received 28 July 2008 Received in revised form 22 July 2009 Accepted 23 July 2009 Available online 6 August 2009

a b s t r a c t Applied researchers often use tests based on contingency tables, especially in preliminary data analysis and diagnostic testing. We show that many such tests may be alternatively implemented by testing for coefficient restrictions in linear regression systems. © 2009 Elsevier B.V. All rights reserved.

Keywords: Contingency table Linear regression Chi-squared test Wald test Ranks JEL classification: C12 C22 C32 C53

1. Introduction Often applied economists and financiers use tests associated with contingency tables. Such tests are designed for verifying independence or homogeneity properties of original data or regression residuals, and are heavily used in preliminary data analysis and diagnostic testing. For example, the phrase “contingency table” leads to 185 and 61 hits using advance search (performed in July 2008) in JSTOR economics (31 journals) and finance (7 journals) collections, respectively. Some of associated tests are even more frequently mentioned. The tests related to contingency tables are performed by utilizing particular formulas, often quite complex ones. In this paper we give a number of results showing that typically such tests may be alternatively implemented via a system of linear regressions. This concerns tests for independence, tests for accordance with distribution, tests for symmetry, and tests based on ranks. Such reformulation is useful for a number of reasons. First, it unifies the regression analysis with the theory of contingency tables. Second, the bridge between the two theories sheds more light on intuitive contents of

contingency table tests and test statistics. Third, running regressions may be more convenient and familiar for practitioners. A complete working paper version of the article containing references to applications, more related discussions, and proofs of all results can be found on the website www.nes.ru/~sanatoly/Papers/ CT.pdf. 2. Two-way contingency tables We begin by introducing some basic notation. The sample size is denoted by n. Bars denote taking sample averages.  We consider a two-way ðℓx + 1Þ × ℓy + 1 contingency table. The state space Ωx of one variable, x, is partitioned into the cover x + 1 space Ωy of the other variable, y, is fKi gℓ i = 1 ; similarly, the state  ℓy + 1 partitioned into the cover Λ j j = . Let us denote 1 Ii; · = IðxaKi Þ;

0165-1765/$ – see front matter © 2009 Elsevier B.V. All rights reserved. doi:10.1016/j.econlet.2009.07.014

Ii;j = IðxaKi ÞIðyaΛ j Þ;

where I (·) denotes the indicator function. Let πi; · = PrfxaKi g;

⁎ Corresponding author. Stanislav Anatolyev, New Economic School, Nakhimovsky Pr., 47, Moscow, 117418 Russia. E-mail address: [email protected] (S. Anatolyev).

I · ;j = IðyaΛ j Þ;

π · ;j = PrfyaΛ j g;

πi;j = PrfxaKi ; yaΛ j g;

and define ℓ

x πx = jjπ i; · jji = 1;

ℓy = 1

πy = jjπ · ;j jjj

ℓy ℓx = 1 j = 1:

π = jjπi;j jji

190

S. Anatolyev, G. Kosenok / Economics Letters 105 (2009) 189–192

We assume that πi,j N 0 for all i and j. The contingency table looks as follows:

distribution of y does not depend on x. Suppose now that the ℓy + 1 marginals π · ; j j = are known a priori. Then the χ 2 test, whose 1 statistic can be modified to take account of this knowledge, may be interpreted as a test for accordance of ℓx + 1 independent subsamples with a known multinomial distribution. The modified test statistic is equal to 2

X =n

+ 1 ℓxX + 1 ℓyX i=1

 2 pi;j − pi; · π · ;j pi; · π · ;j

j=1

;

ð3Þ

  and is asymptotically distributed as χ 2 ðℓx + 1Þℓy :

The figures in the tables are empirical probabilities of falling into corresponding cells pi;j = Ii;j

Theorem 2. The χ 2 test (3) is asymptotically equivalent to an OLS-based Wald test for the nullity of all coefficients in a linear multiple regression of I., j − π., j on Ii,. with a constant in each equation, i.e. for the null H0 : α j = βji = 0; i = 1; : : : ; ℓx ; j = 1; : : : ; ℓy in the regression system

and marginal empirical probabilities pi; · = Ii; · ;

I · ;j − π · ;j = α j +

p · ;j = I · ;j :

3. Tests and their equivalences 3.1. Tests for independence The classical χ2-test statistic for independence between the variables x and y (more precisely, for no association between x and y) is equal to

X =n

+ 1 ℓxX + 1 ℓyX i=1



pi;j −pi; · p · ;j

j=1

βji Ii; · + ηj ;

j = 1;: : :; ℓy :

ð4Þ

i=1

In many applications, each Ki is an interval ½κ i − 1 ; κ i Þ and each Λ j is an  interval λj − 1 ; λj Þ, where −∞ = κ 0 bκ 1 b: : :bκ ℓx bκ ℓx + 1 = + ∞ and −∞ = λ0 bλ1 b: : : bλℓy bλℓy + 1 = + ∞. When ℓx = ℓy and Ki =Λj for all i, the contingency table is referred to as one with identical categorizations. However, rows and columns of a contingency table need not correspond to partitionings of a real axis, and categorizations need not be identical.

2

ℓx X

pi; · p · ;j

2 ;

ð1Þ

  and is asymptotically distributed as χ 2 ℓx ℓy :

Remark 1. The regression from Theorem 2 is the same as that from Theorem 1. However, the set of restrictions is expanded by additional ℓy restrictions of equality of the intercepts in Eq. (2) to the known a priori y-marginals. This explains the additional ℓy degrees of freedom in the asymptotic χ 2 distribution. When ℓx = 0, the contingency table essentially becomes one-way, and there is only one subsample yj ðxaXx Þ. Then the test is called the Pearson (1900) test for goodness of fit, and it simply verifies if the sample is drawn from a given multinomial distribution. The test statistic becomes Pearson's  2 ℓy + 1 p · ;j − π · ;j X 2 X =n ; ð5Þ π · ;j j=1   and is asymptotically distributed as χ 2 ℓy : Corollary 1. The Pearson test (5) is asymptotically equivalent to an OLS-based Wald test for the nullity of all coefficients in a linear multiple regression of I · ;j − π · ;j on a constant in each equation, i.e. for the null H0 : α j = 0; j = 1; : : : ; ℓy

Theorem 1. The χ 2 test (1) is asymptotically equivalent to an OLSbased Wald test for the nullity of all slope coefficients in a linear multiple regression of I.,j on Ii,. with a constant in each equation, i.e. for the null H0 : βji = 0; i = 1; : : : ; ℓx ; j = 1; : : : ; ℓy

in the regression system I · ;j − π · ;j = α j + ηj ;

j = 1; : : : ; ℓy :

ð6Þ

Note that when the contingency table is 2 × 2, the test for independence can be run using only one bivariate regression.

Applications of the Pearson test in economics can be divided into two categories. In the first category, frequencies of simulated values from an estimated model falling into pre-specified bins are compared to a multinomial distribution implied by an assumed continuous distribution, the latter possibly having shape parameters estimated. Most often, the reference distribution is uniform so that  however,  π · ;j = 1 = ℓy + 1 , and the leading application is evaluation of conditional density forecasts. In the second category of applications, one compares frequencies of model-generated predictions falling into pre-specified bins to a multinomial distribution implied by an empirical density.

3.2. Tests for accordance with distribution

3.3. Tests for symmetry

The previous χ 2 test may be also interpreted as a test for homogeneity of ℓx + 1 subsamples yj ðxaKi Þ, i.e. that the conditional

Next we analyze two tests for symmetry in contingency tables with identical categorizations. Stuart (1955) suggested a test for

in the regression system I · ;j = α j +

ℓx X

βji Ii; · + ηj ;

j = 1; : : : ; ℓy :

ð2Þ

i=1

Alternatively, Ii,. may be regressed on I.,j rather than I.,j are regressed on Ii,..

S. Anatolyev, G. Kosenok / Economics Letters 105 (2009) 189–192

homogeneity of the marginal distributions of x and y. Formally, the null is H0 : πi; · = π · ;i ; i = 1;: : :; ℓ;

V

Qn = ndn V

−1

within a sample. The sums of ranks for the separate samples is Pnj denoted by Rj = i = 1 rj;i . The Kruskal–Wallis test statistic is KW =

which automatically implies also πℓ + 1; · = π · ;ℓ + 1 . The test is based on the ℓ × 1 vector of differences pi; · − p · ;i ; i = 1;: : :; ℓ. Let dn = jjpi; · − p · ;i jjℓ i = 1 . The test statistic is dn ;

191



2 k X 12 1 n+1 nj : Rj − ðn − 1Þn j = 1 nj 2

Let asymptotically nY∞ and minj nj Y∞ so that λj u limminj nj Y∞ nj = n ≠ 0 for j = 1; :::; k. Under these circumstances, KW is asymptotically distributed as χ 2 ðk − 1Þ:

 ℓ ℓ − 2pi;i − pi; · − where V = jjVi;j jji = 1 j = 1 ,  and Vi;i = pi; · + p · ;i  p · ;i Þ2 , Vi;j = − pi;j − pj;i − pi; · − p · ;i pj; · − p · ;j , i ≠ j. Under 2 HO, Qn is asymptotically distributed as χ ðℓÞ:

Theorem 5. The Kruskal–Wallis KW test is asymptotically equivalent to an OLS-based Wald test for the nullity of all intercepts in a linear multiple 1 : : :; k − 1, on a constant, i.e. for the null regression of rj;i − n + 2 ; j = 1;

Theorem 3. The Stuart Qn test is asymptotically equivalent to an OLSbased Wald test for the nullity of all intercepts in a linear multiple regression of Ii,. − I.,i on a constant, i.e. for the null

in the regression system

i = 1; : : : ; ℓ:

ð7Þ

Bowker (1948) suggested a test for complete symmetry of the contingency table. Such symmetry implies a stronger equivalence between the two classifications than equality of marginal distributions. In fact, it is the two conditional distributions that are compared. Formally, the null is H0 : πi;j = πj;i ; i = 2;: : :; ℓ + 1; j = 1;: : :; i − 1: The test is based on ℓðℓ + 1Þ = 2 differences pi;j − pj;i ; i = 2;: : :; ℓ + 1, j = 1;: : :; i − 1. The test statistic is

Un = n

i=2

j=1

 2 pi;j −pj;i pi;j + pj;i

j = 1;: : :; k − 1;

ð9Þ

with observations running from i = 1 to i = nj for equation j.

in the regression system

ℓX + 1 iX −1

n+1 = α j + ηij ; 2

rj;i −

H0 : α i = 0; i = 1; : : : ; ℓ

Ii; · − I · ;i = α i + ηi ;

H0 : α j = 0; j = 1; : : : ; k − 1

Remark 2. A similar, but different, situation is considered in statistical literature. A fixed number s of products are ranked by a fixed number k of experts. Denote by Ki,j the ranking that the expert j gave the product i (Ki,j varies from 1 to s), and by Ni,j the number of times the product i received ranking j. The Friedman test statistic 0 12 s k X X 12 s + 1 @ kA F= Ki;j − ksðs + 1Þ j = 1 2 j=1 is used to test for homogeneity of products. It is asymptotically distributed as χ 2 ðs − 1Þ as the number of experts increases. It is possible to show that F is asymptotically equivalent to an OLS-based Wald test for H0 : α i = 0; i = 1; : : : ; s − 1

:

in the regression system

Under HO, Un is asymptotically distributed as χ ðℓðℓ + 1Þ = 2Þ: 2

Ki;j −

s+1 = α i + ηij ; 2

i = 1; : : : ; s − 1;

ð10Þ

Theorem 4. The Bowker Un test is asymptotically equivalent to an OLSbased Wald test for the nullity of all intercepts in a linear multiple regression of Ii;j − Ij;i on a constant, i.e. for the null

with observations running from j = 1 to j =k. The Anderson test statistic

H0 : α ij = 0; i = 2;: : :; ℓ + 1; j = 1; : : : ; i − 1

A=

in the regression system Ii;j − Ij;i = α ij + ηij ;

i = 2;: : :; ℓ + 1; j = 1;: : :; i − 1:

ð8Þ



s s X sX k 2 Ni;j − ; k i=1 j=1 s

  asymptotically distributed as χ 2 ðs−1Þ2 as the number of experts increases, is used to test for homogeneity of products. It is possible to show that A is asymptotically equivalent to an OLS-based Wald test for H0 : α i;j = 0; i; j = 1; : : : ; s − 1

3.4. Tests based on ranks Often researchers carry out testing for independence or homogeneity using rank transformed data rather than the original data, the idea being to compare more objective “ordinal” data characteristics instead of “cardinal” ones. In the rest of the article we review two class of tests based on ranks — the Kruskal–Wallis test and the Spearman rank test. Suppose that k random samples of size n1 ; :::; nk are tested for identity of distributions they come from. Let the vector of ranks  V r1;1 ; :::; r1;n1 ; :::; rk;1 ; :::; rk;nk correspond to the pooled sample (of Pk length n = j = 1 nj ). Let j index samples, while i index observations

in the regression system Ni;j −

k = α i;j + ηij ; s

i; j = 1; : : : ; s − 1;

ð11Þ

with one observation per equation. Suppose the vector of ranks (R1,…,Rn)' corresponds to a random sample of length n. The Spearman rank statistic ρ is defined as ρ=

n X 12 ðn − 1Þn i = 1

i−

n+1 2



n+1 Ri − : 2

192

S. Anatolyev, G. Kosenok / Economics Letters 105 (2009) 189–192

Theorem 6. The Spearman rank statistic ρ is equal to n + 1 times the OLS slope coefficient in a linear regression of Ri on a constant and observation number i

As a consequence, an OLS-based t test for the null H0 : β = 0 may be used to test for independence of two given random samples.

Ri = α + βi + η;

0 1 s k X X 12 1 2 @ i Ki;j − ksðs + 1Þ A; U = pffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi 2 kðs − 1Þsðs + 1Þ i = 1 j = 1

ð12Þ

with observations running from i + 1 to i + n. As a consequence, an OLS-based t test for the null H0 : β = 0 may be used to test for independence of elements in a given sample, which is often implemented in practice by informally comparing ρ to zero. The pairwise Spearman rank correlation coefficient ρ between two vectors of ranks (R1,…,Rn)' and (S1,…,Sn)' corresponding to two random samples of length n is defined as    Rj − Ri i;j = 1 Sj − Si ρ = rffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffiffi  2 P  2ffi : Pn n S −S R − R j i j i i;j = 1 i;j = 1 Pn

asymptotically distributed as N(0,1) as the number of experts increases, is used to test for homogeneity of products. It is possible to show that U is asymptotically equivalent to an OLS-based t test for H0 : β = 0 in the regression Ki;j = α + βi + ηij ;

Theorem 7. The Spearman rank correlation coefficient ρ is equal the OLS slope coefficient in a linear regression of Rj − Ri on Sj − Si   Rj − Ri = β Sj − Si + η;

Remark 3. In the context of Remark 2, the Umbrella test statistic

ð13Þ

with n2 observations for all possible pairs (i, j) where each index runs from 1 to n. Alternatively, one may switch Sj − Si and Rj − Ri in the regression (13). A constant term may be innocuously introduced into the regression (13).

ð14Þ

with observations running from i,j = 1 to i = s, j = k. References Bowker, A.H., 1948. A test for symmetry in contingency tables. Journal of the American Statistical Association 43, 572–574. Pearson, K., 1900. On the criterion that a given system of deviations from the probable in the case of a correlated system of variables is such that it can be reasonably supposed to have arisen from random sampling. Philosophical Magazine Series 50, 157–175. Stuart, A., 1955. A test for homogeneity of the marginal distributions in a two-way classification. Biometrika 42, 412–416.