• Nie Znaleziono Wyników

1. Analysis of variance tests (ANOVA) 2. Goodness-of-fit tests

N/A
N/A
Protected

Academic year: 2021

Share "1. Analysis of variance tests (ANOVA) 2. Goodness-of-fit tests"

Copied!
32
0
0

Pełen tekst

(1)

Mathematical Statistics

Anna Janicka

Lecture XIII, 20.05.2019

ANOVA

NON-PARAMETRIC TESTS

(2)

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

(3)

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...

(4)

More populations

Assume we have k samples:

, and

all X

i,j

are 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 σ

2

let n=n

1

+n

2

+...+n

k

nk

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

(5)

Test of the Analysis of Variance (ANOVA) for significance level α

H

0

: µ

1

= µ

2

=... = µ

k

H

1

: ¬ H

0

(i.e. not all µ

i

are 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

k

n

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

1

k n k

K = >

α

− −

(6)

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

, ) ( ) ( )

(

(7)

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

(8)

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

(9)

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

(10)

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)

(11)

Kolmogorov goodness-of-fit test

Model: X

1

, X

2

, ..., X

n

are 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

0

is continuous, we use the statistic

where

and F

n

(t) – n-th empirical CDF

} ,

max{

| ) ( )

(

|

sup

0

=

+

=

t R n n n

n

F t F t D D

D

n x i

F D

x n F

D

n i n

i

i n n i n i n

1

) (

max

, ) (

max

1,..., 0 : 1,..., 0 :

=

=

= =

+

(12)

Kolmogorov goodness-of-fit test – cont.

The test: we reject H

0

when:

D

n

> c( α , n)

for a critical value c( α , n).

Theorem. If H

0

is true, the distribution of D

n

does 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

+∞=−∞

 = −

 →

k

d k k

n

d

n

K d e

D n

P ( ) ( ) ( 1 )

2 2 2

(13)

Kolmogorov goodness-of-fit test – cont. (2)

Tables of the asymptotic distribution K(d)

1-

α

0.8 0.9 0.95 0.99

quantile 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

(14)

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

(15)

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

(16)

Kolmogorov-Smirnov test of equality of distributions

Model: X

1

, X

2

, ..., X

n

are an IID sample from a distribution with CDF F, Y

1

, Y

2

, ..., Y

m

are 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

=

tR n

m

(17)

Kolmogorov-Smirnov test of equality of distributions – cont.

The test: we reject H

0

if:

D

n,m

> c( α , n, m) for a critical value c( α , n, m).

Theorem. If H

0

is true, the distribution of D

n,m

does 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 2

(18)

Kolmogorov-Lilliefors goodness-of-fit test Model: X

1

, X

2

, ..., X

n

are 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 n

n

D D

D

n z i

D n z

D

n i n

i

i n i n i

1

max

,

max

1,..., 1,...,

=

=

= =

+

 

 

 −

Φ

= S

X z

i

X

i:n

2 1 1

2 1 1

1

= , =

= ( )

= n

i i

n n

i i

n X S X X

X

(19)

Kolmogorov-Lilliefors goodness-of-fit test – cont.

The test: we reject H

0

if:

D

n

> D

n

( α )

for a critical value D

n

( α ).

Theorem. If H

0

is true, the distribution of D

n

does 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

(20)

Kolmogorov-Lilliefors goodness-of-fit test – critical values

Source: H. Lilliefors

(21)

Chi-squared goodness-of-fit test

Model: X

1

, X

2

, ..., X

n

are 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

i

denotes 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

(22)

Chi-squared goodness-of-fit test – cont.

General form of the test:

here:

Theorem. If H

0

is true, the distribution of the χ

2

statistic converges to a chi-squared distr with k-1 degrees of freedom χ

2

(k-1) for n→∞

Procedure: we reject H

0

if χ

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 ( - )

χ

(23)

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

0

i 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

(24)

Chi-squared goodness-of-fit test – distribution with an unknown parameter.

Model: X

1

, X

2

, ..., X

n

are 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(

θ

)

(25)

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

0

is true, the distribution of the χ

2

statistic converges to a chi-squared

distribution with k-d-1 degrees of freedom

χ

2

(k-d-1) for n→∞

(26)

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

n

are 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.

(27)

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.

(28)

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

0

s j

r i

j Y

i X

P

p

ij

= ( = , = ) = 1 ,..., = 1 ,...,

= =

= =

r

i ij

j s

j ij

i

p p p

p

1

,

1

r j

s i

p p

p

ij

=

i

j

= 1 ,..., , = 1 ,...,

(29)

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

(30)

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

0

is true)

∑ ∑

= =

=

r

i

s j

j i

j i

ij

n N

N

n N

N N

1 1

2 2

/

)

/

χ (

(31)

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.95

2 05 . 0

1

− − = χ ≈

χ

→ no grounds to reject H0.

(32)

Cytaty

Powiązane dokumenty

observation X, when the alternative is true” to the “highest chance of obtaining observation X, when the null is true”; we reject the null. hypothesis in favor of the alternative

A shop assistant believes that orange juice is bought three times more frequently than apple juice, while the latter is bought twice as frequently as tomato juice.. The consequences

Therefore, they are commonly crushed into concrete gravel (used as road filling); the reinforcement steel is recycled into new steel products at EoL. The Finnish company, Peikko,

witamin¦ E, a lekarze opiekuj¡cy si¦ pacjentami po operacji, którzy podejmuj¡ decyzje o zako«czeniu rekonwalescencji nie wiedz¡ którzy pacjenci nale»¡ do próby. x jak

Poniższa tabela przedstawia liczby prosiąt zdrowych i chorych na nosoryjówke w zależności od tego, czy matka była zdrowa, czy też chora.. Zbadać, czy istnieje zależność

Results for simulation are compiled in table 3, which shows the resulting values of equivalent (von Misses) stress, contact pressure and plastic deformation of the samples surface

One hundred people were interviewed outside a chocolate shop to nd out which avor of chocolate cream they preferred... Therefore, we reject the null

One hundred people were interviewed outside a chocolate shop to nd out which avor of chocolate cream they preferred... Therefore, we reject the null