Mathematical Statistics
Anna Janicka
Lecture XIII, 20.05.2019
ANOVA
NON-PARAMETRIC TESTS
Plan for Today
1. Analysis of variance tests (ANOVA) 2. Goodness-of-fit tests
Kolmogorov test
Kolmogorov-Smirnov (two samples) Kolmogorov-Lilliefors
chi-squared goodness-of-fit
3. Tests of independence
chi-squared test
Tests for more than two populations
A naive approach:
pairwise tests for all pairs But:
in this case, the type I error is higher than
the significance level assumed for each
simple test...
More populations
Assume we have k samples:
, and
all X
i,jare independent (i=1,...,k, j=1,.., n
i) X
i,j~N(m
i, σ
2)
we do not know m
1, m
2, ..., m
k, nor σ
2let n=n
1+n
2+...+n
knk
k k
k
n n
X X
X
X X
X
X X
X
, 2
, 1
,
, 2 2
, 2 1
, 2
, 1 2
, 1 1
, 1
,..., ,
...
, ,...,
,
, ,...,
,
2 1
Test of the Analysis of Variance (ANOVA) for significance level α
H
0: µ
1= µ
2=... = µ
kH
1: ¬ H
0(i.e. not all µ
iare equal) A LR test; we get a test statistic:
with critical region
for k=2 the ANOVA is equivalent to the two-sample t-test.
) ,
1 (
~ ) /(
) (
) 1 /(
) (
1 1
2 ,
1
2
k n
k F k
n X
X
k X
X F
kn
i
n
j i j i
k
i i i
i
− −
−
−
−
= −
∑ ∑
∑
= =
=
∑
∑ ∑
∑
= = = = = == k
i i i
k i
n
j i j
n
j i j
i
i n X
X n X n
n X
X i i
1
1 1 ,
1 ,
1 , 1
1
)}
, 1 (
) ( :
{
* x F x F
1k n k
K = >
−α− −
ANOVA – interpretation
we have
– between group variance estimator
– within group variance estimator
∑ ∑
= = −−
k i
n
j i j i
i X X
k
n 1 1
2
, )
1 (
Sum of Squares (SS)
Sum of Squares Between (SSB)
Sum of Squares Within (SSW)
∑
= −−
k
i ni Xi X
k 1
)2
1 ( 1
∑ ∑ ∑
∑ ∑
= = − = k= − + = = −i
k i
n
j i j i
i i
k i
n
j i j
i
i X X n X X X X
1 1 1
2 ,
2
1 1
2
, ) ( ) ( )
(
ANOVA test – table
source of
variability sum of squares degrees of freedom
value of the test statistic F between
groups SSB k-1 –
within groups SSW n-k –
total SS n-1 F
ANOVA test – example
Yearly chocolate consumption in three cities: A, B, C based on random samples of n
A= 8, n
B= 10, n
C= 9 consumers. Does consumption depend on the city?
α=0.01
→ reject H
0(equality of means), consumption depends on city
A B C
sample mean 11 10 7
sample variance 3.5 2.8 3
61 . 5 )
24 . 2 (
and
31 . 24 12
/ 7 . 73
2 / 63 . 75
7 . 73 8
3 9 8 . 2 7 5 . 3
63 . 75 9
) 3 . 9 7 ( 10 )
3 . 9 10 ( 8 ) 3 . 9 11 (
3 . 9 )
9 7 10 10
8 11 (
99 . 0
2 2
2 27
1
≈
≈
=
=
⋅ +
⋅ +
⋅
=
=
⋅
− +
⋅
− +
⋅
−
=
=
⋅ +
⋅ +
⋅
=
F F
SSW SSB
X
ANOVA test – table – example
source of
variability sum of squares degrees of freedom
value of the test statistic F between
groups 75.63 2 –
within groups 73.7 24 –
total 149.33 26 12.31
Non-parametric tests
we check whether a random variable fits a given distribution (goodness-of-fit tests).
we check whether random variables have the same distribution
we check whether variables/characteristics
are independet (test of independence)
Kolmogorov goodness-of-fit test
Model: X
1, X
2, ..., X
nare an IID sample from distribution with CDF F.
H
0: F = F
0 (F0 specified)H
1: ¬ H
0 (i.e. the CDF is different)If F
0is continuous, we use the statistic
where
and F
n(t) – n-th empirical CDF
} ,
max{
| ) ( )
(
|
sup
∈−
0=
+ −=
t R n n nn
F t F t D D
D
n x i
F D
x n F
D
n i ni
i n n i n i n1
) (
max
, ) (
max
1,..., 0 : 1,..., 0 :−
−
=
−
=
= − =+
Kolmogorov goodness-of-fit test – cont.
The test: we reject H
0when:
D
n> c( α , n)
for a critical value c( α , n).
Theorem. If H
0is true, the distribution of D
ndoes not depend on F
0.
Problem: This distribution needs tables, for each different n.
Theorem. In the limit
the approximation may be used for n ≥ 100
∑
+∞=−∞−
∞
→
= −
→
≤
kd k k
n
d
nK d e
D n
P ( ) ( ) ( 1 )
2 2 2Kolmogorov goodness-of-fit test – cont. (2)
Tables of the asymptotic distribution K(d)
1-
α
0.8 0.9 0.95 0.99quantile of
K(d) 1,07 1,22 1,36 1,63
c(n,
α
)for n≥100 1,07/ n 1,22/ n 1,36/ n 1,63 / n
Kolmogorov goodness-of-fit test – example
Does the sample
0.4085 0.5267 0.3751 0.8329 0.0846 0.8306 0.6264 0.3086 0.3662 0.7952 come from a uniform distribution U(0,1)?
Source: W. Niemiro
Kolmogorov goodness-of-fit test – example cont.
D
n= 0.2086 c(10; 0.9) = 0.369
→ no grounds to reject the null hypothesis that the distribution is uniform
Xi:10 (i-1)/10 i/10 i/10 - F(Xi:10) F(Xi:10)-i/10
0.0846 0 0.1 0.0154 0.0846
0.3086 0.1 0.2 -0.1086 0.2086
0.3662 0.2 0.3 -0.0662 0.1662
0.3751 0.3 0.4 0.0249 0.0751
0.4085 0.4 0.5 0.0915 0.0085
0.5267 0.5 0.6 0.0733 0.0267
0.6264 0.6 0.7 0.0736 0.0264
0.7952 0.7 0.8 0.0048 0.0952
0.8306 0.8 0.9 0.0694 0.0306
0.8329 0.9 1 0.1671 -0.0671
Kolmogorov-Smirnov test of equality of distributions
Model: X
1, X
2, ..., X
nare an IID sample from a distribution with CDF F, Y
1, Y
2, ..., Y
mare an IID sample from a distribution with CDF G.
H
0: F = G
H
1: ¬ H
0 (i.e. the CDF functions/distributions differ)If F (and G) is continuous, we test with
where F
n(t) – n-th empirical CDF for the first sample, and G
m(t) – m-th empirical CDF for the second sample
| ) ( )
(
|
,
sup F t G t
D
n m=
t∈R n−
mKolmogorov-Smirnov test of equality of distributions – cont.
The test: we reject H
0if:
D
n,m> c( α , n, m) for a critical value c( α , n, m).
Theorem. If H
0is true, the distribution of D
n,mdoes not depend on F (or G).
Theorem. In the limit
the approximation is OK for n,m ≥ 100
∑
+∞=−∞−
∞
→
∞
+
≤
→ → = −
k
d k k
m m n
m n n
nm
D d K d e
P (
,)
,( ) ( 1 )
2 2 2Kolmogorov-Lilliefors goodness-of-fit test Model: X
1, X
2, ..., X
nare an IID sample from a distribution with CDF F.
H
0: F is a CDF of a normal distribution
(with unknown parameters)
H
1: ¬ H
0 (i.e. the distribution is not normal)We test with where
and
} ,
max{
+ −=
n nn
D D
D
n z i
D n z
D
n i ni
i n i n i1
max
,
max
1,..., 1,...,−
−
=
−
=
= − =+
−
Φ
= S
X z
iX
i:n2 1 1
2 1 1
1
∑
= , = −∑
= ( − )= n
i i
n n
i i
n X S X X
X
Kolmogorov-Lilliefors goodness-of-fit test – cont.
The test: we reject H
0if:
D
n> D
n( α )
for a critical value D
n( α ).
Theorem. If H
0is true, the distribution of D
ndoes not depend on the parameters of the normal distribution.
Problem: we need tables and do not know the analytical form of this distribution...
Used for small samples (n ≤30), when it performs
better than the chi-squared test
Kolmogorov-Lilliefors goodness-of-fit test – critical values
Source: H. Lilliefors
Chi-squared goodness-of-fit test
Model: X
1, X
2, ..., X
nare an IID sample from a discrete distribution with k values (1, ..., k).
H
0: the distribution probabilities are equal to
H
1: ¬ H
0 (i.e. the distribution is different)If the results of the experiment are
where N
idenotes the number of outcomes equal to i:
i 1 2 3 ... k
P(X=i) p1 p2 p3 ... pk
i 1 2 3 ... k
Ni N1 N2 N3 ... Nk
∑
= == n
j X i
i j
N 11
value labels
Chi-squared goodness-of-fit test – cont.
General form of the test:
here:
Theorem. If H
0is true, the distribution of the χ
2statistic converges to a chi-squared distr with k-1 degrees of freedom χ
2(k-1) for n→∞
Procedure: we reject H
0if χ
2> c, where c= χ
21-α(k-1) is a quantile of rank 1- α from a chi- squared distr with k-1 degrees of freedom
∑
= expected value
value) expected
- value observed
( 2
χ2
∑
==
i i k i
i np
np
N 2
1
2 ( - )
χ
Chi-squared goodness-of-fit test – example
Is a die symmetric? For a significance level α =0.05
n=150 tosses. Results:
H
0: (N
1, N
2, N
3, N
4, N
5, N
6)
~Mult(150, 1/6, 1/6, 1/6, 1/6, 1/6, 1/6) H
1: ¬ H
0i 1 2 3 4 5 6
Ni 15 27 36 17 26 29
24 . 25 12
) 25 29
( 25
) 25 26
( 25
) 25 17
( 25
) 25 36
( 25
) 25 27
( 25
) 25 15
( 2 2 2 2 2 2
2 − =
− +
− +
− +
− +
− + χ =
7 . 11 )
5
2
(
05 . 0
1−
≈
χ
→ we reject H0.Source: W. Niemiro
Chi-squared goodness-of-fit test – distribution with an unknown parameter.
Model: X
1, X
2, ..., X
nare an IID sample from a discrete distribution with k values (1, ..., k).
H
0: distribution probabilities are equal to
where θ is an unknown parameter of dimension d.
H
1: ¬ H
0 (i.e. the distribution is different)i 1 2 3 ... k
P(X=i) p1(
θ
) p2(θ
) p3(θ
) ... pk(θ
)Chi-squared goodness-of-fit test – distribution with an unknown parameter, cont.
Test statistics are constructed like in the
previous case, with the expected values calculated using ML estimators of the
parameter θ . Only the number of degrees of freedom changes:
Theorem. If H
0is true, the distribution of the χ
2statistic converges to a chi-squared
distribution with k-d-1 degrees of freedom
χ
2(k-d-1) for n→∞
Chi-squared goodness-of-fit test – version for continuous distributions
Kolmogorov tests are better, but the chi- squared test may also be used
Model: X
1, X
2, ..., X
nare an IID sample from a continuous distribution.
H
0: The distribution is given by F
H
1: ¬ H
0 (i.e. the distribution is different)It suffices to divide the range of values of the random variable into classes and count the
observations. The expected values are known
(result from F).Then: the chi-squared test.
Chi-squared goodness-of-fit test – practical notes
The test should be used for large samples The expected counts can’t be too small (<5). If they are smaller, observations should be grouped.
The classes in the „continuous” version
may be chosen arbitrarily, but it is best if
the theoretical probabilities are balanced.
Chi-squared test of independence
Model: (X
1,Y
1), ..., (X
n,Y
n) are an IID sample from a two-dimensional distribution with r*s values
(denoted by the set {1, ..., r} × {1, ..., s}).
Let the theoretical distribution be
Denote
We want to veryfy independence of X and Y:
H
0:
H
1: ¬ H
0s j
r i
j Y
i X
P
p
ij= ( = , = ) = 1 ,..., = 1 ,...,
∑
∑
= • =•
= =
ri ij
j s
j ij
i
p p p
p
1,
1r j
s i
p p
p
ij=
i•∗
•j= 1 ,..., , = 1 ,...,
Chi-squared test of independence – cont.
The empirical distribution may be summarized by a table (so-called contingency table, or
crosstab)
i \ j 1 2 ... s Ni•
1 N11 N12 N1s N1•
2 N21 N22 N2s N2•
...
r Nr1 Nr2 Nrs Nr•
N•j N•1 N•2 N•s n
Chi-squared test of independence – cont. (2)
This is a special case of a goodness-of-fit test with (r-1) + (s-1) parameters to be
estimated:
The test statistic:
has a chi-squared distribution with (r-1)(s-1) degrees of freedom (if H
0is true)
∑ ∑
= =•
•
•
−
•=
ri
s j
j i
j i
ij
n N
N
n N
N N
1 1
2 2
/
)
/
χ (
Chi-squared test of independence – example
We verify independence of political and
musical preferences, for signif. level α =0.05
Source: W. Niemiro
Support X Do not support X Total
Listen to jazz 25 10 35
Listen to rock 20 20 40
Listen to hip-hop 15 10 25
Total 60 40 100
57 . 100 3
/ 25
* 40
) 100 / 25
* 40 10
( 100
/ 40
* 40
) 100 / 40
* 40 20
( 100
/ 35
* 40
) 100 / 35
* 40 10
(
100 / 25
* 60
) 100 / 25
* 60 15
( 100
/ 40
* 60
) 100 / 40
* 60 20
( 100
/ 35
* 60
) 100 / 35
* 60 25
(
2 2
2
2 2
2 2
− ≈
− +
− + +
+ − + −
= − χ
99 . 5 )
2 ( ))
1 3
)(
1 2
((
02.952 05 . 0
1−
− − = χ ≈
χ
→ no grounds to reject H0.