Em que nível um teste


15

JUSTIFICATIVA: Pule com segurança - está aqui para referência e para legitimar a pergunta.

A abertura deste artigo diz:

"O famoso teste de contingência qui-quadrado de Karl Pearson é derivado de outra estatística, chamada estatística z, com base na distribuição Normal. As versões mais simples do χ2 podem ser matematicamente idênticas aos testes z equivalentes. Os testes produzem o mesmo resultado em todas as circunstâncias. Para todos os efeitos, "qui-quadrado" pode ser chamado de "z-quadrado". Os valores críticos de χ2 para um grau de liberdade são o quadrado dos valores críticos correspondentes de z ".

Isso foi afirmado várias vezes no currículo ( aqui , aqui , aqui e outros).

E, de fato, podemos provar que χ1df2 é equivalente aX2comXN(0,1):

Digamos que XN(0,1) e que Y=X2 e encontre a densidade de Y usando o método cdf :

p(Yy)=p(X2y)=p(yxy). O problema é que não podemos integrar de forma estreita a densidade da distribuição normal. Mas podemos expressá-lo:

FX(y)=FX(y)FX(y).
Tomando o derivado:

fX(y)=FX(y)12y+FX(y)12y.

Como os valores do normal são simétricos:pdf

. Igualando isso aopdfdo normal (agora oxnopdfseráfX(y)=FX(y)1ypdfxpdf a ser conectado aoe - x 2y partes do normalpdf); e lembrando-se de incluir1ex22pdf no final:1y

fX(y)=FX(y)1y=12πey21y=12πey2y121

Compare com o pdf do quadrado chi:

fX(x)=12ν/2Γ(ν2)ex2xν21

Desde , para1df, derivamos exatamente opdfdo quadrado de chi.Γ(1/2)=π1pdf

Além disso, se chamamos a função prop.test()em R, estamos invocando o mesmo teste do como se decidíssemos .χ2chisq.test()

A QUESTÃO:

Então, eu entendo todos esses pontos, mas ainda não sei como eles se aplicam à implementação real desses dois testes por dois motivos:

  1. Um teste z não é quadrado.

  2. As estatísticas de teste reais são completamente diferentes:

O valor da estatística de teste para um χ2 é:

ondeχ2=i=1n(OiEi)2Ei=Ni=1npi(Oi/Npipi)2

χ2 = Pearson's cumulative test statistic, which asymptotically approaches a χ2 distribution. Oi = the number of observations of type i; N = total number of observations; Ei = Npi = the expected (theoretical) frequency of type i, asserted by the null hypothesis that the fraction of type i in the population is pi; n = the number of cells in the table.

On the other hand, the test statistic for a z-test is:

Z=x1n1x2n2p(1p)(1/n1+1/n2) with p=x1+x2n1+n2, where x1 and x2 are the number of "successes", over the number of subjects in each one of the levels of the categorical variables, i.e. n1 and n2.

This formula seems to rely on the binomial distribution.

These two tests statistics are clearly different, and result in different results for the actual test statistics, as well as for the p-values: 5.8481 for the χ2 and 2.4183 for the z-test, where 2.41832=5.84817 (thank you, @mark999). The p-value for the χ2 test is 0.01559, while for the z-test is 0.0077. The difference explained by two-tailed versus one-tailed: 0.01559/2=0.007795 (thank you @amoeba).

So at what level do we say that they are one and the same?


But these are two identical tests. Z squared is the chi-square statistic. Let you have 2x2 frequency table where columns are the two groups and the rows are "success" and "failure". Then the so called expected frequencies of the chi-square test in a given column is the weighted (by the groups' N) average column (group) profile multiplied by that group's N. Thus, it comes that chi-square tests the deviation of each of the two groups profiles from this average group profile, - which is equivalent to testing the groups' profiles difference from each other, the z-test of proportions.
ttnphns

In the example on the last hyperlink the χ2 is almost the square of the z-test statistic, but not quite, and the p-values are different. Also, when you look at the formulas for the rest statistics above, is it truly immediate that they are identical? Or even one the square of the other?
Antoni Parellada

2
In chisq.test(), have you tried using correct=FALSE?
mark999

1
Indeed, Antoni. Both tests exist with or without the Yates. Could it be that you compute one with but the other without it?
ttnphns

1
Thank you! You were (predictably) correct. With the Yates correction off, one is just the square of the other. I edited the question accordingly, although a bit fast. I still would like to prove algebraically that both test statistics are the same (or one the square of the other), and understand why the p-values are different.
Antoni Parellada

Respostas:


12

Let us have a 2x2 frequency table where columns are two groups of respondents and rows are the two responses "Yes" and "No". And we've turned the frequencies into the proportions within group, i.e. into the vertical profiles:

      Gr1   Gr2  Total
Yes   p1    p2     p
No    q1    q2     q
      --------------
     100%  100%   100%
      n1    n2     N

The usual (not Yates corrected) χ2 of this table, after you substitute proportions instead of frequencies in its formula, looks like this:

n1[(p1p)2p+(q1q)2q]+n2[(p2p)2p+(q2q)2q]=n1(p1p)2+n2(p2p)2pq.

Remember that p=n1p1+n2p2n1+n2, the element of the weighted average profile of the two profiles (p1,q1) and (p2,q2), and plug it in the formula, to obtain

...=(p1p2)2(n12n2+n1n22)pqN2

Divide both numerator and denominator by the (n12n2+n1n22) and get

(p1p2)2pq(1/n1+1/n2)=Z2,

the squared z-statistic of the z-test of proportions for "Yes" response.

Thus, the 2x2 homogeneity Chi-square statistic (and test) is equivalent to the z-test of two proportions. The so called expected frequencies computed in the chi-square test in a given column is the weighted (by the group n) average vertical profile (i.e. the profile of the "average group") multiplied by that group's n. Thus, it comes out that chi-square tests the deviation of each of the two groups profiles from this average group profile, - which is equivalent to testing the groups' profiles difference from each other, which is the z-test of proportions.

This is one demonstration of a link between a variables association measure (chi-square) and a group difference measure (z-test statistic). Attribute associations and group differences are (often) the two facets of the same thing.


(Showing the expansion in the first line above, By @Antoni's request):

n1[(p1p)2p+(q1q)2q]+n2[(p2p)2p+(q2q)2q]=n1(p1p)2qpq+n1(q1q)2ppq+n2(p2p)2qpq+n2(q2q)2ppq=n1(p1p)2(1p)+n1(1p11+p)2p+n2(p2p)2(1p)+n2(1p21+p)2ppq=n1(p1p)2(1p)+n1(pp1)2p+n2(p2p)2(1p)+n2(pp2)2ppq=[n1(p1p)2][(1p)+p]+[n2(p2p)2][(1p)+p]pq=n1(p1p)2+n2(p2p)2pq.


@ttnphs This is great! Any chance you could clarify the intermediate step in the first equation (χ2) formula - I don't see how the q's go away after the equal sign.
Antoni Parellada

@ttnphs When I expand it I get n1[(p1p)2p+(q1q)2q]+n2[(p2p)2p+(q2q)2q]=n1(q(p2+p(2p12q1+p12)+p(q2+q12)pq)+n2(q(p2+p(2p22q2)+p22)+p(q2+q22)pq)
Antoni Parellada

@ttnphs ... Or some reference so it's less work to type the latex... And I'll promptly and happily 'accept' the answer...
Antoni Parellada

@Antoni, expansion inserted.
ttnphns

@ttnphns Awesome!
Antoni Parellada
Ao utilizar nosso site, você reconhece que leu e compreendeu nossa Política de Cookies e nossa Política de Privacidade.
Licensed under cc by-sa 3.0 with attribution required.