Friedman Test and Categorical Data Analysis

Friedman Test

  • Non-parametric equivalent of the One-way repeated measures ANOVA and an extension of the Wilcoxon signed-rank test.

  • Used for comparing 3+ dependent groups.

  • Requires 3+ observations/measurements for each "participant."

Main Assumptions of Repeated Measures ANOVA

  • Normality of residuals

  • Sphericity

  • If one or more of these assumptions fail, consider the Fredman test.

  • Used for continuous or ordinal data.

Hypotheses
  • H0H_0: All groups belong to the same distribution.

  • HaH_a: At least one group belongs to a different distribution.

  • If the distributions of the groups are of the same shape, the hypotheses are:

    • H0H_0: The medians of all groups are equal.

    • HaH_a: At least one group has a median not equal to the others.

Method

  1. State H0H_0

  2. By construction, each group will have the same number of entries, denoted as nn, and let kk be the number of groups.

  3. Rank the data for each participant across groups from 1 to kk (Potential ranks: 1,2,,k1, 2, …, k).

  4. If we have repeated values across groups, assign a tied rank, which is the mean of the potential ranks of these data (Actual ranks).

  5. Sum the ranks for each group, denoted by RiR_i for the ithi^{th} group.

Test Statistic

  • The test statistic is given by:
    F=[12nk(k+1)<em>i=1kR</em>i2]3n(k+1)F = [\frac{12}{nk(k+1)} \sum<em>{i=1}^{k} R</em>i^2] - 3n(k+1)

  • If we have tied ranks, we use the corrected test statistic:
    F<em>corrected=(k1)[</em>i=1kR<em>i2C</em>F]<em>i=1n</em>j=1kr<em>ij2C</em>FF<em>{corrected} = \frac{(k-1) [\sum</em>{i=1}^{k} R<em>i^2 - C</em>F]}{\sum<em>{i=1}^{n} \sum</em>{j=1}^{k} r<em>{ij}^2 - C</em>F}
    where C<em>F=nk(k+1)24C<em>F = \frac{n k (k+1)^2}{4} and r</em>ijr</em>{ij} is the rank corresponding to group ii in participant jj.

  • For k=3k = 3 and k=4k = 4, and n=2,3,4n = 2, 3, 4, we evaluate the test statistic by using tables.

  • If FF/F{corrected} > F{crit}, we reject H0H_0. Otherwise, we use χ2\chi^2 tables with k1k-1 degrees of freedom.

  • If FF/F{corrected} > \chi^2{crit}, we reject H0H_0.

Post Hoc Tests

  • Wilcoxon signed-rank tests on all pairs. However, this tends to inflate the Type I error rate.

  • To control this, we use the following Bonferroni correction.

  • Nemenyi post hoc tests.

Categorical Data Analysis

  • Categorical data take nominal values, i.e., no intrinsic ordering (e.g., eye color).

  • We address cases where both predictor and outcome variables are categorical (e.g., association between personality and color preference).

  • We cannot compare means with categorical data.

  • Consider frequencies instead.

Assumptions for Categorical Variables

  • Independence: Each person, item, etc., only contributes to one cell in the frequency table.

  • Expected Frequencies:

    • For χ2\chi^2 goodness-of-fit test and 2 x 2 tables, no expected frequencies should be < 5.

    • In longer tables, all expected frequencies > 1 and no more than 20% of expected frequencies < 5.

The χ2\chi^2 Tests

  • These can be used for goodness-of-fit and to test for association between categorical variables.

The Chi-Square (χ2\chi^2) Distribution

  • Let Z<em>1,,Z</em>kN(0,1)Z<em>1, …, Z</em>k \sim N(0, 1), then
    S=<em>i=1kZ</em>i2χv2S = \sum<em>{i=1}^{k} Z</em>i^2 \sim \chi^2_v

  • SS has a probability density function (pdf):
    Pv(x)={12v/2Γ(v/2)xv/21ex/2,amp;xgt;0 0,amp;otherwiseP_v(x) = \begin{cases} \frac{1}{2^{v/2} \Gamma(v/2)} x^{v/2 - 1} e^{-x/2}, &amp; x &gt; 0 \ 0, &amp; \text{otherwise} \end{cases}
    where Γ\Gamma denotes the Gamma function.

  • For nNn \in \mathbb{N}, Γ(n)=(n1)!\Gamma(n) = (n-1)!

  • For zCz \in \mathbb{C}, \Re(z) > 0,
    Γ(z):=0xz1exdx\Gamma(z) := \int_{0}^{\infty} x^{z-1} e^{-x} dx

Properties

  • χ2\chi^2 distributions have a positive skew.

  • As vv \rightarrow \infty, χ2\chi^2 becomes symmetrical.

  • Let Xχv2X \sim \chi^2_v, then
    E(X)=vE(X) = v
    Var(X)=2vVar(X) = 2v
    Xv2vN(0,1)\frac{X - v}{\sqrt{2v}} \sim N(0, 1)

Calculations
  • If Xχ2<em>vX \sim \chi^2<em>v, then E(X)=xP</em>v(x)dx=vE(X) = \int x P</em>v(x) dx = v
    Var(X)=E(X2)[E(X)]2=2vVar(X) = E(X^2) - [E(X)]^2 = 2v
    E(X2)=x2Pv(x)dx=(v+2)vE(X^2) = \int x^2 P_v(x) dx = (v+2)v

  • If {X<em>i}</em>i=1N\lbrace X<em>i \rbrace</em>{i=1}^{N} is a sequence of independent χ2\chi^2 random variables with d.f. v<em>1,v</em>2,,v<em>Nv<em>1, v</em>2, …, v<em>N respectively, then </em>i=1NX<em>iχ2</em><em>i=1Nv</em>i\sum</em>{i=1}^{N} X<em>i \sim \chi^2</em>{\sum<em>{i=1}^{N} v</em>i}

χ2\chi^2 Goodness-of-Fit Test

  • Used to test if categorical data are as expected, or if it fits a certain distribution.

Example
  • Exam Mark classification: A, B, C, D, E

  • Exam Board: expectation of frequencies in each class.

  • Exam Results: test to compare with expected frequencies to determine any potential issues.

Test Statistic
  • The test statistic is:
    X2=<em>i=1K(O</em>iE<em>i)2E</em>iX^2 = \sum<em>{i=1}^{K} \frac{(O</em>i - E<em>i)^2}{E</em>i}
    where K is the number of categories.

  • OiO_i are the observed frequencies.

  • EiE_i are the expected frequencies.

Evaluation
  • Evaluate X2X^2 using χ2\chi^2 tables with K1K-1 degrees of freedom.

  • Hypotheses:

    • H0:X2=0H_0: X^2 = 0 (no difference between observed and expected frequencies).

    • H1:X20H_1: X^2 \neq 0 (a significant difference between the observed and expected frequencies).

  • If X^2 > \chi^2{crit}, we reject H</em>0H</em>0.