Probability and Statistics for Computer Science How - - PowerPoint PPT Presentation

probability and statistics
SMART_READER_LITE
LIVE PREVIEW

Probability and Statistics for Computer Science How - - PowerPoint PPT Presentation

Probability and Statistics for Computer Science How are these connected? X ( N ) = 1 N ( X 1 + X 2 + ... + X N ) 2 exp ( ( x ) 2 1 p ( x ) = ) 2 2


slide-1
SLIDE 1

ì ¡

Probability ¡and ¡Statistics ¡ for ¡Computer ¡Science ¡ ¡

How ¡are ¡these ¡connected? ¡

Hongye ¡Liu, ¡Teaching ¡Assistant ¡Prof, ¡CS361, ¡UIUC, ¡10.15.2019 ¡ Credit: ¡wikipedia ¡

p(x) = 1 σ √ 2π exp(−(x − µ)2 2σ2 )

μ σ ¡ σ ¡ X(N) = 1 N (X1 + X2 + ... + XN)

slide-2
SLIDE 2

Last ¡Lecture ¡

✺ Review ¡of ¡sample ¡mean ¡and ¡

confidence ¡interval ¡

✺ Bootstrap ¡simulaNon ¡of ¡other ¡

sample ¡staNsNc ¡

✺ Hypothesis ¡test ¡

slide-3
SLIDE 3

Quantile ¡

✺ QuanNles ¡give ¡

a ¡measure ¡of ¡ locaNon, ¡the ¡ median ¡is ¡the ¡ 0.5 ¡quanNle ¡

Probability ¡density ¡ Credit: ¡ ¡

  • J. ¡Orloff ¡et ¡al ¡

¡ ¡ ¡ CumulaNve ¡Probability ¡ ¡ ¡(CDF) ¡ ¡

slide-4
SLIDE 4

Quantile ¡

✺ QuanNles ¡are ¡corresponding ¡to ¡

percenNles ¡using ¡percentage ¡in ¡the ¡ case ¡of ¡data ¡set. ¡

✺ Median ¡is ¡0.5 ¡quanNle ¡and ¡50 ¡

percenNle ¡

slide-5
SLIDE 5
  • Q. ¡ ¡

Histogram of sample_median

sample_median Frequency 250 300 350 400 450 500 550 500 1000 1500 2000 2500 3000

✺ Given ¡the ¡histogram ¡of ¡

the ¡bootstrap ¡samples’ ¡ staNsNc, ¡we ¡want ¡to ¡get ¡ its ¡95% ¡confidence ¡

  • interval. ¡Where ¡is ¡the ¡

le^ ¡side ¡threshold? ¡ ¡ ¡ ¡ ¡ ¡A. ¡0.025 ¡quanNle ¡ ¡ ¡ ¡ ¡ ¡B. ¡0.05 ¡quanNle ¡ ¡ ¡ ¡ ¡ ¡C. ¡0.975 ¡quanNle ¡

slide-6
SLIDE 6
slide-7
SLIDE 7
  • Q. ¡ ¡

Histogram of sample_median

sample_median Frequency 250 300 350 400 450 500 550 500 1000 1500 2000 2500 3000

✺ Given ¡the ¡histogram ¡of ¡

the ¡bootstrap ¡samples’ ¡ staNsNc, ¡we ¡want ¡to ¡get ¡ its ¡95% ¡confidence ¡

  • interval. ¡Where ¡is ¡the ¡

le^ ¡side ¡threshold? ¡ ¡ ¡ ¡ ¡ ¡A. ¡0.025 ¡quanNle ¡ ¡ ¡ ¡ ¡ ¡B. ¡0.05 ¡quanNle ¡ ¡ ¡ ¡ ¡ ¡C. ¡0.975 ¡quanNle ¡

slide-8
SLIDE 8

Contents ¡

✺ Review ¡of ¡variance, ¡sample ¡mean ¡ ✺ Sum ¡and ¡difference ¡between ¡

variables ¡of ¡normal ¡distribuNons ¡

✺ Hypothesis ¡test ¡of ¡equality ¡of ¡two ¡

sample ¡means ¡

✺ Chi-­‑square ¡test ¡

slide-9
SLIDE 9

A ¡review ¡about ¡variance ¡

✺ When ¡X ¡and ¡Y ¡are ¡independent ¡random ¡variables, ¡we ¡

have ¡

✺ If ¡X ¡and ¡Y ¡are ¡independent ¡IID ¡random ¡draws ¡from ¡the ¡

same ¡distribuNon, ¡X= ¡X1, ¡Y= ¡X2 ¡ ¡

var[X + Y ] = var[X] + var[Y ]

var[X1 + X2] = var[X1] + var[X2] = 2var[X1] var[2 · X1] = 4var[X1]

var[X1 + X2] = var[2 · X1]

slide-10
SLIDE 10

Review ¡of ¡standard ¡deviation ¡

✺ For ¡a ¡random ¡variable ¡X ¡ ¡ ✺ It’s ¡the ¡same ¡for ¡a ¡data ¡set ¡{x} ¡

std[X] = σ =

  • var[X]
  • r

var[X] = std[X]2 = σ2 std({x}) = σ =

  • var({x})
  • r

var({x}) = std({x})2 = σ2

slide-11
SLIDE 11

Review ¡of ¡sample ¡mean ¡

✺ The ¡sample ¡mean ¡is ¡the ¡average ¡of ¡N ¡IID ¡ ¡

draws: ¡

✺ By ¡linearity ¡of ¡the ¡expectaNon ¡and ¡the ¡fact ¡

the ¡draws ¡of ¡sample ¡are ¡IID ¡ ¡ ¡ ¡

X(N) = 1 N (X1 + X2 + ... + XN)

Random ¡ ¡ variable! ¡

E[X(N)] = popmean({x})

slide-12
SLIDE 12

Standard ¡deviation ¡of ¡sample ¡mean ¡ is ¡called ¡stderr ¡

✺ By ¡the ¡variance ¡of ¡the ¡sum ¡of ¡independent ¡

random ¡variables ¡and ¡the ¡scaling ¡property ¡of ¡ variance, ¡we ¡know ¡the ¡variance ¡of ¡sample ¡mean ¡is: ¡ ¡ ¡

✺ We ¡call ¡the ¡standard ¡deviaNon ¡of ¡sample ¡mean ¡

stderr ¡and ¡so ¡we ¡have: ¡ ¡ ¡

var[X(N)] = popvar({x}) N

stderr =

  • var[X(N)] = popstd({x})

√ N

** ¡ ** ¡

slide-13
SLIDE 13

Review ¡of ¡sample ¡mean ¡

✺ When ¡N ¡is ¡very ¡large, ¡according ¡to ¡the ¡Central ¡

Limit ¡Theorem, ¡sample ¡mean ¡is ¡approaching ¡a ¡ normal ¡distribuNon. ¡And ¡this ¡normal ¡density ¡ has ¡μ ¡≈ ¡mean ¡of ¡the ¡realized ¡sample ¡and ¡σ ¡≈ ¡

  • stderr. ¡

✺ When ¡we ¡don’t ¡know ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡we ¡

esNmate ¡it ¡with ¡the ¡following: ¡ ¡ ¡

stderr({x}) ≃ stdunbiased({x}) √ N

popstd({x})

** ¡

slide-14
SLIDE 14
  • Q. ¡ ¡

✺ Among ¡the ¡students ¡in ¡CS361, ¡I ¡randomly ¡sampled ¡

HW1, ¡HW2 ¡and ¡HW3 ¡grades ¡from ¡random ¡16 ¡students ¡ for ¡each ¡homework, ¡and ¡assume ¡students’ ¡ performance ¡in ¡HW1, ¡HW2 ¡and ¡HW3 ¡are ¡independent. ¡ Suppose ¡I ¡found ¡the ¡populaNon ¡variances ¡of ¡the ¡ grades ¡of ¡HW1, ¡HW2, ¡and ¡HW3 ¡are ¡9, ¡4, ¡4, ¡what ¡is ¡the ¡ variance ¡of ¡the ¡sum ¡of ¡the ¡three ¡sample ¡means? ¡

  • A. ¡7/4 ¡ ¡ ¡ ¡ ¡

¡ ¡B. ¡7/8 ¡ ¡

  • C. ¡ ¡17/16

¡D. ¡ ¡7/16 ¡ ¡

slide-15
SLIDE 15
slide-16
SLIDE 16
  • Q. ¡ ¡

✺ Among ¡the ¡students ¡in ¡CS361, ¡I ¡randomly ¡sampled ¡

HW1, ¡HW2 ¡and ¡HW3 ¡grades ¡from ¡random ¡16 ¡students ¡ for ¡each ¡homework, ¡and ¡assume ¡students’ ¡ performance ¡in ¡HW1, ¡HW2 ¡and ¡HW3 ¡are ¡independent. ¡ Suppose ¡I ¡found ¡the ¡populaNon ¡variances ¡of ¡the ¡ grades ¡of ¡HW1, ¡HW2, ¡and ¡HW3 ¡are ¡9, ¡4, ¡4, ¡what ¡is ¡the ¡ variance ¡of ¡the ¡sum ¡of ¡the ¡three ¡sample ¡means? ¡

  • A. ¡7/4 ¡ ¡ ¡ ¡ ¡

¡ ¡B. ¡7/8 ¡ ¡

  • C. ¡ ¡17/16

¡D. ¡ ¡7/16 ¡ ¡

slide-17
SLIDE 17

Calculate ¡the ¡standard ¡error ¡for ¡ sample ¡mean ¡

✺ The ¡unbiased ¡esNmate ¡of ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡is ¡

defined ¡as ¡

✺ So ¡the ¡standard ¡error ¡is ¡esNmated ¡as ¡

stdunbiased({x}) =

  • 1

N − 1

  • xi∈ sample

(xi − mean({xi}))2

stderr({x}) = std[X(N)] = popsd({x}) √ N = stdunbiased({x}) √ N

popsd({x})

¡ ¡ ¡ ¡

≃ stdunbiased({x}) √ N

slide-18
SLIDE 18

Interpreting ¡the ¡standard ¡error ¡

Credit: ¡ ¡ wikipedia ¡

99.7% ¡ 95% ¡ 68% ¡ PopulaNon ¡ ¡ mean ¡ μ+Standard ¡error ¡ Probability ¡ distribuNon ¡

  • f ¡sample ¡

mean ¡tends ¡ normal ¡ when ¡N ¡is ¡ large ¡

slide-19
SLIDE 19

Confidence ¡intervals ¡when ¡N ¡is ¡large ¡

✺ For ¡about ¡68% ¡of ¡realized ¡sample ¡means ¡ ✺ For ¡about ¡95% ¡of ¡realized ¡sample ¡means ¡ ✺ For ¡about ¡99.7% ¡of ¡realized ¡sample ¡means ¡

mean({x}) − stderr({x}) ≤ popmean({x}) ≤ mean({x}) + stderr({x})

mean({x})−2·stderr({x}) ≤ popmean({x}) ≤ mean({x})+2·stderr({x}) mean({x})−3·stderr({x}) ≤ popmean({x}) ≤ mean({x})+3·stderr({x})

slide-20
SLIDE 20

What ¡does ¡95% ¡Confidence ¡interval ¡ mean? ¡

✺ For ¡95% ¡of ¡the ¡realized ¡sample ¡means, ¡if ¡you ¡

construct ¡the ¡confidence ¡interval ¡this ¡way, ¡the ¡ populaNon ¡mean ¡will ¡lie ¡within ¡such ¡interval. ¡

✺ It ¡does ¡not ¡mean ¡the ¡populaNon ¡mean ¡lies ¡in ¡the ¡

interval ¡with ¡probability ¡95% ¡

slide-21
SLIDE 21
slide-22
SLIDE 22

Contents ¡

✺ Review ¡of ¡variance, ¡sample ¡mean ¡ ✺ Sum ¡and ¡difference ¡between ¡

variables ¡of ¡normal ¡distribuEons ¡

✺ Hypothesis ¡test ¡of ¡equality ¡of ¡two ¡

sample ¡means ¡

✺ Chi-­‑square ¡test ¡

slide-23
SLIDE 23

We ¡are ¡interested ¡in ¡comparing ¡ sample ¡means ¡

✺ Are ¡the ¡average ¡

daily ¡body ¡ temperature ¡of ¡the ¡ two ¡beavers ¡the ¡ same? ¡

✺ We ¡need ¡to ¡model ¡

the ¡difference ¡ between ¡two ¡ sample ¡means ¡

¡ ¡ ¡

  • vs. ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

slide-24
SLIDE 24

How ¡do ¡we ¡model ¡the ¡difference ¡ between ¡two ¡samples ¡means? ¡

✺ We ¡know ¡when ¡the ¡sample ¡size ¡N ¡is ¡large, ¡

the ¡sample ¡mean ¡random ¡variable ¡ approaches ¡normal. ¡

✺ So ¡our ¡problem ¡became ¡finding ¡the ¡model ¡

  • f ¡the ¡difference ¡between ¡two ¡normally ¡

distributed ¡random ¡variables. ¡

slide-25
SLIDE 25

Background: ¡sum ¡of ¡independent ¡normals ¡ ¡

✺ We ¡know ¡ ✺ The ¡sum ¡of ¡X1 ¡and ¡X2 ¡is ¡sNll ¡normal ¡(proof ¡

  • mined) ¡

X1 ∼ normal(µ1, σ2

1)

X2 ∼ normal(µ2, σ2

2)

X1 + X2 ∼ normal(µ1 + µ2, σ2

1 + σ2 2)

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

? ¡

slide-26
SLIDE 26

Background: ¡sum ¡of ¡independent ¡normals ¡ ¡

✺ We ¡know ¡ ✺ So ¡ ✺ By ¡the ¡linearity ¡of ¡expected ¡value ¡and ¡the ¡

sum ¡rule ¡of ¡variance ¡of ¡the ¡sum ¡of ¡two ¡ independent ¡random ¡variables. ¡

X1 ∼ normal(µ1, σ2

1)

X2 ∼ normal(µ2, σ2

2)

X1 + X2 ∼ normal(µ1 + µ2, σ2

1 + σ2 2)

slide-27
SLIDE 27

Background: ¡sum ¡of ¡independent ¡normals ¡ ¡

✺ We ¡know ¡ ¡ ✺ So ¡ ✺ By ¡properNes: ¡ ¡

X1 ∼ normal(µ1, σ2

1)

X2 ∼ normal(µ2, σ2

2)

X1 + X2 ∼ normal(µ1 + µ2, σ2

1 + σ2 2)

E[X1 + X2] = E[X1] + E[X2]

var[X1 + X2] = var[X1] + var[X2]

slide-28
SLIDE 28

Difference ¡of ¡independent ¡normals ¡ ¡

✺ We ¡know ¡ ✺ The ¡difference ¡of ¡X1 ¡and ¡X2 ¡is ¡sNll ¡normal ¡

(proof ¡omined) ¡

X1 ∼ normal(µ1, σ2

1)

X2 ∼ normal(µ2, σ2

2)

X1 − X2 ∼ ? ¡

slide-29
SLIDE 29

Difference ¡of ¡independent ¡normals ¡ ¡

✺ We ¡know ¡ ✺ So ¡

✺ By ¡the ¡linearity ¡of ¡expected ¡value ¡and ¡the ¡sum ¡

rule ¡of ¡variance ¡of ¡the ¡sum ¡of ¡two ¡independent ¡ random ¡variables ¡and ¡the ¡scaling ¡property ¡of ¡

  • variance. ¡

X1 ∼ normal(µ1, σ2

1)

X2 ∼ normal(µ2, σ2

2)

X1 − X2 ∼ normal(µ1 − µ2, σ2

1 + σ2 2)

** ¡

slide-30
SLIDE 30

Derivation ¡of ¡the ¡mean ¡and ¡variance ¡of ¡ difference ¡of ¡independent ¡normals ¡ ¡

✺ Because ¡ ¡ ¡ ¡

E[X1 − X2] = E[X1] − E[X2] = µ1 − µ2 var[X1 − X2] = var[X1 + (−X2)] = var[X1] + var[−X2] = var[X1] + var[X2] = σ2

1 + σ2 2 ¡ ¡ ¡ ¡ ¡ ¡ ¡

slide-31
SLIDE 31

Derivation ¡of ¡the ¡mean ¡and ¡variance ¡of ¡ difference ¡of ¡independent ¡normals ¡ ¡

✺ Because ¡ ¡ ¡ ¡

E[X1 − X2] = E[X1] − E[X2] = µ1 − µ2 var[X1 − X2] = var[X1 + (−X2)] = var[X1] + var[−X2] = var[X1] + var[X2] = σ2

1 + σ2 2 ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

slide-32
SLIDE 32

Derivation ¡of ¡the ¡mean ¡and ¡variance ¡of ¡ difference ¡of ¡independent ¡normals ¡ ¡

✺ Because ¡ ¡ ¡ ¡

E[X1 − X2] = E[X1] − E[X2] = µ1 − µ2 var[X1 − X2] = var[X1 + (−X2)] = var[X1] + var[−X2] = var[X1] + var[X2] = σ2

1 + σ2 2 ¡ ¡ ¡ ¡ ¡ ¡ ¡

slide-33
SLIDE 33

Derivation ¡of ¡the ¡mean ¡and ¡variance ¡of ¡ difference ¡of ¡independent ¡normals ¡ ¡

✺ Because ¡ ¡ ¡ ¡

E[X1 − X2] = E[X1] − E[X2] = µ1 − µ2 var[X1 − X2] = var[X1 + (−X2)] = var[X1] + var[−X2] = var[X1] + var[X2] = σ2

1 + σ2 2 ¡ ¡ ¡ ¡ ¡ ¡ ¡

var[c · X2] = c2var[X2]

slide-34
SLIDE 34

Derivation ¡of ¡the ¡mean ¡and ¡variance ¡of ¡ difference ¡of ¡independent ¡normals ¡ ¡

✺ Because ¡ ¡ ¡ ¡

E[X1 − X2] = E[X1] − E[X2] = µ1 − µ2 var[X1 − X2] = var[X1 + (−X2)] = var[X1] + var[−X2] = var[X1] + var[X2] = σ2

1 + σ2 2

slide-35
SLIDE 35

Derivation ¡of ¡the ¡mean ¡and ¡variance ¡of ¡ difference ¡of ¡independent ¡normals ¡ ¡

✺ Because ¡ ¡

✺ ¡ ¡

E[X1 − X2] = E[X1] − E[X2] = µ1 − µ2 var[X1 − X2] = var[X1 + (−X2)] = var[X1] + var[−X2] = var[X1] + var[X2] = σ2

1 + σ2 2

X1 − X2 ∼ normal(µ1 − µ2, σ2

1 + σ2 2)

** ¡

slide-36
SLIDE 36

Now ¡we ¡are ¡ready ¡to ¡check ¡the ¡ differences ¡between ¡sample ¡means ¡

✺ Because ¡sample ¡means ¡are ¡roughly ¡normal ¡

when ¡N ¡is ¡large. ¡

¡ ¡

X1 − X2 ∼ normal(µ1 − µ2, σ2

1 + σ2 2)

** ¡

slide-37
SLIDE 37

Contents ¡

✺ Review ¡of ¡variance, ¡sample ¡mean ¡ ✺ Sum ¡and ¡difference ¡between ¡

variables ¡of ¡normal ¡distribuNons ¡

✺ Hypothesis ¡test ¡of ¡equality ¡of ¡two ¡

sample ¡means ¡

✺ Chi-­‑square ¡test ¡

slide-38
SLIDE 38

The ¡difference ¡between ¡two ¡sample ¡means ¡

✺ Suppose ¡we ¡draw ¡samples ¡from ¡two ¡populaNons ¡ ¡ ¡ ¡ ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡and ¡ ¡ ¡

✺ From ¡a ¡sample ¡of ¡size ¡kx ¡from ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡we ¡get ¡sample ¡

mean ¡ ¡

✺ From ¡a ¡sample ¡of ¡size ¡ky from ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡, ¡we ¡get ¡sample ¡

mean ¡

{x} {y} {x} {y}

X(kx) Y (ky)

slide-39
SLIDE 39

The ¡difference ¡between ¡two ¡sample ¡means ¡

D = X(kx) − Y (ky)

✺ Define ¡random ¡variable ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

as ¡the ¡difference ¡between ¡the ¡sample ¡ means ¡

✺ If ¡we ¡hypothesize ¡that ¡popmean({x}) ¡= ¡

popmean({y}), ¡then ¡

E[D] = E[X(kx)] − E[Y (ky)] = 0

slide-40
SLIDE 40

Standard ¡error ¡of ¡the ¡difference ¡between ¡two ¡ sample ¡means ¡

✺ Recall ¡the ¡standard ¡error ¡is ¡the ¡standard ¡

deviaNon ¡of ¡a ¡sample ¡mean ¡

✺ By ¡the ¡property ¡of ¡variance ¡of ¡the ¡difference ¡

between ¡two ¡independent ¡normals ¡

var[D] = stderr({x})2 + stderr({y})2

stderr[D] =

  • stderr({x})2 + stderr({y})2

  • stdunbiased({x})2

kx + stdunbiased({y})2 ky

slide-41
SLIDE 41

P-­‑value ¡for ¡testing ¡the ¡equality ¡of ¡two ¡ means ¡

✺ Define ¡the ¡test ¡staNsNc ¡ ✺ If ¡kx ≥ 30 and If ¡ky ≥ 30 ¡

g = mean({x}) − mean({y}) stderr(D)

p = 1 − f = 1 − 1 √ 2π |g|

−|g|

exp(−u2 2 )du

slide-42
SLIDE 42

P-­‑value: ¡Rejection ¡region-­‑ ¡“The ¡extreme ¡ fraction” ¡

✺ It ¡is ¡convenNonal ¡to ¡report ¡the ¡p-­‑value ¡of ¡a ¡

hypothesis ¡test ¡

¡ ¡

✺ Since ¡N>30, ¡x ¡should ¡come ¡from ¡a ¡standard ¡normal ¡ ¡

RejecNon ¡region ¡ ¡(2α) ¡ ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

By ¡convenNon: ¡ 2α ¡= ¡0.05 ¡ That ¡is: ¡ If ¡p ¡< ¡0.05, ¡reject ¡H0 ¡

p = 1 − f = 1 − 1 √ 2π |g|

−|g|

exp(−u2 2 )du

slide-43
SLIDE 43

Comparing ¡the ¡body ¡temperatures ¡of ¡two ¡ beavers ¡

✺ kx = 114 and ky = 100 ¡ ✺ Mean({x}) ¡= ¡36.86219 ¡ ✺ Mean({y}) ¡= ¡37.5967 ¡ ✺ stderr({x}) ¡= ¡ ✺ stderr({y}) ¡= ¡ ✺ ¡stderr(D) ¡= ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡ ¡0.04821181 ¡

{x} ¡ {y} ¡

stdunbiased({x}) √ 114 stdunbiased({y}) √ 100

  • stderr({x})2 + stderr({y})2
slide-44
SLIDE 44

Comparing ¡the ¡body ¡temperatures ¡of ¡two ¡ beavers ¡

✺ Hypothesis ¡H0: ¡the ¡mean ¡temperatures ¡of ¡the ¡

two ¡beavers ¡are ¡the ¡same ¡

✺ The ¡test ¡staNsNc ¡g ¡= ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡-­‑15.235 ¡ ¡

¡ ¡

✺ So ¡we ¡can ¡reject ¡the ¡hypothesis ¡that ¡the ¡mean ¡

temperatures ¡are ¡the ¡same ¡ ¡

36.86219 − 37.5967 0.04821181

p = 1 − f = 1 − 1 √ 2π 15.235

−15.235

exp(−u2 2 )du

p ≃ 0

slide-45
SLIDE 45

What ¡if ¡N ¡< ¡30? ¡

✺ There ¡are ¡general ¡soluNons ¡for ¡either ¡N ¡>= ¡30 ¡or ¡N ¡< ¡

30 ¡if ¡the ¡data ¡sets ¡are ¡random ¡samples ¡from ¡normal ¡ distributed ¡data. ¡

✺ The ¡difference ¡between ¡sample ¡means ¡can ¡be ¡

either ¡modeled ¡as ¡t-­‑distribuNon ¡with ¡degree ¡(kx +ky-2) ¡when ¡their ¡standard ¡deviaNons ¡are ¡the ¡same ¡

✺ Or ¡the ¡difference ¡between ¡sample ¡means ¡can ¡be ¡

approximated ¡with ¡t-­‑distribuNon ¡with ¡proper ¡ degree ¡of ¡freedom. ¡

✺ There ¡are ¡build ¡in ¡t-­‑test ¡procedures ¡for ¡such ¡

  • purposes. ¡

¡

slide-46
SLIDE 46

Compare ¡the ¡two ¡mean ¡temperatures ¡of ¡ two ¡beavers ¡with ¡t.test ¡ ¡

✺ Hypothesis ¡H0: ¡the ¡mean ¡temperatures ¡of ¡the ¡

two ¡beavers ¡are ¡the ¡same ¡ ¡

✺ p ¡< ¡2.2e-­‑16 ¡, ¡also ¡reject ¡the ¡hypothesis ¡

¡ ¡

slide-47
SLIDE 47

Be ¡wary ¡of ¡one ¡tailed ¡p-­‑values ¡

✺ The ¡one ¡tailed ¡p-­‑value ¡should ¡only ¡be ¡considered ¡

when ¡the ¡realized ¡sample ¡mean ¡or ¡differences ¡will ¡for ¡ sure ¡fall ¡only ¡to ¡one ¡size ¡of ¡the ¡distribuNon. ¡

✺ SomeNmes ¡scienNst ¡are ¡tempted ¡to ¡use ¡one ¡tailed ¡

test ¡because ¡it’ll ¡give ¡smaller ¡p-­‑val. ¡But ¡this ¡is ¡bad ¡ staNsNcs! ¡

slide-48
SLIDE 48
  • Q. ¡ ¡

✺ What ¡is ¡the ¡test ¡staNsNc ¡g ¡in ¡the ¡previous ¡

example ¡compared ¡to ¡when ¡N ¡is ¡>= ¡30? ¡

  • A. Normal ¡(0, ¡1) ¡ ¡ ¡ ¡ ¡ ¡

¡ ¡

  • B. t-­‑distribuNon ¡(degree ¡= ¡N) ¡
  • C. ¡ ¡ ¡Normal ¡(mean, ¡stderr) ¡
slide-49
SLIDE 49
slide-50
SLIDE 50
  • Q. ¡ ¡

✺ What ¡is ¡the ¡test ¡staNsNc ¡g ¡in ¡the ¡previous ¡

example ¡compared ¡to ¡when ¡N ¡is ¡>= ¡30? ¡

  • A. Normal ¡(0, ¡1) ¡ ¡ ¡ ¡ ¡ ¡

¡ ¡

  • B. t-­‑distribuNon ¡(degree ¡= ¡N) ¡
  • C. ¡ ¡ ¡Normal ¡(mean, ¡stderr) ¡
slide-51
SLIDE 51

Contents ¡

✺ Review ¡of ¡variance, ¡sample ¡mean ¡ ✺ Sum ¡and ¡difference ¡between ¡

variables ¡of ¡normal ¡distribuNons ¡

✺ Hypothesis ¡test ¡of ¡equality ¡of ¡two ¡

sample ¡means ¡

✺ Chi-­‑square ¡test ¡

slide-52
SLIDE 52

Chi-­‑square ¡distribution ¡

✺ If ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡are ¡independent ¡variables ¡of ¡standard ¡normal ¡

distribuNon, ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ X = Z2

1 + Z2 2 + ... + Z2 m = m

  • i=1

Zi

Z′

is

has ¡a ¡Chi-­‑square ¡distribuNon ¡with ¡degree ¡of ¡freedom ¡ m ¡, ¡ ¡X ∼ χ2(m)

✺ We ¡can ¡test ¡the ¡goodness ¡of ¡fit ¡for ¡a ¡model ¡using ¡a ¡

staNsNc ¡C ¡against ¡this ¡distribuNon, ¡where ¡ ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

C =

m

  • i=1

(fo(εi) − ft(εi))2 ft(εi)

slide-53
SLIDE 53

Chi-­‑square ¡distribution ¡

X = Z2

1 + Z2 2 + ... + Z2 m = m

  • i=1

Zi

Z′

is

has ¡a ¡Chi-­‑square ¡distribuNon ¡with ¡degree ¡of ¡freedom ¡ m ¡, ¡ ¡X ∼ χ2(m)

✺ We ¡can ¡test ¡the ¡goodness ¡of ¡fit ¡for ¡a ¡model ¡using ¡a ¡

staNsNc ¡C ¡against ¡this ¡distribuNon, ¡where ¡ ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

C =

m

  • i=1

(fo(εi) − ft(εi))2 ft(εi)

TheoreNcal ¡frequency ¡ Observed ¡frequency ¡

✺ If ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡are ¡independent ¡variables ¡of ¡standard ¡normal ¡

distribuNon, ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡

slide-54
SLIDE 54

Independence ¡analysis ¡using ¡Chi-­‑square ¡

✺ Given ¡the ¡two ¡way ¡table, ¡test ¡whether ¡the ¡

column ¡and ¡row ¡are ¡independent ¡

Boy ¡ Girl ¡ Total ¡ Grades ¡

117 ¡ 130 ¡ 247 ¡

Popular ¡

50 ¡ 91 ¡ 141 ¡

Sports ¡

60 ¡ 30 ¡ 90 ¡

Total ¡

227 ¡ 251 ¡ 478 ¡

slide-55
SLIDE 55

Independence ¡analysis ¡using ¡Chi-­‑square ¡

✺ The ¡theoreNcal ¡expected ¡values ¡if ¡

independent ¡

Boy ¡ Girl ¡ Total ¡ Grades ¡

117.29916 ¡ 129.70084 ¡ 247 ¡

Popular ¡

66.96025 ¡ 74.03975 ¡ 141 ¡

Sports ¡

42.74059 ¡ 47.25941 ¡ 90 ¡

Total ¡

227 ¡ 251 ¡ 478 ¡

slide-56
SLIDE 56

The ¡degree ¡of ¡the ¡chi-­‑square ¡distribution ¡ for ¡the ¡two ¡way ¡table ¡

✺ The ¡degree ¡of ¡freedom ¡for ¡the ¡chi-­‑square ¡

distribuNon ¡for ¡a ¡r ¡by ¡c ¡table ¡is ¡ ¡ ¡(r-­‑1) ¡× ¡(c-­‑1) ¡ ¡where ¡r>1 ¡and ¡c>1 ¡

✺ ¡Because ¡the ¡degree ¡df ¡= ¡n-­‑1-­‑p ¡

¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡rc ¡-­‑1-­‑ ¡(r-­‑1) ¡-­‑ ¡(c-­‑1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡(r-­‑1) ¡×(c-­‑1) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡= ¡2 ¡

¡

See ¡textbook ¡Pg ¡171-­‑172 ¡

n ¡is ¡the ¡number ¡of ¡cells ¡of ¡ data; ¡ p ¡is ¡the ¡number ¡of ¡ unknown ¡parameters ¡

slide-57
SLIDE 57

Chi-­‑square ¡test ¡for ¡the ¡popular ¡kid ¡data ¡

✺ The ¡Chi-­‑staNsNc ¡: ¡21.455 ¡ ✺ P-­‑value: ¡2.193e-­‑05 ¡ ✺ It’s ¡very ¡unlikely ¡the ¡two ¡categories ¡are ¡

independent ¡

chisq.test(data_BG) ¡ ¡ ¡Pearson's ¡Chi-­‑squared ¡test ¡ ¡ data: ¡ ¡data_BG ¡ X-­‑squared ¡= ¡21.455, ¡df ¡= ¡2, ¡p-­‑value ¡= ¡2.193e-­‑05 ¡

slide-58
SLIDE 58
  • Q. ¡What ¡is ¡the ¡degree ¡of ¡freedom ¡for ¡this? ¡

✺ The ¡following ¡2-­‑way ¡table ¡for ¡chi-­‑square ¡test ¡

has ¡a ¡degree ¡of ¡freedom ¡equal ¡to: ¡

¡ ¡ ¡ ¡ ¡

¡A. ¡8 ¡ ¡B. ¡ ¡6 ¡

¡ ¡ ¡ ¡ ¡C. ¡3 ¡ ¡D. ¡ ¡4 ¡ ¡ ¡

Class ¡ Male ¡ Female ¡ 1st ¡ 118 ¡ 4 ¡ 2nd ¡ 154 ¡ 13 ¡ 3rd ¡ 387 ¡ 89 ¡ Crew ¡ 670 ¡ 3 ¡

slide-59
SLIDE 59
slide-60
SLIDE 60
  • Q. ¡What ¡is ¡the ¡degree ¡of ¡freedom ¡for ¡this? ¡

✺ The ¡following ¡2-­‑way ¡table ¡for ¡chi-­‑square ¡test ¡

has ¡a ¡degree ¡of ¡freedom ¡equal ¡to: ¡

¡ ¡ ¡ ¡ ¡

¡A. ¡8 ¡ ¡B. ¡ ¡6 ¡

¡ ¡ ¡ ¡ ¡C. ¡3 ¡ ¡D. ¡ ¡4 ¡ ¡ ¡

Class ¡ Male ¡ Female ¡ 1st ¡ 118 ¡ 4 ¡ 2nd ¡ 154 ¡ 13 ¡ 3rd ¡ 387 ¡ 89 ¡ Crew ¡ 670 ¡ 3 ¡

slide-61
SLIDE 61

Chi-­‑square ¡test ¡is ¡very ¡versatile ¡

✺ Chi-­‑square ¡test ¡is ¡so ¡versaNle ¡that ¡it ¡can ¡

be ¡uNlized ¡in ¡many ¡ways ¡either ¡for ¡ discrete ¡data ¡or ¡conNnuous ¡data ¡via ¡ intervals ¡

✺ Please ¡check ¡out ¡the ¡worked-­‑out ¡

examples ¡in ¡the ¡textbook ¡and ¡read ¡more ¡ about ¡its ¡applicaNons. ¡

slide-62
SLIDE 62

Assignments ¡

✺ Finish ¡Chapter ¡7 ¡of ¡the ¡textbook ¡ ✺ Next ¡Nme: ¡ ¡Maximum ¡likelihood ¡

esNmate, ¡Bayesian ¡inference ¡

¡

slide-63
SLIDE 63

Additional ¡References ¡

✺ Peter ¡Dalgaard ¡"Introductory ¡StaNsNcs" ¡

with ¡R ¡

✺ Robert ¡V. ¡Hogg, ¡Elliot ¡A. ¡Tanis ¡and ¡Dale ¡L. ¡

  • Zimmerman. ¡“Probability ¡and ¡StaNsNcal ¡

Inference” ¡ ¡

✺ Morris ¡H. ¡Degroot ¡and ¡Mark ¡J. ¡Schervish ¡

"Probability ¡and ¡StaNsNcs” ¡

slide-64
SLIDE 64

Acknowledgement ¡

Thank You!