Dataanalyse - Hypotesetest - Kursusgang 3 Ege Rubak - - - PowerPoint PPT Presentation

dataanalyse hypotesetest kursusgang 3
SMART_READER_LITE
LIVE PREVIEW

Dataanalyse - Hypotesetest - Kursusgang 3 Ege Rubak - - - PowerPoint PPT Presentation

2 test Recap p -value Two sample tests Other goodness-of-fit checks Dataanalyse - Hypotesetest - Kursusgang 3 Ege Rubak - rubak@math.aau.dk http://www.math.aau.dk/ rubak/teaching/2010/nano4 19. februar 2010 1/20 Dataanalyse -


slide-1
SLIDE 1

1/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Dataanalyse - Hypotesetest - Kursusgang 3

Ege Rubak - rubak@math.aau.dk http://www.math.aau.dk/∼rubak/teaching/2010/nano4

  • 19. februar 2010

Dataanalyse - Kursusgang 3

slide-2
SLIDE 2

2/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Confidence interval for µ with known σ

Sample with (X1, . . . , Xn) independent, Xi ∼ N(µ, σ2).

We have: X ∼ N(µ, σ2/n) and

Z = X − µ

  • σ2/n

∼ N(0, 1).

Therefore:

P

  • zα/2 ≤ Z ≤ z1−α/2
  • = 1 − α,

where zα/2 is the α/2 quantile in N(0, 1). I.e. if α is 0.05 as usual we look up the 2.5% quantile z0.025 = −1.96 and the 97.5% quantile z0.975 = 1.96 in the standard normal distribution N(0, 1).

I.e. the confidence interval is:

[x + zα/2 σ √n; x + z1−α/2 σ √n]

Dataanalyse - Kursusgang 3

slide-3
SLIDE 3

2/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Confidence interval for µ with known σ

Sample with (X1, . . . , Xn) independent, Xi ∼ N(µ, σ2).

We have: X ∼ N(µ, σ2/n) and

Z = X − µ

  • σ2/n

∼ N(0, 1).

Therefore:

P

  • zα/2 ≤ Z ≤ z1−α/2
  • = 1 − α,

where zα/2 is the α/2 quantile in N(0, 1). I.e. if α is 0.05 as usual we look up the 2.5% quantile z0.025 = −1.96 and the 97.5% quantile z0.975 = 1.96 in the standard normal distribution N(0, 1).

I.e. the confidence interval is:

[x + zα/2 σ √n; x + z1−α/2 σ √n]

Dataanalyse - Kursusgang 3

slide-4
SLIDE 4

2/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Confidence interval for µ with known σ

Sample with (X1, . . . , Xn) independent, Xi ∼ N(µ, σ2).

We have: X ∼ N(µ, σ2/n) and

Z = X − µ

  • σ2/n

∼ N(0, 1).

Therefore:

P

  • zα/2 ≤ Z ≤ z1−α/2
  • = 1 − α,

where zα/2 is the α/2 quantile in N(0, 1). I.e. if α is 0.05 as usual we look up the 2.5% quantile z0.025 = −1.96 and the 97.5% quantile z0.975 = 1.96 in the standard normal distribution N(0, 1).

I.e. the confidence interval is:

[x + zα/2 σ √n; x + z1−α/2 σ √n]

Dataanalyse - Kursusgang 3

slide-5
SLIDE 5

3/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Hypothesis test for µ = µ0 with known σ

Suppose we have a hypothesis H0: µ = µ0 (µ0 is a known

number). Assuming H0 is true we can calculate Z = X − µ0

  • σ2/n

∼ N(0, 1) for a given data set. This is called the Z-statistic, and if Z / ∈ [zα/2, z1−α/2] we reject H0.

This is the same as checking µ0 is in the confidence interval

[x + zα/2 σ √n; x + z1−α/2 σ √n]

Sometimes called a z-test (e.g. in MATLAB).

Dataanalyse - Kursusgang 3

slide-6
SLIDE 6

3/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Hypothesis test for µ = µ0 with known σ

Suppose we have a hypothesis H0: µ = µ0 (µ0 is a known

number). Assuming H0 is true we can calculate Z = X − µ0

  • σ2/n

∼ N(0, 1) for a given data set. This is called the Z-statistic, and if Z / ∈ [zα/2, z1−α/2] we reject H0.

This is the same as checking µ0 is in the confidence interval

[x + zα/2 σ √n; x + z1−α/2 σ √n]

Sometimes called a z-test (e.g. in MATLAB).

Dataanalyse - Kursusgang 3

slide-7
SLIDE 7

3/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Hypothesis test for µ = µ0 with known σ

Suppose we have a hypothesis H0: µ = µ0 (µ0 is a known

number). Assuming H0 is true we can calculate Z = X − µ0

  • σ2/n

∼ N(0, 1) for a given data set. This is called the Z-statistic, and if Z / ∈ [zα/2, z1−α/2] we reject H0.

This is the same as checking µ0 is in the confidence interval

[x + zα/2 σ √n; x + z1−α/2 σ √n]

Sometimes called a z-test (e.g. in MATLAB).

Dataanalyse - Kursusgang 3

slide-8
SLIDE 8

4/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

When σ is unknown

Same same, but different! Since σ2 is unknown we use the estimator, S2 ∼

σ2 n−1χ2(n − 1),

and we know T = X − µ

  • S2/n

∼ t(n − 1). (1)

The confidence interval is:

[x + tα/2 s √n; x + t1−α/2 s √n] (2) where tα/2 is the α/2 quantile in t(n − 1).

To test a hypothesis H0: µ = µ0 we insert µ0 in (1) and reject H0

if the T-statistic is outside the interval [tα/2, t1−α/2]. This is the same as checking µ0 is in the confidence interval (2).

Sometimes called a t-test.

Dataanalyse - Kursusgang 3

slide-9
SLIDE 9

4/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

When σ is unknown

Same same, but different! Since σ2 is unknown we use the estimator, S2 ∼

σ2 n−1χ2(n − 1),

and we know T = X − µ

  • S2/n

∼ t(n − 1). (1)

The confidence interval is:

[x + tα/2 s √n; x + t1−α/2 s √n] (2) where tα/2 is the α/2 quantile in t(n − 1).

To test a hypothesis H0: µ = µ0 we insert µ0 in (1) and reject H0

if the T-statistic is outside the interval [tα/2, t1−α/2]. This is the same as checking µ0 is in the confidence interval (2).

Sometimes called a t-test.

Dataanalyse - Kursusgang 3

slide-10
SLIDE 10

4/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

When σ is unknown

Same same, but different! Since σ2 is unknown we use the estimator, S2 ∼

σ2 n−1χ2(n − 1),

and we know T = X − µ

  • S2/n

∼ t(n − 1). (1)

The confidence interval is:

[x + tα/2 s √n; x + t1−α/2 s √n] (2) where tα/2 is the α/2 quantile in t(n − 1).

To test a hypothesis H0: µ = µ0 we insert µ0 in (1) and reject H0

if the T-statistic is outside the interval [tα/2, t1−α/2]. This is the same as checking µ0 is in the confidence interval (2).

Sometimes called a t-test.

Dataanalyse - Kursusgang 3

slide-11
SLIDE 11

4/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

When σ is unknown

Same same, but different! Since σ2 is unknown we use the estimator, S2 ∼

σ2 n−1χ2(n − 1),

and we know T = X − µ

  • S2/n

∼ t(n − 1). (1)

The confidence interval is:

[x + tα/2 s √n; x + t1−α/2 s √n] (2) where tα/2 is the α/2 quantile in t(n − 1).

To test a hypothesis H0: µ = µ0 we insert µ0 in (1) and reject H0

if the T-statistic is outside the interval [tα/2, t1−α/2]. This is the same as checking µ0 is in the confidence interval (2).

Sometimes called a t-test.

Dataanalyse - Kursusgang 3

slide-12
SLIDE 12

4/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

When σ is unknown

Same same, but different! Since σ2 is unknown we use the estimator, S2 ∼

σ2 n−1χ2(n − 1),

and we know T = X − µ

  • S2/n

∼ t(n − 1). (1)

The confidence interval is:

[x + tα/2 s √n; x + t1−α/2 s √n] (2) where tα/2 is the α/2 quantile in t(n − 1).

To test a hypothesis H0: µ = µ0 we insert µ0 in (1) and reject H0

if the T-statistic is outside the interval [tα/2, t1−α/2]. This is the same as checking µ0 is in the confidence interval (2).

Sometimes called a t-test.

Dataanalyse - Kursusgang 3

slide-13
SLIDE 13

5/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Example of hypothesis test

Suppose we measure the height of 100 people

x1 x2 · · · x100 178 cm 183 cm · · · 175 cm and calculate the estimate of the mean x = 178 and the estimate

  • f the variance s2 = 64 (i.e. s = 8).

We want to test H0 : µ = 180 cm at level of significance

α = 0.05.

Since

t = 178 − 180 8/10 = −2.5, t0.025 = −1.98, t0.975 = 1.98 we reject H0.

What about with level of significance α = 0.01? In this case

t0.005 = −2.63, t0.995 = 2.63, and we cannot reject H0.

Dataanalyse - Kursusgang 3

slide-14
SLIDE 14

5/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Example of hypothesis test

Suppose we measure the height of 100 people

x1 x2 · · · x100 178 cm 183 cm · · · 175 cm and calculate the estimate of the mean x = 178 and the estimate

  • f the variance s2 = 64 (i.e. s = 8).

We want to test H0 : µ = 180 cm at level of significance

α = 0.05.

Since

t = 178 − 180 8/10 = −2.5, t0.025 = −1.98, t0.975 = 1.98 we reject H0.

What about with level of significance α = 0.01? In this case

t0.005 = −2.63, t0.995 = 2.63, and we cannot reject H0.

Dataanalyse - Kursusgang 3

slide-15
SLIDE 15

5/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Example of hypothesis test

Suppose we measure the height of 100 people

x1 x2 · · · x100 178 cm 183 cm · · · 175 cm and calculate the estimate of the mean x = 178 and the estimate

  • f the variance s2 = 64 (i.e. s = 8).

We want to test H0 : µ = 180 cm at level of significance

α = 0.05.

Since

t = 178 − 180 8/10 = −2.5, t0.025 = −1.98, t0.975 = 1.98 we reject H0.

What about with level of significance α = 0.01? In this case

t0.005 = −2.63, t0.995 = 2.63, and we cannot reject H0.

Dataanalyse - Kursusgang 3

slide-16
SLIDE 16

5/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Example of hypothesis test

Suppose we measure the height of 100 people

x1 x2 · · · x100 178 cm 183 cm · · · 175 cm and calculate the estimate of the mean x = 178 and the estimate

  • f the variance s2 = 64 (i.e. s = 8).

We want to test H0 : µ = 180 cm at level of significance

α = 0.05.

Since

t = 178 − 180 8/10 = −2.5, t0.025 = −1.98, t0.975 = 1.98 we reject H0.

What about with level of significance α = 0.01? In this case

t0.005 = −2.63, t0.995 = 2.63, and we cannot reject H0.

Dataanalyse - Kursusgang 3

slide-17
SLIDE 17

6/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

We want a number telling how much data confirms the

hypothesis.

Define p-value:

p-value = P(similar dataset supports H0 less | H0 is true) = P estimates from similar data- set are more extreme H0 is true

  • Dataanalyse - Kursusgang 3
slide-18
SLIDE 18

6/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

We want a number telling how much data confirms the

hypothesis.

Define p-value:

p-value = P(similar dataset supports H0 less | H0 is true) = P estimates from similar data- set are more extreme H0 is true

  • Dataanalyse - Kursusgang 3
slide-19
SLIDE 19

6/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

We want a number telling how much data confirms the

hypothesis.

Define p-value:

p-value = P(similar dataset supports H0 less | H0 is true) = P estimates from similar data- set are more extreme H0 is true

  • = P

  estimates from similar dataset are more extreme if we assume H0 is true   remember definition

Dataanalyse - Kursusgang 3

slide-20
SLIDE 20

7/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

If H0 : µ = 180 is true:

T = X − 180

  • S2/n

∼ t(99)

p-value for our observation x = 178, s2 = 64:

p-value = P estimates from similar data- set are more extreme H0 is true

  • NOTE: “more extreme” depends on the hypothesis.

Dataanalyse - Kursusgang 3

slide-21
SLIDE 21

7/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

If H0 : µ = 180 is true:

T = X − 180

  • S2/n

∼ t(99)

p-value for our observation x = 178, s2 = 64:

p-value = P estimates from similar data- set are more extreme H0 is true

  • = P(|T| ≥ 2.5)

0.2 0.4

1 2 3 4 −1 −2 −3 −4

178−180 8/10

extreme

NOTE: “more extreme” depends on the hypothesis.

Dataanalyse - Kursusgang 3

slide-22
SLIDE 22

7/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

If H0 : µ = 180 is true:

T = X − 180

  • S2/n

∼ t(99)

p-value for our observation x = 178, s2 = 64:

p-value = P estimates from similar data- set are more extreme H0 is true

  • = P(|T| ≥ 2.5)

0.2 0.4

1 2 3 4 −1 −2 −3 −4 Area = 0.007 t(99)

NOTE: “more extreme” depends on the hypothesis.

Dataanalyse - Kursusgang 3

slide-23
SLIDE 23

7/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

If H0 : µ = 180 is true:

T = X − 180

  • S2/n

∼ t(99)

p-value for our observation x = 178, s2 = 64:

p-value = P estimates from similar data- set are more extreme H0 is true

  • = P(|T| ≥ 2.5) = 1.4%

0.2 0.4

1 2 3 4 −1 −2 −3 −4 Area = 0.007 t(99)

NOTE: “more extreme” depends on the hypothesis.

Dataanalyse - Kursusgang 3

slide-24
SLIDE 24

7/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

p-value

If H0 : µ ≥ 180 is true:

T = X − 180

  • S2/n

∼ t(99)

p-value for our observation x = 178, s2 = 64:

p-value = P estimates from similar data- set are more extreme H0 is true

  • = 1.4% = P(T ≤ −2.5) = 0.7%

0.2 0.4

1 2 3 4 −1 −2 −3 −4 t(99) extreme

NOTE: “more extreme” depends on the hypothesis.

Dataanalyse - Kursusgang 3

slide-25
SLIDE 25

8/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Fatcs about p-value

Small p-value (≤ 0.05): We reject hypothesis. Large p-value: We cannot reject hypothesis. The larger the p-value, the more faith we have in our hypothesis. p-value (much) greater than 0.05 ⇒ estimate is (well) inside 95

% confidence interval.

Dataanalyse - Kursusgang 3

slide-26
SLIDE 26

9/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Paired samples

Data:

Sample 1: x1,1 x1,2 . . . x1,n Sample 2: x2,1 x2,2 . . . x2,n

Assumptions:

◮ Observations occur in pairs, (x1,i, x2,i). ◮ Each sample consists of independent, normally distributed

  • bservations, Xi,j ∼ N(µi, σ2

i ). Note:

◮ The two samples do not need to be independent. ◮ Is often used in before-after experiments.

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

Dataanalyse - Kursusgang 3

slide-27
SLIDE 27

9/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Paired samples

Data:

Sample 1: x1,1 x1,2 . . . x1,n Sample 2: x2,1 x2,2 . . . x2,n

Assumptions:

◮ Observations occur in pairs, (x1,i, x2,i). ◮ Each sample consists of independent, normally distributed

  • bservations, Xi,j ∼ N(µi, σ2

i ). Note:

◮ The two samples do not need to be independent. ◮ Is often used in before-after experiments.

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

Dataanalyse - Kursusgang 3

slide-28
SLIDE 28

10/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Paired samples

Data:

Sample 1 : x1,1 x1,2 . . . x1,n Sample 2 : x2,1 x2,2 . . . x2,n Difference: d1 d2 . . . dn di = x1,i − x2,i

We have

di ∼∼ N(µ1 − µ2

, σ2

∗)

don’t worry about this one

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

  • H0 : µ1 − µ2 = 0

H1 : µ1 − µ2 = 0

Use usual t-test to test if δ = 0.

Dataanalyse - Kursusgang 3

slide-29
SLIDE 29

10/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Paired samples

Data:

Sample 1 : x1,1 x1,2 . . . x1,n Sample 2 : x2,1 x2,2 . . . x2,n Difference: d1 d2 . . . dn di = x1,i − x2,i

We have

di ∼∼ N(µ1 − µ2

, σ2

∗)

don’t worry about this one

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

  • H0 : µ1 − µ2 = 0

H1 : µ1 − µ2 = 0

Use usual t-test to test if δ = 0.

Dataanalyse - Kursusgang 3

slide-30
SLIDE 30

10/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Paired samples

Data:

Sample 1 : x1,1 x1,2 . . . x1,n Sample 2 : x2,1 x2,2 . . . x2,n Difference: d1 d2 . . . dn di = x1,i − x2,i

We have

di ∼∼ N(µ1 − µ2

, σ2

∗)

don’t worry about this one

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

  • H0 : µ1 − µ2 = 0

H1 : µ1 − µ2 = 0

  • H0 : δ = 0

H1 : δ = 0

Use usual t-test to test if δ = 0.

Dataanalyse - Kursusgang 3

slide-31
SLIDE 31

10/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Paired samples

Data:

Sample 1 : x1,1 x1,2 . . . x1,n Sample 2 : x2,1 x2,2 . . . x2,n Difference: d1 d2 . . . dn di = x1,i − x2,i

We have

di ∼∼ N(µ1 − µ2

, σ2

∗)

don’t worry about this one

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

  • H0 : µ1 − µ2 = 0

H1 : µ1 − µ2 = 0

  • H0 : δ = 0

H1 : δ = 0

Use usual t-test to test if δ = 0.

Dataanalyse - Kursusgang 3

slide-32
SLIDE 32

11/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Unpaired samples

Data:

Sample 1: x1,1 x1,2 . . . x1,n1 Sample 2: x2,1 x2,2 . . . x2,n2

Assumptions:

◮ Each sample consists of independent normally distributed

  • bservations, Xi,j ∼ N(µi, σ2

i ).

◮ The two samples are independent.

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

  • H0 : µ1 − µ2 = 0

H1 : µ1 − µ2 = 0

Dataanalyse - Kursusgang 3

slide-33
SLIDE 33

11/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Unpaired samples

Data:

Sample 1: x1,1 x1,2 . . . x1,n1 Sample 2: x2,1 x2,2 . . . x2,n2

Assumptions:

◮ Each sample consists of independent normally distributed

  • bservations, Xi,j ∼ N(µi, σ2

i ).

◮ The two samples are independent.

Hypothesis:

H0 : µ1 = µ2 H1 : µ1 = µ2

  • H0 : µ1 − µ2 = 0

H1 : µ1 − µ2 = 0

Dataanalyse - Kursusgang 3

slide-34
SLIDE 34

12/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Procedure:

◮ Calculate

x1,· = 1 n1

n1

  • j=1

x1,j

  • g

x2,· = 1 n2

n2

  • j=1

x2,j

◮ Is x1,· − x2,· close to 0 in appropriate distribution? ◮ Assumptions gives “appropriate distribution”:

T = x1,· − x2,·

  • σx 1,·−x2,·

∼ t-distributed.

σx1,·−x2,· and degrees of freedom both depend on the variances!

Dataanalyse - Kursusgang 3

slide-35
SLIDE 35

12/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Procedure:

◮ Calculate

x1,· = 1 n1

n1

  • j=1

x1,j

  • g

x2,· = 1 n2

n2

  • j=1

x2,j

◮ Is x1,· − x2,· close to 0 in appropriate distribution? ◮ Assumptions gives “appropriate distribution”:

T = x1,· − x2,·

  • σx 1,·−x2,·

∼ t-distributed.

σx1,·−x2,· and degrees of freedom both depend on the variances!

Dataanalyse - Kursusgang 3

slide-36
SLIDE 36

12/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Procedure:

◮ Calculate

x1,· = 1 n1

n1

  • j=1

x1,j

  • g

x2,· = 1 n2

n2

  • j=1

x2,j

◮ Is x1,· − x2,· close to 0 in appropriate distribution? ◮ Assumptions gives “appropriate distribution”:

T = x1,· − x2,·

  • σx 1,·−x2,·

∼ t-distributed.

σx1,·−x2,· and degrees of freedom both depend on the variances!

Dataanalyse - Kursusgang 3

slide-37
SLIDE 37

13/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Paired vs independent test

We must know from experiment, if samples are paired.

◮ Same number of observations, doesn’t necessarily mean we can

use paired test!

◮ If possible, we prefer paired test. Dataanalyse - Kursusgang 3

slide-38
SLIDE 38

14/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test for goodness-of-fit

Data:

Total Class 1 2 . . . k Observation

  • 1
  • 2

. . .

  • k

n Expected

  • bservation

e1 e2 . . . ek n

Hypothesis:

H0 : Data follows certain distribution H1 : Data doesn’t follow this distribution

Under H0: o’s ≈ e’s. Test statistic:

χ2 =

k

  • i=1

(oi − ei)2 ei ∼ χ2(k − m − 1)

Large values of χ2 are critical for H0.

Dataanalyse - Kursusgang 3

slide-39
SLIDE 39

14/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test for goodness-of-fit

Data:

Total Class 1 2 . . . k Observation

  • 1
  • 2

. . .

  • k

n Expected

  • bservation

e1 e2 . . . ek n

Hypothesis:

H0 : Data follows certain distribution H1 : Data doesn’t follow this distribution

Under H0: o’s ≈ e’s. Test statistic:

χ2 =

k

  • i=1

(oi − ei)2 ei ∼ χ2(k − m − 1)

Large values of χ2 are critical for H0.

Dataanalyse - Kursusgang 3

slide-40
SLIDE 40

14/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test for goodness-of-fit

Data:

Total Class 1 2 . . . k Observation

  • 1
  • 2

. . .

  • k

n Expected

  • bservation

e1 e2 . . . ek n

Hypothesis:

H0 : Data follows certain distribution H1 : Data doesn’t follow this distribution

Under H0: o’s ≈ e’s. Test statistic:

χ2 =

k

  • i=1

(oi − ei)2 ei ∼ χ2(k − m − 1)

Large values of χ2 are critical for H0.

Dataanalyse - Kursusgang 3

slide-41
SLIDE 41

14/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test for goodness-of-fit

Data:

Total Class 1 2 . . . k Observation

  • 1
  • 2

. . .

  • k

n Expected

  • bservation

e1 e2 . . . ek n

Hypothesis:

H0 : Data follows certain distribution H1 : Data doesn’t follow this distribution

Under H0: o’s ≈ e’s. Test statistic:

χ2 =

k

  • i=1

(oi − ei)2 ei ∼ χ2(k − m − 1)

Large values of χ2 are critical for H0.

Dataanalyse - Kursusgang 3

slide-42
SLIDE 42

14/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test for goodness-of-fit

Data:

Total Class 1 2 . . . k Observation

  • 1
  • 2

. . .

  • k

n Expected

  • bservation

e1 e2 . . . ek n

Hypothesis:

H0 : Data follows certain distribution H1 : Data doesn’t follow this distribution

Under H0: o’s ≈ e’s. Test statistic:

  • num. of parameters,

estimated

χ2 =

k

  • i=1

(oi − ei)2 ei ∼ χ2(k − m − 1)

Large values of χ2 are critical for H0.

Dataanalyse - Kursusgang 3

slide-43
SLIDE 43

14/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test for goodness-of-fit

Data:

Total Class 1 2 . . . k Observation

  • 1
  • 2

. . .

  • k

n Expected

  • bservation

e1 e2 . . . ek n

Hypothesis:

H0 : Data follows certain distribution H1 : Data doesn’t follow this distribution

Under H0: o’s ≈ e’s. Test statistic:

  • num. of parameters,

estimated

χ2 =

k

  • i=1

(oi − ei)2 ei ∼ χ2(k − m − 1)

Large values of χ2 are critical for H0.

Dataanalyse - Kursusgang 3

slide-44
SLIDE 44

14/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test for goodness-of-fit

Data:

Total Class 1 2 . . . k Observation

  • 1
  • 2

. . .

  • k

n Expected

  • bservation

e1 e2 . . . ek n

Hypothesis:

H0 : Data follows certain distribution H1 : Data doesn’t follow this distribution

Under H0: o’s ≈ e’s. Test statistic:

  • num. of parameters,

estimated

χ2 =

k

  • i=1

(oi − ei)2 ei ∼ χ2(k − m − 1)

Large values of χ2 are critical for H0.

Dataanalyse - Kursusgang 3

slide-45
SLIDE 45

15/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test example

A die is rolled 600 times:

1 2 3 4 5 6 119 117 98 89 96 81

Hypothesis:

H0 : The die is fair H1 : The die is not fair

Under H0 the expected table is:

1 2 3 4 5 6 100 100 100 100 100 100

Calculate test statistic:

χ2 = (119 − 100)2 100 + (117 − 100)2 100 + · · · + (81 − 100)2 100 ≈ 11.5

Calculate p-value in χ2(5) distribution = 4.2%

Dataanalyse - Kursusgang 3

slide-46
SLIDE 46

15/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test example

A die is rolled 600 times:

1 2 3 4 5 6 119 117 98 89 96 81

Hypothesis:

H0 : The die is fair H1 : The die is not fair

Under H0 the expected table is:

1 2 3 4 5 6 100 100 100 100 100 100

Calculate test statistic:

χ2 = (119 − 100)2 100 + (117 − 100)2 100 + · · · + (81 − 100)2 100 ≈ 11.5

Calculate p-value in χ2(5) distribution = 4.2%

Dataanalyse - Kursusgang 3

slide-47
SLIDE 47

15/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test example

A die is rolled 600 times:

1 2 3 4 5 6 119 117 98 89 96 81

Hypothesis:

H0 : The die is fair H1 : The die is not fair

Under H0 the expected table is:

1 2 3 4 5 6 100 100 100 100 100 100

Calculate test statistic:

χ2 = (119 − 100)2 100 + (117 − 100)2 100 + · · · + (81 − 100)2 100 ≈ 11.5

Calculate p-value in χ2(5) distribution = 4.2%

Dataanalyse - Kursusgang 3

slide-48
SLIDE 48

15/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

χ2 test example

A die is rolled 600 times:

1 2 3 4 5 6 119 117 98 89 96 81

Hypothesis:

H0 : The die is fair H1 : The die is not fair

Under H0 the expected table is:

1 2 3 4 5 6 100 100 100 100 100 100

Calculate test statistic:

χ2 = (119 − 100)2 100 + (117 − 100)2 100 + · · · + (81 − 100)2 100 ≈ 11.5

Calculate p-value in χ2(5) distribution = 4.2%

Dataanalyse - Kursusgang 3

slide-49
SLIDE 49

16/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Remarks about χ2 tests

NOTE: The χ2 is an approximate distribution for the test statistic

and the approximation is typically not good if any expected count is less than 5.

“χ2 test” cover several tests:

◮ Test distribution. ◮ Test for independence between observations in table. ◮ Test for homogenity in table.

Common features:

◮ Data is in table. ◮ Test statistic:

(observed − expected)2 expected .

◮ Test statistic is χ2 distributed. Dataanalyse - Kursusgang 3

slide-50
SLIDE 50

16/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Remarks about χ2 tests

NOTE: The χ2 is an approximate distribution for the test statistic

and the approximation is typically not good if any expected count is less than 5.

“χ2 test” cover several tests:

◮ Test distribution. ◮ Test for independence between observations in table. ◮ Test for homogenity in table.

Common features:

◮ Data is in table. ◮ Test statistic:

(observed − expected)2 expected .

◮ Test statistic is χ2 distributed. Dataanalyse - Kursusgang 3

slide-51
SLIDE 51

17/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Histogram

We observe n values x1, x2, . . . , xn. Histogram of data:

◮ Divide the x axis into equally sized intervals. ◮ Make a bar in each interval that represents the number of

  • bservations in the interval.

1 2 3 4

1 2 3 −1 −2 −3 Observations:

  • 2.9, -2.9, -2.5, -2.1,
  • 1.5, -0.75, -0.5,
  • 0.25, 0.5, 0.5, 2, 2.5,

2.6

Dataanalyse - Kursusgang 3

slide-52
SLIDE 52

18/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Problems with histograms

With few observations it can be hard to recognize the distribution The intervals should be chosen apropriately (rarely a serious

problem)

−2 1 2 3 2 4 6 8 −3 −1 1 3 1 2 3 4 5 −2.5 −1.0 0.5 1 2 3 4 −3 −1 1 2 1 2 3 4 5 −2 1 0.0 1.0 2.0 3.0 −2 1 2 3 2 4 6

20 normal distributed observations in each histogram.

Dataanalyse - Kursusgang 3

slide-53
SLIDE 53

18/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Problems with histograms

With few observations it can be hard to recognize the distribution The intervals should be chosen apropriately (rarely a serious

problem)

−3 −1 1 2 20 60 −3 −1 1 3 40 80 −3 −1 1 3 40 80 −3 −1 1 3 20 60 −4 −2 2 40 80 −3 −1 1 3 20 60

200 normal distributed observations in each histogram.

Dataanalyse - Kursusgang 3

slide-54
SLIDE 54

18/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Problems with histograms

With few observations it can be hard to recognize the distribution The intervals should be chosen apropriately (rarely a serious

problem)

−4 2 4 4 8 12 −1.5 0.0 1.0 0.0 1.0 2.0 −2.0 −0.5 1.0 1 2 3 4 5

20 normal distributed observations in each histogram.

Dataanalyse - Kursusgang 3

slide-55
SLIDE 55

18/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

Problems with histograms

With few observations it can be hard to recognize the distribution The intervals should be chosen apropriately (rarely a serious

problem)

−4 2 4 40 80 −2 −1 1 2 2 4 6 8 −2 1 2 20 40

200 normal distributed observations in each histogram.

Dataanalyse - Kursusgang 3

slide-56
SLIDE 56

19/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

QQ-plot

QQ-plot: 2. method to explore distribution of data. Idea: Compare empirical distribution function with a theoretical

distribution function.

−1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0 0.0 0.2 0.4 0.6 0.8 1.0

20 normal distributed observations.

Problem: It is difficult to compare graphs, that are not straight

lines.

New idea: Compare empirical quantiles with theoretical quantiles.

Dataanalyse - Kursusgang 3

slide-57
SLIDE 57

19/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

QQ-plot

QQ-plot: 2. method to explore distribution of data. Idea: Compare empirical distribution function with a theoretical

distribution function.

−1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0 0.0 0.2 0.4 0.6 0.8 1.0

20 normal distributed observations.

Problem: It is difficult to compare graphs, that are not straight

lines.

New idea: Compare empirical quantiles with theoretical quantiles.

Dataanalyse - Kursusgang 3

slide-58
SLIDE 58

19/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

QQ-plot

QQ-plot: 2. method to explore distribution of data. Idea: Compare empirical distribution function with a theoretical

distribution function.

−1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0 0.0 0.2 0.4 0.6 0.8 1.0

20 normal distributed observations.

Problem: It is difficult to compare graphs, that are not straight

lines.

New idea: Compare empirical quantiles with theoretical quantiles.

Dataanalyse - Kursusgang 3

slide-59
SLIDE 59

19/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

QQ-plot

QQ-plot: 2. method to explore distribution of data. Idea: Compare empirical distribution function with a theoretical

distribution function.

−1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 2.0 0.0 0.2 0.4 0.6 0.8 1.0 Observed Value

2 1

  • 1
  • 2

Expected Normal Value

2 1

  • 1
  • 2

20 normal distributed observations.

Problem: It is difficult to compare graphs, that are not straight

lines.

New idea: Compare empirical quantiles with theoretical quantiles.

Dataanalyse - Kursusgang 3

slide-60
SLIDE 60

20/20

Recap p-value Two sample tests χ2 test Other goodness-of-fit checks

QQ-plots

Facts about QQ-plots

◮ If the proposed distribution is good, we get a linear pattern. ◮ As the number of observations increase, the variability decreases. ◮ The points are dependent, so they have a tendency to twist

around the line.

Examples of QQ-plots

Observed Value

3 2 1

  • 1
  • 2
  • 3

Expected Normal Value

3 2 1

  • 1
  • 2
  • 3

Observed Value

1.5 1.0 0.5 0.0

  • 0.5

Expected Normal Value

1.5 1.0 0.5 0.0

  • 0.5

Observed Value

4 3 2 1

  • 1

Expected Normal Value

3 2 1

  • 1

Normal distributed data Uniformly distributed data Lognormal distributed data

Dataanalyse - Kursusgang 3