Sample sta*s*cs and linear regression NEU 466M - - PowerPoint PPT Presentation

sample sta s cs and linear regression
SMART_READER_LITE
LIVE PREVIEW

Sample sta*s*cs and linear regression NEU 466M - - PowerPoint PPT Presentation

Sample sta*s*cs and linear regression NEU 466M Instructor: Professor Ila R. Fiete Spring 2016 Mean { x 1 , , x N } N samples of variable x N h x


slide-1
SLIDE 1

Sample ¡sta*s*cs ¡and ¡linear ¡regression ¡ ¡

NEU ¡466M ¡ Instructor: ¡Professor ¡Ila ¡R. ¡Fiete ¡ Spring ¡2016 ¡

slide-2
SLIDE 2

Mean ¡

{x1, · · · , xN} hxi ⌘ 1 N

N

X

i=1

xi sample mean

N ¡samples ¡of ¡variable ¡x ¡

  • ther notation: ¯

x

mean(x)

slide-3
SLIDE 3

Binned ¡version ¡of ¡mean ¡

N ¡samples ¡of ¡variable ¡x ¡

{x1, · · · , xN} {n1, · · · nB} counts per bin hxi ⌘ 1 N

B

X

i=1

nici sample mean {c1, · · · cB}, B bins

slide-4
SLIDE 4

Variance ¡

{x1, · · · , xN}

homework: show that h(x hxi)2i = hx2i hxi2

h(x hxi)2i ⌘ 1 N 1

N

X

i=1

(xi hxi)2 sample variance

a ¡measure ¡of ¡the ¡“scaJer”/spread ¡ ¡

  • f ¡the ¡data ¡around ¡its ¡mean ¡value ¡
slide-5
SLIDE 5

Standard ¡devia*on ¡

{x1, · · · , xN} p h(x hxi)2 standard deviation

slide-6
SLIDE 6

Covariance ¡

{x1, · · · , xN}{y1, · · · , yN} sample covariance

N ¡samples ¡each ¡of ¡ variables ¡x, ¡y ¡

C(x, y) ⌘ 1 N 1

N

X

i=1

(xi hxi)(yi hyi) (C(x, x) is simply sample variance of x)

slide-7
SLIDE 7

Covariance: ¡what ¡does ¡it ¡measure? ¡

C(x, y) ⌘ 1 N 1

N

X

i=1

(xi hxi)(yi hyi)

  • If ¡x, ¡y ¡ ¡both ¡deviate ¡from ¡their ¡means ¡together ¡(both ¡up ¡then ¡both ¡

down) ¡then ¡terms ¡in ¡sum ¡are ¡posi*ve, ¡C(x,y) ¡> ¡0. ¡

  • If ¡x,y ¡deviate ¡from ¡their ¡means ¡independent ¡of ¡each ¡other, ¡then ¡

terms ¡in ¡the ¡sum ¡are ¡randomly ¡posi*ve ¡and ¡nega*ve, ¡C(x,y) ¡~=0. ¡

  • If ¡x,y ¡deviate ¡from ¡their ¡means ¡in ¡opposite ¡direc*ons, ¡then ¡terms ¡

in ¡sum ¡are ¡nega*ve, ¡C(x,y) ¡< ¡0. ¡ ¡

Literally, ¡covariance ¡is ¡a ¡measure ¡of ¡co-­‑varia*on. ¡ ¡

slide-8
SLIDE 8

−4 −3 −2 −1 1 2 3 4 −4 −3 −2 −1 1 2 3 4 x y

Covariance ¡example ¡I ¡

x, y independent

x = randn(1000, 1) y = randn(1000, 1)

C(x, y) = 0.009;

x > 0, y around 0 without bias

009; C(x, x) = 1.069

slide-9
SLIDE 9

−4 −3 −2 −1 1 2 3 4 −4 −3 −2 −1 1 2 3 4 x y

Covariance ¡example ¡II ¡

x, y independent

x = 0.2 ∗ randn(1000, 1) y = 0.2 ∗ randn(1000, 1)

C(x, y) = 0.001; C(x, x) = 0.0407

slide-10
SLIDE 10

−3 −2 −1 1 2 3 4 −2 −1.5 −1 −0.5 0.5 1 1.5 2 2.5 x y

Covariance ¡example ¡III ¡

x, y not independent

C(x, x) = 0.907; C(x, y) = 0.464; C(y, y) = 0.469

x = randn(1000, 1) y = 0.5 ∗ x + 0.5 ∗ randn(1000, 1)

x > 0, y > 0

slide-11
SLIDE 11

Alterna*ve ¡nota*on ¡

  • Mean: ¡ ¡
  • Variance: ¡
  • Covariance: ¡ ¡
  • Standard ¡devia*on ¡

hxi, ¯ x, µx, E(x) hx2i hxi2, x2 ¯ x2, σ2

x, var(x), C(x, x)

hxyi hxihyi, xy ¯ x¯ y, σ2

xy, cov(x), C(x, y)

p hx2i hxi2, q x2 ¯ x2, σx, std(x)

slide-12
SLIDE 12

Pearson’s ¡correla*on ¡coefficient ¡

ρ(x, y) = ⌦ (x hxi)(y hyi) ↵ p h(x hxi)2ih(x hxi)2i

ρ(x, y) = C(x, y) σxσy

shorter-­‑form ¡nota*on ¡

slide-13
SLIDE 13

Pearson’s ¡correla*on ¡coefficient ¡and ¡ covariance ¡only ¡measure ¡linear ¡dependency ¡

from: ¡hJps://en.wikipedia.org/wiki/Correla*on_and_dependence ¡ ¡

slide-14
SLIDE 14

Robust ¡sta*s*cs? ¡

  • Mean, ¡variance ¡are ¡easy ¡to ¡compute, ¡widely ¡

used/useful. ¡ ¡

  • But ¡not ¡robust: ¡sensi*ve ¡to ¡outliners. ¡
  • More ¡robust ¡alterna*ve ¡to ¡mean: ¡median. ¡ ¡
slide-15
SLIDE 15

LINEAR ¡REGRESSION ¡IN ¡TERMS ¡OF ¡ SAMPLE ¡STATISTICS ¡

Applica*on ¡

slide-16
SLIDE 16

Regression: ¡curve-­‑fi`ng ¡

{(x1, y1), (x2, y2), · · · , (xN, yN)} free parameters: (w0, w1, · · · , wM)

˜ y(x) = w0 + w1x + · · · + wMxM =

M

X

j=0

wjxj

Scalar ¡explanatory ¡variable ¡(X) ¡and ¡response ¡variable ¡(Y); ¡N ¡samples ¡

slide-17
SLIDE 17

Linear ¡least-­‑squares ¡regression ¡

dE dw0 = 0, dE dw1 = 0

E = 1 2

N

X

n=1

[˜ y(xn; w) − yn]2 = 1 2

N

X

n=1

[

M

X

j=0

wjxj

n − yn]2

= 1 2

N

X

n=1

[w0 + w1xn − yn]2

To ¡solve ¡for ¡best ¡w0, ¡w1: ¡ ¡ M=1 ¡for ¡linear ¡ ¡ regression ¡

slide-18
SLIDE 18

Linear ¡least-­‑squares ¡regression ¡

E = 1 2

N

X

n=1

[w0 + w1xn − yn]2

dE dw0 =

N

X

n=1

[w0 + w1xn yn] = Nw0 + Nw1hxi Nhyi = 0

(1) w0 + w1hxi hyi = 0

slide-19
SLIDE 19

Linear ¡least-­‑squares ¡regression ¡

E = 1 2

N

X

n=1

[w0 + w1xn − yn]2

dE dw1 =

N

X

n=1

[w0 + w1xn yn]xn = Nw0hxi + Nw1hx2i Nhxyi = 0

w0hxi + w1hx2i hxyi = 0 (2)

slide-20
SLIDE 20

Linear ¡least-­‑squares ¡regression ¡

w1 = C(x, y) C(x, x) w0 = hyi w1hxi

slope y − intercept

In ¡homework: ¡check ¡matlab’s ¡polyfit ¡with ¡this ¡op*mal ¡expression ¡for ¡linear-­‑least ¡squares ¡fi`ng. ¡

slide-21
SLIDE 21

Linear ¡least-­‑squares ¡regression ¡

w1 = C(x, y) C(x, x) w0 = hyi w1hxi

slope y − intercept

ρ(x, y) = C(x, y) σxσy

Contrast ¡with ¡w1: ¡Pearson’s ¡correla*on ¡ Different ¡normaliza*ons: ¡ ¡

  • Different ¡correla*on ¡coefficient ¡for ¡same ¡slope ¡but ¡different ¡amounts ¡of ¡x,y-­‑scaJer. ¡ ¡
  • Same ¡correla*on ¡for ¡different ¡slopes ¡and ¡different ¡x,y ¡scaJer. ¡ ¡ ¡
  • Correla*on: ¡more ¡strongly ¡penalizes ¡y-­‑scaJer, ¡more ¡weakly ¡penalizes ¡x-­‑scaJer. ¡ ¡
slide-22
SLIDE 22

Slope ¡versus ¡Pearson’s ¡correla*on ¡coefficient ¡

from: ¡hJps://en.wikipedia.org/wiki/Correla*on_and_dependence ¡ ¡

same ¡slope ¡ different ¡ρ ¡ different ¡ ¡ slope, ¡same ¡ρ ¡

slide-23
SLIDE 23

BACK ¡TO ¡SAMPLE ¡STATISTICS: ¡ MULTIVARIATE ¡

Applica*on ¡

slide-24
SLIDE 24

Mul*ple ¡variables: ¡covariance ¡matrix ¡

{xα1, · · · , xαN} sample covariance matrix

N ¡samples ¡of ¡the ¡αth ¡variable ¡xα ¡

K ¡different ¡variables ¡xα ¡, ¡labeled ¡by ¡α, ¡β ¡ ¡= ¡{1,…,K}: ¡ ¡

K × K dim since K variables

Cαβ ⌘ 1 N 1

N

X

i=1

(xαi hxαi)(xβi hxβi) = cov(xα, xβ)

slide-25
SLIDE 25

Covariance ¡matrix ¡

  • (α,β) ¡element ¡is ¡covariance ¡between ¡xα, ¡xβ. ¡ ¡
  • Diagonal ¡of ¡covariance ¡matrix ¡is ¡variance ¡of ¡each ¡

variable: ¡var(xα) ¡or ¡C(xα, ¡xα). ¡

  • K2 ¡entries ¡total, ¡but ¡only ¡half ¡of ¡off-­‑diagonal ¡terms ¡are ¡

independent ¡because ¡of ¡symmetry ¡(C(xβ, ¡xα)= ¡C(xα, ¡xβ)). ¡

  • Thus ¡only ¡(K2-­‑K)/2 ¡+ ¡K ¡= ¡K(K+1)/2 ¡independent ¡terms. ¡ ¡ ¡

Q’s: ¡How ¡do ¡do ¡linear ¡regression ¡in ¡mul*variate ¡case? ¡Will ¡it ¡involve ¡covariance ¡matrix? ¡

slide-26
SLIDE 26

−4 −3 −2 −1 1 2 3 4 −4 −3 −2 −1 1 2 3 4 x y

Covariance ¡example ¡I ¡

x, y independent

x = randn(1000, 1) y = randn(1000, 1)

C =  0.959 0.009 0.009 1.069

slide-27
SLIDE 27

−3 −2 −1 1 2 3 4 −2 −1.5 −1 −0.5 0.5 1 1.5 2 2.5 x y

Covariance ¡example ¡III ¡

x, y not independent

x = randn(1000, 1) y = 0.5 ∗ x + 0.5 ∗ randn(1000, 1)

C =  0.907 0.464 0.464 0.469

slide-28
SLIDE 28

Summary ¡

  • Defined ¡sample ¡mean ¡and ¡variance ¡of ¡a ¡

variable ¡

  • Defined ¡covariance ¡between ¡a ¡pair ¡of ¡

variables ¡

  • Solved ¡op*mal ¡(least-­‑squares) ¡linear ¡

regression ¡between ¡two ¡variables ¡in ¡terms ¡of ¡ mean, ¡covariance ¡

  • Covariance ¡matrix: ¡covariance ¡between ¡all ¡ ¡

¡ ¡ ¡ ¡K(K+1)/2 ¡unique ¡pairs ¡of ¡K ¡variables ¡