Ch 3 線性迴歸與相關分析 相關分析 Lear Regresso Ad Correlato Aalyss Correlato Aalyss Correlato Aalyss Correlato Aalyss s the study of the relatoshp betwee two varables. Scatter Dagram A Scatter Dagram s a chart that portrays the relatoshp betwee the two varables. It s the usual frst step correlatos aalyss Scatter Dagram ( 散佈圖 ) Coeffcet of Correlato ( 相關係數 ) Coeffcet of Determato ( 判定係數 ) 3 4
Scatter Dagram Example Scatter Dagram The sales maager of Coper Sales of Amerca, whch has a large sales force throughout the Uted States ad Caada, wats to determe whether there s a relatoshp betwee the umber of sales calls made a moth ad the umber of copers sold that moth. The maager selects a radom sample of represetatves ad determes the umber of sales calls each represetatve made last moth ad the umber of copers sold. 5 6 ( 母體 ) 相關係數 (Correlato Coeffcet) ρ () ( 母體 ) 相關係數 (Correlato Coeffcet) ρ () X 與 Y 兩變數的相關方向與相關程度, 可以由相關係數 ρ 來衡量 X μ X Y μ Y E[( X μx)( Y μy)] σ ρ = E = = σ X σy σ XσY σ XσY 若 X 與 Y 為 N 個成對資料, 則 : N N ( X μ )( Y μ ) 相關係數 ρ 僅能衡量 X 與 Y 的線性相關程度 - ρ ρ = + 完全正 ( 線性 ) 相關 ρ = - 完全負 ( 線性 ) 相關 ρ = 無 ( 線性 ) 相關 X Y ρ, N N ρ = 表示 X 與 Y 的無線性相關, 並不表示 X 與 ( X μx) ( Y μy) Y 無關 若 X 與 Y 的無關, 則 ρ N N = 其中 σ 稱為 X 與 Y 的共變異數 (Covarace) 7 8
Correlato Coeffcet - Iterpretato ( 樣本 ) 相關係數 r () 母體相關係數 ρ 無法得知, 因此必須利用樣本估計 9 若有 組樣本 : ( X, Y ) (X, Y ),..., (X,Y ) : r S =, S S X Y ( X X)( Y Y) S S X X =, X = ( ), S Y Y, 其中 S 稱為與的樣本共變異數 Y = ( ) X Y ( 樣本 ) 相關係數 r () r 在各種可能的散佈圖 樣本相關係數 r 能估計 X 與 Y 的 ( 母體 ) 相關係數 - r r = + 完全正 ( 線性 ) 相關 r = - 完全負 ( 線性 ) 相關 r = 無 ( 線性 ) 相關 3
r 在各種可能的散佈圖 r 在各種可能的散佈圖 3 4 r 的抽樣分配 r 的抽樣分配可分兩種情形討論 : 當 ρ =, r 為對稱分配 (, /-) 當 ρ, r 為偏態分配,E[r ] ρ 檢定 H : ρ = H H : ρ = : ρ t 檢定統計量 : r -r - ~ t 5 6 4
EX3. 廣告支出與銷售額間的相關係數? EX3. 廣告支出與銷售額間的相關係數? 大發汽車公司的廣告支出與銷售額資料如下表, 求廣告支出與銷售額之間的相關係數 7 8 EX3. 廣告支出與銷售額間的相關係數? EX3. 檢定廣告支出與銷售額間的關係是否為 4,84, r = =.966 875, 8,68, 將所得的樣本相關係數 r 作為母體相關係數 ρ 的估計值, 表示大發汽車公司的汽車銷售額與廣告支出有很大的相關性 在大發公司的汽車銷售額與廣告支出關係中, 若要檢定廣告支出與銷售額間的相關係數是否為零, 此時檢定假設為 : H : ρ = H: ρ 計算統計量如下 : t =.966 = 9.5 -(.966) 6 =.5 t = 9.5 t 故拒絕 H, 亦即廣告支出與銷售額有關係 在顯著水準 α, 檢定統計量大於臨界值 6,.5 =.447, 9 5
檢定 H : ρ = ρ EX3.3 看電視的時間 (X) 與教育年數 (Y) 的相關 H : ρ = ρ H : ρ ρ 檢定統計量 : Z + r + ρ r = l ~ N l, r ρ 3 為調查看電視的時間 (X) 與教育年數 (Y) 的相關, 隨機抽取 5 個人, 得 r = -.5 請檢定下面的假 設 ( α =.5) : H : ρ = -.6 H: ρ -.6 EX3.3 看電視的時間 (X) 與教育年數 (Y) 的相關 EX3.3 看電視的時間 (X) 與教育年數 (Y) 的相關 -.5 -.6 因 Z r = l = -.549, Z ρ = l = -.693 +.5 +.6 Z- r Zρ -.549-(-.693).44 故可得 = =.46-3 47 =.986 < Z.5 =.96 因此不拒絕 H, 即看電視時間與教育年數的相關係數為 ρ = -.6 3 若欲求 ρ 之信賴區間, 則先求 : Zr- Zα Zρ Z r+ Z α -3-3 再將 Z, r Z ρ代入上式, 再求 ρ 之信賴區間 Z ρ 的信賴區間為 : + ρ.88.59 -ρ -.684 ρ -.57 4 6
變異數分析 vs. 迴歸模型 線性迴歸模型 Lear Regresso Model 5 變異數分析是探討因子 ( 獨立變數 ) 對相依變數是否有影響的統計方法, 但有兩點限制 : 僅能探討有無影響, 無法估計影響程度 僅能處理離散自變數, 無法處理連續自變數 迴歸模型能解決這兩個問題 : 肥料用量與產量的關係 商品價格與需求量的關係 廣告支出與銷售額的關係 6 Regresso Aalyss - Uses 獨立變數與相依變數 Some examples. Is there a relatoshp betwee the amout Healthtex speds per moth o advertsg ad ts sales the moth? Ca we base a estmate of the cost to heat a home Jauary o the umber of square feet the home? Is there a relatoshp betwee the mles per gallo acheved by large pckup trucks ad the sze of the ege? Is there a relatoshp betwee the umber of hours that studets studed for a exam ad the score eared? 獨立變數或稱自變數或解釋變數 ( Idepedet Varable ) ---- The Idepedet Varable provdes the bass for estmato. It s the predctor varable. 相依變數或稱被解釋變數 (Depedet Varable ) ---- The Depedet Varable s the varable beg predcted or estmated. 7 8 7
迴歸模型 迴歸模型是用來分析一個或一個以上的自變數與依變數的數量關係, 以瞭解自變數為某一數量時, 依變數反應的數量 迴歸模型的主要功能 : 瞭解自變數與依變數的關係式及影響方向與程度 利用自變數與相依變數的關係式, 對依變數做預測 簡單迴歸模型與複迴歸模型 依自變數的多寡, 迴歸模型可分為 : 簡單迴歸模型 : 只有一個自變數 消售額與廣告支出 家庭支出與所得 複迴歸模型 : 兩個或兩個以上自變數 銷售額與廣告支出 季節 地區等 庭支出與所得 人口 財富等 9 3 簡單線性迴歸模型 () 簡單線性迴歸模型 () Recall the example volvg Coper Sales of Amerca. The sales maager gathered formato o the umber of sales calls made ad the umber of copers sold for a radom sample of sales represetatves. Use the least squares method to determe a lear equato to express the relatoshp betwee the two varables. What s the expected umber of copers sold by a represetatve who made calls? 業務經理想以一條直線方程式, 描述 撥電話數 與 銷售額 之間的關係 自變數 (X): 撥電話數 依變數 (Y): 銷售額 Goal: Y=α+βX, α=?, β=? 3 3 8
簡單線性迴歸模型 (3) 任意決定一條直線, 皆會產生誤差 假設 :Y = +.5 X, 則 X= Y =35 Welch: (X, Y) = (, 3) Error = -5 Ramrez: (X, Y) = (, 4) Error = 5 簡單線性迴歸模型 (4) 任意決定一條 Y=α+βX, 皆會產生誤差, 因此最適當的估計式, 必須使誤差最小 以 Y=α+βX+ε 描述迴歸模型, 其中 ε 表示誤差 33 34 簡單線性迴歸模型 (5) 簡單線性迴歸模型 : Y =α + β X +ε,,,,, 其中 α 稱為截距 (Itercept), β 稱為迴歸係數 (Regresso Coeffcet), ε 為隨機誤差 ε 的來源 : 人類行為或自然現象的隨機性 測量誤差 其他因素 簡單線性迴歸模型 (6) Assumptos Uderlyg Lear Regresso: For each value of X, there s a group of Y values, ad these Y values are ormally dstrbuted. The meas of these ormal dstrbutos of Y values all le o the straght le of regresso,.e. E[Y X] =α+βx. The stadard devatos of these ormal dstrbutos are equal. The Y values are statstcally depedet. Ths meas that the selecto of a sample, the Y values chose for a partcular X value do ot deped o the Y values for ay other X values. 35 36 9
簡單線性迴歸模型 (7) 最小平方法估計 α 與 β () 以上假設可以簡寫成 :..d. Y = α + βx + ε, 其中 ε ~N(, σ ) (..d. = detcal ad depedet dstrbuto ) 因此, Y ~ N(α + βx, σ ) 且 E[Y ] = α + βx E[Y] = α + βx 37 我們分別以 ˆα 與 β ˆ 表示 α 與 β 的估計值 最小平方法是使樣本觀察值與估計值的差異平方和最小, 以求取 ˆα 與 β ˆ 的方法 M SSE α, ˆ β ˆ, 其中 α, β ( ) SSE (Sum squares of error) = Y - α - βx ( ) 38 最小平方法估計 α 與 β () 最小平方法估計 α 與 β (3) ˆα 與 β ˆ 可由下列聯立方程式解得 : SSE = ( Y - α - βx )( ) ˆα = SSE = ( Y - α - βx )(- X) = ˆβ 整理可得標準方程式 (Normal Equato) 如下 : Y = α + β X ------------ () = α X + β X --------- ---() 39 ( ) ( X)( Y) X ( X) (X-X)(Y-Y) ( X-X) () X - () : 解得 β ˆ = 分子分母同除, 可得 β ˆ = S 分子分母同除 -, 可得 ˆβ = S X 4
最小平方法估計 α 與 β (4) 簡單線性迴歸模型 (8) (), 可得 :Y = ˆ α + βˆ X, ˆ α = Y - β ˆ X 因此, 可得迴歸估估計式 : The Y = regresso a + bx equato s : Y ˆ = ˆ α + β ˆ X Y Y = 8 = 8.9476.9476 +.84 +.84 X ( ) 4 Y = 4.636 4 估計 σ S YX SY X (or ) 由於 σ 是母體殘差項 ( Resdual) ε 的變異數, 因此表示為 : N N ( ε E[ ε] ) ( ε) σ = = N N 因此, 估計可以使用樣本殘差項 e = Y ˆ ˆ X σ α β σ 估計式 : S YX = ( e ) 來估計 S YX 是估計的標準誤 (Stadard Error), 可用來描述估計 的準確性 由標準方程式 (Norma l Equato) 可以將 S 改寫如下, 以方便運算 S ˆ Y ˆ αy βxy YX = YX 43 44
Stadard Error of the Estmate - Example Cofdece Iterval ad Predcto Iterval Recall the example volvg Coper Sales of Amerca. The sales maager determed the least squares regresso equato s gve below. Determe the stadard error of estmate as a measure of how well the values ft the regresso le. Y = 8.9476 +. 84 X s y. x = = Σ( Y Y ) 784. = 9.9 45 A cofdece terval reports the mea value of Y for a gve X. A predcto terval reports the value of Y for a partcular value of X. 46 Cofdece Iterval Estmate - Example We retur to the Coper Sales of Amerca llustrato. Determe a 95 percet cofdece terval for all sales represetatves who make 5 calls. 47 Cofdece Iterval Estmate - Example Step Compute the pot estmate of Y I other words, determe the umber of copers we expect a sales represetatve to sell f he or she makes 5 calls. The regresso equato s : Y = 8.9476 +.84X Y = 8.9476 +.84(5) Y = 48.556 48
Cofdece Iterval Estmate - Example Cofdece Iterval Estmate - Example Step Fd the value of t To fd the t value, we eed to frst kow the umber of degrees of freedom. I ths case the degrees of freedom s - = = 8. We set the cofdece level at 95 percet. The value of t s.36. 49 5 Cofdece Iterval Estmate - Example Step 4 Use the formula above by substtutg the umbers computed prevous sldes Predcto Iterval Estmate - Example We retur to the Coper Sales of Amerca llustrato. Determe a 95 percet predcto terval for Shela Baker, a West Coast sales represetatve who made 5 calls. Thus, the 95 percet cofdece terval for the average sales of all sales represetatves who make 5 calls s from 4.97 up to 56.88 copers. 5 5 3
Predcto Iterval Estmate - Example Predcto Iterval Estmate - Example Step Compute the pot estmate of Y I other words, determe the umber of copers we expect a sales represetatve to sell f he or she makes 5 calls. The regresso equato s : Y = 8.9476 +.84X Y = 8.9476 +.84(5) Y = 48.556 53 Step Usg the formato computed earler the cofdece terval estmato example, use the formula above. If Shela Baker makes 5 sales calls, the umber of copers she wll sell wll be betwee about 4 ad 73 copers. 54 Ex. 3.4 Ex. 3. 5 在大發汽車的例子, 迴歸係數可使用 最小平方法估計如下 : ( X X)( Y Y) 4,84, ( X X) 875, ˆ β = = = 5.53 ˆ α = Y ˆ βx =, 3 5.53 75 = 8, 9.75 因此, 迴歸式為 : Y ˆ = ˆ α + ˆ βx = 8, 9.75 + 5.53 X 55 大發公司的廣告支出與銷售額的例子中, 總經理想要預測若廣告支出為 4 萬元時, 汽車的平均銷售額為多少? 求 95% 的信賴區間為何? 56 4
Ex. 3. 5 Ex. 3. 5 由已經估得的迴歸估計式 : Y=89.75+5.53X ˆ 將 X =4 帶入可得 Ŷ = 89.75 + 5.53 4 = 63.75 即當廣告支出為 4 萬元時, 根據估計的迴歸模型預測銷售額為 63.75 萬元 求得 Y ˆ 樣本變異數 X - X (4-75) Ŷ Y X Y X 8 875 X S = S + = S + = 386.6457 = 689 57 58 Ex. 3. 5 E(Y X=4) 的 95% 信賴區間為 Ŷ ± t S = 63.75 ± t S 6,.5 Yˆ 6,.5 Yˆ = 63.75 ±.45 689 = 63.75 ±.45 455 Ex. 3. 6 在大發公司的廣告支出與銷售額關係的例子中, 戴經理想知道如果明年的廣告支出為 4 萬元時, 明年的銷售額為何? = 63.75 ± 4.75 因此, 在 95% 信賴區間水準下, 廣告支出為 4 萬元的 年平均銷售額的信賴區間為 498 到 747.5 萬元 59 6 5
Ex. 3. 6 Ex. 3. 6 先求變異數 : S e = S Y X + + X -X X (4-75) = SYX + + 8 875 = 386.6457 = 5795 6 得信賴區間為 : Y ˆ ± t S = 63.75 ± t S 6,.5 e 6,.5 e = 63.75 ±.45 579 = 63.75 ±.45 76 = 63.75 ± 778.7 因此, 若明年的廣告支出為 4 萬元時, 在 95% 信賴區間水準下, 明年汽車銷售額的信賴區間為 454.5 到 78.45 萬元 6 ( Y Y) 依變數的總差異 = 依變數總差異 ( Yˆ Y) = 依變數可解釋差異 ( Y ˆ Y) = 依變數不可解釋差異 ( Y ) ( ˆ ) ( ˆ Y = Y Y + Y Y) 總差異 = 可解釋差異 + 不可解釋差異 63 依變數的總差異 64 6
依變數的總變異 ( ) ( ˆ ) SST = Y Y = 依變數總變異 (total sum of squares ) SSR = Y Y = 依變數可解釋變異 (sum of squares due to regresso) ( ˆ ) SSE = Y Y = 依變數不可解釋變異 (sum of squares due to error) SST = SSR + SSE 總變異 = 可解釋變異 + 不可解釋變異 R, 判定係數 (Coeffcet of Determato) 可解釋變異 (SSR) 佔總變異 (SST) 的比例稱為判定係數 (R ) 判定係數可以用來衡量迴歸方程式的配適度, 並衡量迴歸方程式的解釋能力 R = SSR/SST = - (SSE/SST) R R =: 自變數完全解釋依變數 R =: 自變數完全無法解釋依變數 65 66 R, 判定係數 (Coeffcet of Determato) R = R, 判定係數 (Coeffcet of Determato) R =.8 67 68 7
R, 判定係數 (Coeffcet of Determato) R = ANOVA Table SST = SSR = SSE = ( Y Y) ( Yˆ Y) ( Y Yˆ ) = ( Y ˆ α ˆ βx) 69 ANOVA Table Source df SS MS Regresso SSR SSR/ Error - SSE SSE/(-) Total - SST SST/- 7 迴歸解釋能力的檢定 Ex. 3.6 H : 迴歸無解釋能力 ( β = ) H : 迴歸有解釋能力 ( β ) SSR / MSR F檢定統計量 : F = = ~ F SSE / MSE 決策法則 : () F > F 拒絕 H () F F 接受 H,, α,, α, 7 大發公司的廣告支出與銷售額的變異數分析結果如下表, 請問迴歸模型可接受嗎? 變異來源平方和 (SS) 自由度 df 平均平方和 MS F 回歸 675887 675887 83.54 隨機 973 6 386 總和 868 7 7 8
Ex. 3.6 Ex. 3.6 計算公式與結果如下 而 MSR = SSR / = 675887 / = 675887 ˆ SSR= (Y- Y ) = 675887 SST = (Y- Y ) =868 ˆ SSE = (Y- Y ) = SST- SSR 故 MSE = SSE / (-) = 973 / 6 = 386 MSR 675887 F = = = 83.54 MSE 386 F F 檢定統計量大於臨界值,6,.5 = 5.99, 因此拒絕 H 此即表示迴歸模型是可接受的, 自變數與依變數有顯著關係, =868 675887= 973 73 迴歸方程式有解釋能力 74 Exercse, 3, 5, 7, 9,, 3, 5, 9,, 3, 5, 7, 9, 3, 33, 35, 37, 39, 43, 45, 47, 5, 55, 57, 59, 75 9