06. multiple linear regression - kocwcontents.kocw.net/kocw/document/2014/hanyang/huhseon/3.pdf ·...

16
2014-09-23 1 Hanyang University Quest Lab. Chapter 6 Multiple linear regression Fall, 2014 Department of IME Hanyang University Hanyang University Quest Lab. - Multiple regression Y (outcome, response variable) vs. x 1 ,x 2 , ⋯, x p (independent var, input var, regressors, covariates) 다음과 같은 모형도 다중회귀모형에 속함에 유의 Y i = β 0 + β 1 x 1i + β 2 x 1i 2 + ε i Y i = β 0 + β 1 x 1i + β 2 x 2i + β 3 x 1i x 2i + ε i 6.1 Introduction Y i = β 0 + β 1 x 1i + β 2 x 2i +…+ β p x pi + ε i : coefficients,j = 0,1,…,k ε i : noise or unexplained part, ~N (0, )

Upload: others

Post on 08-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

2014-09-23

1

Hanyang

University

Quest Lab.

Chapter 6

Multiple linear regression

Fall, 2014Department of IMEHanyang University

Hanyang UniversityQuest Lab.

- Multiple regressionY (outcome, response variable)

vs. x1,x2, ⋯, xp (independent var, input var, regressors, covariates)

• 다음과 같은 모형도 다중회귀모형에 속함에 유의Yi=β0+β1x1i+β2x1i2+εiYi=β0+β1x1i+β2x2i+β3 x1ix2i +εi

6.1 Introduction

Yi= β0+ β1x1i+ β2x2i+ …+ βpxpi+ εi : coefficients, j = 0,1,…,kεi : noise or unexplained part, ~N (0, )

2014-09-23

2

Hanyang UniversityQuest Lab.

6.2 Explanatory versus predictive modeling

Explanatory modeling Predictive modeling

Model • fits the data closely • predicts the new cases accurately

Data

• Classical, scarce data

• Entire data set is used to

estimate

• Data mining, plentiful data

• training data set to estimate

• validation data set to assess

Performance

measure

• How close the data fit the

model• how well the model predicts

We focus on predictive models.

- Two objectives

1. understand the relationship (classical statistical approach): 주어진 적은 data로부터

관계에 관한 결과를 이끌어내고 얼마나 reliable한 지 아는 것이 중요

2. predict the outcome (data mining): data는 풍부하므로 reliability는 확보가능

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction

75706560

75

70

65

60

height of father

heig

ht o

f son

Y

X

How to find the best line?

2014-09-23

3

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction

Find the straight line that minimizes

Least Square Estimates (Graphically)

å=

=n

iie

1

2RSS

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction

Minimizing sum of squared deviations

→ Estimates and

Predicted value

Best prediction in the sense that:

→ unbiased

→ minimum average squared error under the assumptions

(ε normal, linear relation, independent cases, variability in Y is constant)

→ “ε is normal” assumption can be dropped because we use two data sets

.ˆˆˆˆˆ22110 ppXβXβXββY ++++= L

2ˆ( )i iY Y-åˆib s

2014-09-23

4

Hanyang UniversityQuest Lab.

(1) Simple regression의 경우 (즉, k=1)Yi=β0+β1xi +εi• 가정

– Xi 는 결정되어 있다. (fixed value, not random)– εi는 iid N(0, σ2)– 각각의 오차는 다른 오차에 영향을 주지 않는다.

7

20 1~ ( , )i iY N Xb b s+

0 12

, 1, 2,...,

~ (0, )( , ) 0,

i i i

i

i j

Y X i n

NCov i j

b b e

e se e

= + + =

= ¹

즉, Yi 도 정규확률변수

6.3 Estimating the regression equation and prediction

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction(1) Simple regression 의 경우 (계속)

• 최소자승법 (method of least squares)– 종속변수의 관측된 값과 모형에 의한 예측된 값 사이의 오차의 제곱합을 최소화 시

키는 회귀계수를 추정함이 목적.• β0 와 β1 의 추정

– 오차제곱의 최소화

8

0 1

2 20 1,

1 1

0 10 1

0 11 1

0 1

20 1

min ( )

2 ( ) 0

( ) 2 ( ) 0

ˆ ˆ

ˆ ˆ

n n

i i ii i

n

i iin

i ii

i i

i i i i

Q Y X

Q Y X

Q Y X X

n X Y

X X X Y

b be b b

¶ b b¶b

¶ b b¶b

b b

b b

= =

=

=

= = - -

ì= - - - =ï

ïíï = - - - =ïî

ì + =ïí

+ =ïî

å å

å

å

å åå å å

1 11

2 2 2

1 1

0 1

( )( )ˆ

( )

ˆ ˆ

n n

i i i ii i

n n

i ii i

X X Y Y X Y nXY

X X X nX

Y X

b

b b

= =

= =

- - -

= =

- -

= -

å å

å å정규방정식

2014-09-23

5

Hanyang UniversityQuest Lab.

(2) Multiple regression 의 경우 (즉, k≥2).

9

6.3 Estimating the regression equation and prediction

Yi= β0+ β1x1i+ β2x2i+ …+ βpxpi+ εi , εi~N (0, )다중회귀모형의 행렬식 접근

1 0 1 11 2 21 1 1

2 0 1 12 2 22 2 2

0 1 1 2 2

1 ...

1 ...

1 ...

k p

k p

n n n k pn n

Y X X X

Y X X X

Y X X X

b b b b e

b b b b e

b b b b e

= × + × + × + + × +

= × + × + × + + × +

= × + × + × + + × +M

11 21 11

12 22 22

1 2

0 1

1 2

1

1

1

p

p

n n n pn

p n

X X XYX X XY

Y X X X

b eb e

b e

é ùé ùê úê úê úê ú= = ê úê úê úê úê úë û ë û

é ù é ùê ú ê úê ú ê ú= =ê ú ê úê ú ê úê ú ë ûë û

y X

β ε

L

LM M M M M

L

M M

2

2

22

2

~ (0, )

0

[ ]

0

MVN

Var

s

s

s s

s

= +

é ùê úê ú= =ê úê úê úë û

y Xβ ε

ε I

ε IO

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction• 추정방법: 최소자승법• 정규방정식의 행렬식 표현:

10

20 1 1[ ( ...)]

( ) ( )

2 ( )

i i

T

T T T T T T

T T T T T T T T

Q Y Xb b= - + +

=

=

= - + =

åy - Xβ y - Xβ

y y - y Xβ - β X y + β X Xβ

y y β X y β X Xβ y Xβ β X yQ

( )T T=X X β X y

2 2 0T TQ¶= - + =

¶X y X Xβ

β

1ˆ ( )T T-=β X X X y

2 Tia =å a a

T ff ¶= Þ =

¶x a a

x

2T ff ¶= Þ =

¶x Ax Ax

x

2014-09-23

6

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction• 추정회귀식:

• 잔차(residual):

• σ2의 추정

11

1ˆ ( )

n´= - = -e y y I H y

1

ˆˆn´

= =y Xβ Hy 1( )T Tn n

-

´=H X X X Xwhere

1

TSSESSEMSE

n p

=

=- -

e e

σ2의 불편추정량

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction• 다중회귀모형의 분산분석표(ANOVA)

• 회귀성을 검정을 위한 F-검정– 가설: H0: β1 =β2=…=βp=0

H1: 모든 βi(i=1,2,…,p)가 0은 아니다.

– 검정통계랑:F0=MSR/MSE

– 기각결정: If F0 ≤ F(α; k, n-p-1), H0를 기각하지 못함.If F0 > F(α; k, n-p-1), H0를 기각 (회귀성 유의)

12

요인 제곱합 자유도 평균제곱 F-값 p-값

회귀 SSR p MSR=SSR/p F0=MSR/MSE P{Fk,n-p-1>F0)

잔차 SSE n-p-1 MSE=SSE/(n-p-1)

전체 SST n-1

2014-09-23

7

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction

Example: Predicting the price of used Toyota Corolla

New car를 사려는 고객에게 used car를 사들이겠다는 promotion (trade-in).

이 used car는 small profit만 남기고 sell할 계획. 따라서 그 used car의 가격에

대해 조사.

Price Age KM Fuel_Type HP Metallic Automatic cc Doors Quarterly_Tax Weight13500 23 46986 Diesel 90 1 0 2000 3 210 116513750 23 72937 Diesel 90 1 0 2000 3 210 116513950 24 41711 Diesel 90 1 0 2000 3 210 116514950 26 48000 Diesel 90 0 0 2000 3 210 116513750 30 38500 Diesel 90 0 0 2000 3 210 117012950 32 61000 Diesel 90 0 0 2000 3 210 117016900 27 94612 Diesel 90 1 0 2000 3 210 124518600 30 75889 Diesel 90 1 0 2000 3 210 124521500 27 19700 Petrol 192 0 0 1800 3 100 118512950 23 71138 Diesel 69 0 0 1900 3 185 110520950 25 31461 Petrol 192 0 0 1800 3 100 1185

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction

Among 1,000 records, 60% training vs. 40% validation set

Linear regression with price (dependent var) vs. others (indep. var)

2014-09-23

8

Hanyang UniversityQuest Lab.

6.3 Estimating the regression equation and prediction

Estimated model is applied to validation set to obtain:

50% of errors are within ±$850

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

(1) Reducing the number of predictors

Predictor로 사용할 variable들이 많은 경우의 문제:

• 미래값 예측을 할 때 모든 predictor의 값들이 collect 되지 않거나 비용이 들

수 있음 (그 수가 적었다면 보다 정확하게 측정할 수 있었을 것임)

• Predictor 수가 많을수록 missing value가 발생할 가능성 높아짐

• Multicollinearity(다중공선성: 둘 이상의 predictor가 outcome variable과 동일

한 선형관계를 공유)로 인해 regression coefficient들이 unstable할 수 있음

→ Rule of Thumb: ≥ 5( + 2), = number of cases, = number of predictors

2014-09-23

9

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

다중공선성(multicollinearity)

• 독립변수들 사이에 상관관계를 갖고 있는 현상

• 독립변수들끼리 높은 선형관계가 존재하면 추정된 회귀 계수의 큰 오차 유발

• 다른 예측 변수들을 고정한 가운데 특정 예측 변수가 한 단위 증가할 때 종속

변수의 기대치의 변화를 측정하는 것이 회귀 계수의 일반적인 해석이지만, 다

중공선성이 존재한다면 다른 예측 변수들을 고정한 채, 특정 예측 변수만을 한

단위 증가 시키는 것은 불가능하다.

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

• 다중공선성의 진단 방법

– 독립변수들 간의 상관계수가 매우 높을 때

– 한 독립변수를 모형에 추가하거나 기존의 변수를 제거하는 것이 추정된회귀계수의 크기나 부호에 큰 변화를 줄 때

– 중요한 영향을 가질 것이라 예상되는 독립변수에 대한 검정결과가 유의

하지 않게 나타날 때

– 추정된 회귀계수의 부호가 기존 연구나 이론적인 면에서 알려진 부호와상반될 때

18

2014-09-23

10

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

• 다중공선성의 척도– 분산팽창계수 (VIF : variance inflation factor)

• Rj2 은 Xj 를 종속변수로 하고 나머지 변수를 독립변수로 하는 회귀모형

에서의 결정계수

• VIFj 은 독립변수 사이에서 발생하는 다중공선성으로 인한 분산의 증가

를 의미

• 일반적으로, 가장 큰 값의 VIFj 값이 5~10을 넘으면 다중공선성이 있다

고 판단

19

21 1, 2,...,

1jj

VIF j pR

= =-

Hanyang UniversityQuest Lab.

6. 다중공선성

• 다중공선성의 척도– 상태지표 (condition index)

= 독립변수의 관측치를 표준화한 후 XTX행렬의 고유값 (모두 p+1개)

• 다중공선성이 있다고 할 수 있는 경우

(1) 최대고유값이 1보다 매우 클 때 1보다 상당히 작은 고유값이 존재함

(2) 일반적으로 상태지표가 30이상일 때

20

max 1, 2,...,jj

c j pll

= =

jl

1

1

1p

jj

pl+

=

= +å

2014-09-23

11

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

• 다중공선성의 해결방법

– 변수선택 과정에서 상관계수가 높은 두 변수 중에는 하나만을 선택한다.

– 국부적인 자료수집과정에서 비롯되어 다중공선성이 생겼을 가능성이 있

으므로 좀 더 많은 데이터를 수집하여 분석을 다시 한다.

– 독립변수 중 한 두 개를 차례로 모형에서 제거해보고 회귀계수의 표준오

차가 줄어드는가는 관찰해서 현격히 감소시키는 변수를 제거한다.

21

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

(2) How to reduce the number of predictors

- Domain knowledge를 통해서 (무엇을 측정하는 것인가, 왜 필요한가)

- Model을 통해서 reduce: Exhaustive search and subset selection

• Exhaustive Search

모든 조합에 대해서 regression을 수행한 후 best one을 select2adj (adjusted 2 )를 사용하는 방법

Mallow’s 를 사용하는 방법

• Partial Search Algorithms

Forward

Backward

Stepwise

2014-09-23

12

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

- Fitting regression modes with all possible combination of predictors

- 값이 작더라도 고려할 subset의 수는 매우 많으므로 criteria 필요- 2adj (adjusted 2 )이 작은 모형을 제외:

2 (결정계수): explained variability in the model2 은 predictor의 수가 늘기만 하면 커지는 경향2adj는 predictor의 수가 늘어나는 것에 penalty2adj= 1 − (1 − )

Exhaustive search

Penalty for number of predictors

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

Mallow’s 를 사용하는 방법:

If a subset model is unbiased, average value = + 1, i.e., ( | bias=0)= + 1Good models are: ≈ + 1, and small = + 2( + 1) − ,

where is MSE value when all predictors are included.

2014-09-23

13

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

Results of exhaustive search (with 11 predictors)

Row: best model with 1~11 predictors (2~12 coefficients)

Age, HP, mileage, weights are important predictors

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

2 increases until 6 predictors and stablizesshows 9~11 indicators are good

2014-09-23

14

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

• Partial, iterative search through all regression models

• computationally cheaper, but may miss good combinations

• Predictor의 수가 많을 때에는 괜찮으나 그다지 많지 않은 경우에는 exhaustive

search가 better

- Forward selection

- Backward elimination

- Stepwise regression

Popular subset selection algorithm

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

Forward selection:

• Start with no predictors

• Add predictors one by one

(predictor를 추가함으로써 2이 가장 많이 늘어나는 것을 add)

• 한번 추가된 변수는 제거 되지 않는다.

• Add했을 때 늘어나는 2이 significant하지 않을 때 stop

• 단점은 더 나은 combination을 miss 할 수 있음

2014-09-23

15

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

Backward elimination

• Start with all predictors

• predictor를 하나씩 제거

• 남아있는 predictors들이 significant할 경우 stop

• 다시 모형에 추가되는 변수는 없다.

• 맨 처음 predictor가 모두 있을 때의 계산이 time consuming and unstable

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

Stepwise regression

• 전진선택법과 후진제거법을 복합적으로 사용하는 방법

• 첫 번째 단계에서는 전진선택법을 수행

• 전진선택법에 의하여 변수를 추가하면서 새롭게 추가된 변수에 기인하여 기존 변수가 그 중요도

가 약화되어 제거될 수 있는 지를 매 단계별로 검토하여 해당변수를 제거하는 과정을 거치며 추

가 또는 제거되는 변수가 더 이상 없을 때 끝내는 선택방법

2014-09-23

16

Hanyang UniversityQuest Lab.

6.4 Variable selection in linear regression

Which is the best? Case by case

• Subset selection methods give candidate models that might be “good

models”

• Do not guarantee that “best” model is indeed best

• Also, “best” model can still have insufficient predictive accuracy

• Must run the candidates and assess predictive accuracy

Hanyang UniversityQuest Lab.

• 6.1 (Boston Housing)Multiple regression, exhausted search

• 6.2 Multiple regression, backward selection

• 6.3Multiple regression

• 6.4Multiple regression

Ch. 6 Problems