33
Regression project ( 珊彗)

Regression project (珊彗guo.ba.ntu.edu.tw/教學課程/大學部/統計學下... · 2017. 5. 15. · Regression project 珊 ... • 教室:管一104(工管系2年級),管一203(其他,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

  • Regression project (珊彗)

  • 作業與考試提醒

    l 5/17(三)6:00-9:00pm  統計期中考• 教室:管一104(工管系2年級),管一203(其他,  商研所,工管非2  年級)

    • 5/12(五)實習,講解project• 5/15(一)有office  hour

    l 5/18(四):正常上課• 5/19  (五):有實習課• 5/22(一):  有office  hour• 5/25(四)繳交 regression  project與作業8  (C15,  chi-square)

    2

  • 自我練習題(Q3)

    3

    K=3,  dummy  variable只有兩個SunnyRainother

  • 自我練習題(Q3)

    4

  • 自我練習題(Q3)

    5

    © There is sufficient evidence to infer that weekend attendance is larger than weekday attendance.

    天氣都不顯著

    Weekend顯著

  • 解釋

    l Y=3490+0.369Yesterday+1623 Weenkend+733.5Sunny-765.5 Rain

    6

    Weekend=1,  Y=3490+1623*1+….Weekday=0,  Y=3490+1623*0+….

    記得dummy  variable都是跟0  的那個比

    例如:週末收入比平日收入,多1623例如:晴天收入比陰天收入,多733(假如顯著的話)例如:雨天收入比陰天收入,少765(假如顯著的話)

  • 作業原則

    7

    l 此次作業為小組作業,每組最多4位同學。本次作業同學利用Reg.project此資料,並使用SPSS   or  Excel作出適當的迴歸分析與管理建議。

    l 請依照以下的參考原則完成這次的project報告。l 繳交作業時請繳一交word檔 (需包含報告內文與報表)。

    l 報告內容必須清楚且一致,頁數不可超過十五頁(包含附錄)

  • 作業原則

    8

    l 報告建議要包含以下內容,但不需要完全按照其順序:

    l 利用scatter  diagram或你對資料的了解找出自變數與依變數之關係,可能為直線或曲線關係

    l 確認資料沒有任何outlier,並嘗試可能的交互項(Interaction)在你的模型中

    l 描述得到最後模型的過程(可以寫出你如何找到最佳模型)

    l 確認迴歸模型是否符合殘差假設,假如不符合,請嘗試修正問題;同時也確認是否有共線性問題

    l 評估模型配適度(建議可以做F、 t  檢定)l 解釋最後模型之結果

    l 若能運用第二章所學的畫圖技巧(圓餅圖、長條圖….會有加分效果喔)

    l 報告結論與管理意涵

    l 提醒:本次作業目的是培養學生,能實際實際數據,以及做實務報告的能力。所以不是跑完回歸就沒事囉!要確定模型到底可不可用?是否已經是最好的模型?最後也是最重要的,這回歸模型到底背後有什麼管理意涵?

  • GoodBelly

    9

    l GoodBelly這家公司想知道,有什麼因素會影響其飲料銷售量?

    l 所以他就收集了126家零售商的資訊,觀察了10週,共蒐集了1386筆觀測值。

    l 以下說明非本作業最佳解。請各位利用所學,把你們有test  檢驗的模型、殘差假設、如何找出最佳模型皆呈現在報告上。

  • 10

  • GoodBelly

    11

  • GoodBelly

    12

  • 建議作法 (C17-18)

    l Data  clean(本作業可省略)l Scatter  plot  of  each  X  vs  Yl Create  all  interesting  X  (x^2,  X^3,  X1X2)l Stepwise  reg (找出一個你目前覺得最好的)l 如何確認模型配適度?

    l Regression Diagnostics l Modify residual hypothesisl Model  Assessment  (評估新的 model)l Scenario and conclusions

    13

  • 1. Scatter plot of each Xi vs Yl 插入à散步圖(Scatter  plot  )l 主要看資料是否可能為U or  S型

    14

    0

    200

    400

    600

    800

    1000

    1200

    0 0.2 0.4 0.6 0.8 1 1.2

    Units  Sold

    Demo

    UnitUnit

    Price

  • 15

    2. 確認模型配適度 (Model Assessment)l 先有一條回歸式子

    l 𝑦" = 𝑏% + 𝑏'𝑋1 + 𝑏*𝑋2 + 𝑏,𝑋1𝑋2 … . .+𝜀l 最佳模型,請自己try (可用Stepwise  regression)

    l The  model  is  assessed  using  three  tools:l Standard  error  of  estimate  (標凖誤 𝑆1)l Coefficient  of  determination  (R2 )l F-test  of  the  analysis  of  variance (F檢定)l T-test  of  the  slope  (假設檢定b1)

  • 2. 跑一條回歸式( 自己try)

    16

    R2蠻高的

    𝑺𝜺還可以,不算太高

    F顯著,𝐛𝐢至少一個顯著, ok

  • 17

    3. 確認殘差假設(Regression Diagnostics )問題 檢驗方式 可能解決方式

    • Is  the  error  variable  normally  distributed?

    • Draw a histogram of the residuals

    • X*  test  (C15)

    • 對Y取 log

    • Is  the  error  variance  constant?(Heteroscedasticity)

    • 變異數不齊一

    • Plot the residuals versus 𝑦"

    • 對Y取 log• 其他高階方式

    • Are  the  errors  independent?(Autocorrelation)

    • 自我相關

    • Plot the residuals versus the time periods

    • DW test

    • 加入一個時間變數

    • Is  multicolinearity(intercorrelation)a  problem?

    • 共線性

    • Correlation table• VIF>5

    • 刪除兩個高相關的其中一個。

    • 用逐步回歸法

    • Can  we  identify  outlier?

    Standard  residual  >±2

    • 刪掉它

  • 18

    沒有自我相關

    沒有變異數不齊一

    𝜀 ∼ N(0, 𝜎1)

  • 3.確認殘差假設(先跑出殘差)l Data  à data  analysisà regressionà記得勾選residual,  standard  residual

    19

    Y  hat  

  • 20

    3.1 Diagnostics: The Error Distribution

    The errors histogram

    The errors may benormally distributed

  • 21

    -4000-3000-2000-1000

    0100020003000

    7500 8500 9500 10500 11500 12500

    Residual vs. predicted y

    3.2 Diagnostics: Heteroscedasticity

    There is no problem of heteroscedasticity (the error variance seems to be constant).

    There is a problem of heteroscedasticity

  • 用Y hat跟Residual畫散步圖

    22

    -400

    -300

    -200

    -100

    0

    100

    200

    300

    0 100 200 300 400 500 600 700 800 900

    Residuals

    There is a problem of heteroscedasticity可能有變異數不齊一問題,未來建議可以修正

  • 23

    -4000-3000-2000-1000

    0100020003000

    0 5 10 15 20 25

    Residual over time

    3.3 Diagnostics: First Order Autocorrelation (法一)

    The errors are not independent!!

  • 24

    3.3 Diagnostics: First Order Autocorrelation (法一)

    The errors are not independent!!好像沒有自我相關問題

  • 25

    l Step  1:  H0:  Τhere is no first autocorrelationH1:  Τhere  is  first  autocorrelation(positive/  negative)

    l Step2:  Critical  point (  查表)l If  d4-dL first  order  autocorrelation  existsl If  d  dL and  dU or  between  4-dU and  4-dLthe  test  is  inconclusivel If  d  falls  between  dU and  4-dU there  is  no  evidence  for  first  order  autocorrelation  

    l Step3:  The  test  statistic  is

    Step4:  結論

    3.3 Durbin - Watson Test(法二)

    40

    )(

    1

    2

    2

    21

    ≤≤

    =

    =

    =−

    disdofrangeThe

    e

    eed n

    ii

    n

    iii

    Residual at time i

  • 26

    l Step  1:  H0:  Τhere is no first autocorrelationH1:  Τhere  is  first  autocorrelation(positive/  negative)

    l Step2:  Critical  point (  查表)l DW(k,n)=DW(8,1396)~  dL=1.53,  du=1.83

    l Step3:  The  test  statistic  isl Data-data  analysis  plus-DW  test –選取 residual–就可以跑出d了(d=1.929)

    3.3 Durbin - Watson Test(法二)

  • 27

    dL=1.53 dL=1.53 dL=1.929

    好像沒有自我相關問題

  • DW查表(示意圖)

    28

  • 29

    l Multicolinearity is  not  found  to  be  a  problem.

    3.4 Diagnostics: Multicolinearity(法一)

    • X與X間,相關係數很低

    l Data-->  data  analysis-->  correlationà放入全部資料

  • 30

    3.4 Diagnostics: Multicolinearity (法二)• Multicolinearity causes two kinds of difficulties:

    – The t statistics appear to be too small.– The β coefficients cannot be interpreted as “slopes”.

    F顯著,t  也有顯著應該沒有共線性

  • 31

    3.4 Variance inflationary factor, VIF檢定(法三)

    VIFH ='

    'IJKL >5,  則有共線性問題

    有x1,  x2,  x3個變數~j=3

    𝑋1M = 𝑏% + 𝑏'𝑋2+ 𝑏*𝑋3……… . 1 ,可得  𝑅'*𝑋2M = 𝑏% + 𝑏'𝑋1+ 𝑏*𝑋3……… . 1 ,可得  𝑅**𝑋3M = 𝑏% + 𝑏'𝑋1+ 𝑏*𝑋2……… . 1 ,可得  𝑅,*

    Excel無法跑,除非自己要寫個公式下去跑~不然就….你們以後用SPSS他就會幫你跑了

  • 3.5 Outlierl Data  à data  analysisà regressionà記得勾選residual,  standard  residual

    32

    Standard  residual  >±2 ,看要不要刪除

  • 4. 修正相關假設與重跑模型

    l針對不符合的假設,可以做相關修正l再重跑一次模型,看模型檢定力是否增加l上述的假設不符問題,是否解決l解釋模型,以及各bi對Y的意思。l說明管理意涵與對GoodBelly的建議

    33