第十七單元邏輯斯迴歸分析 ( 一 ) 梁文敏教授葉懿諄統計分析師 邏輯斯迴歸分析適用於依變數為二元類別資料的情形, 又若自變數只有一個, 則此分析稱為簡單邏輯斯迴歸分析 (simple logistic regression) 或稱為單變數邏輯斯迴歸分析 (univariate logistic regression) 在邏輯斯迴歸分析中, 自變數可為連續變數或類別變數 本單元之自變數只有一個, 也就是職場壓力程度, 是一個類別變數, 此類分析除適用簡單邏輯斯分析外, 亦可適用於前一個單元所介紹的列聯表之卡方檢定 但邏輯斯迴歸分析優於列聯表之卡方檢定之處, 在於除了可檢定兩個變數之關係是否顯著外, 亦可以獲得勝算比 (odds ratio) 指標來顯示相關強度的大小 7. 單變數邏輯斯迴歸分析 ~~ 自變數為連續變數 ~~ 範例 年齡 (age) 對現在睡眠困擾 (sleeptr) 之影響 範例資料 : id age sleeptr 3.2 2 38.72 3 32.6 5 29.25 註 :sleeptr(: 沒有,: 有 ) 使用方法 : 本單元研究問題之依變數為是否有睡眠困擾 (sleeptr), 是一個二元類別變數, 違反了線性迴歸, 服從常態分布 因此例中只有一個自變數, 故利用簡單邏輯斯迴歸來探討年齡對於現在睡眠困擾之影響 軟體操作步驟 SSS 步驟 步驟一 : 選擇功能 Analyze 分析 進入 Regression 迴歸方法 進入 Binary Logistic 二元 Logistic 步驟二 : 在 Dependent 依變數框格中 ( 選入變數 :sleeptr) 在 Covariates 共變量框格中 ( 選入變數 :age) 在 Method 方法框格中 ( 選擇 :Enter 輸入 ) 步驟三 : 選擇進入 :Options 選項 勾選 :CI for exp(b) 95% 信賴區間 Continue 繼 - 2 -
續 步驟四 : 選擇 OK 確定 結果表格 Dependent Variable Encoding Original Value Internal Value 在邏輯斯分分析中, 依變變數的編碼碼必須加以注注意, 因其其可能會影響響到之後結結果的 解釋 如果沒有有注意可能會會將整個分分析結果作了了錯誤的解解讀 上表為為依變數的的編碼方式,Original Value 指依變變數的原始始編碼, 即是是資料中的的編碼 ; 而 Internal Value= 代表本本模式中所所探討的機率 (p) 為 Original Value= 的事件機機率 在此此例中依變數數為 - 22 -
sleeptr,sleeptr= 表示有睡眠困擾, 從上表中 Internal Value= 所對應的編碼可知, 本模式探討的機率 (p) 代表有睡眠困擾的機率 Classification Table a,b redicted Step Observed 現在睡眠困繞 Overall ercentage a. Constant is included in the model. b. The cut value is.5 現在睡眠困繞 ercentage Correct 2. 3. 6. Step Step Constant Variables Overall Statistics Variables in the Equation B S.E. Wald df Sig. Exp(B).45.289.973.6.5 Variables not in the Equation age Score df Sig. 5.642.8 5.642.8 Model Summary Step -2 Log likelihood 6.37 a Cox & Snell R Square.3 Nagelkerke R Square.52 a. Estimation terminated at iteration number 4 because parameter estimates changed by less than.. Variables in the Equation 95.% C.I.for EX(B) B S.E. Wald df Sig. Exp(B) Lower Upper Step a age.95.42 5.57.23.99.3.93 Constant -2.564.34 3.86.5.77 a. Variable(s) entered on step : age. 根據上表可以將模式寫成以下的的方程式 : log 2.564.95* age, 表示年齡每增加 歲 增加.99 倍 ( exp. 95. 99, 勝算比的信賴區間為 exp.95.96(.42) ~ exp.95.96(.42) 亦即.3~.93), 且有統計上顯著的意義 (p=.23) - 23 -
~~ 自變數為類別變數 ~~ 範例 壓力程度 (pressure) 對現在睡眠困擾 (sleeptr) 之影響 範例資料 : id pressure sleeptr 2 3 2 5 2 註 :pressure (: 無壓力,: 壓力中等,2: 壓力大 ) sleeptr(: 沒有,: 有 ) 使用方法 : 本單元研究問題之依變數為是否有睡眠困擾 (sleeptr), 是一個二元類別變數, 違反了線性迴歸中依變數必須服從常態分布的假設, 因為只有一個自變數, 故利用簡單邏輯斯迴歸來探討壓力程度對於現在睡眠困擾之影響 軟體操作步驟 SSS 步驟 步驟一 : 選擇功能 Analyze 分析 進入 Regression 迴歸方法 進入 Binary Logistic 二元 Logistic 步驟二 : 在 Dependent 依變數框格中 ( 選入變數 :sleeptr) 在 Covariates 共變量框格中 ( 選入變數 :pressure) 在 Method 方法框格中 ( 選擇 :Enter 輸入 ) 步驟三 : 選擇進入 :Categorical 類別 選入變數 :pressure 在 Contrast 比對框格中 ( 選擇 :Indicator 指標 ) 在 Reference Category 參考類別 ( 勾選 :First 第一個 ) Change 變更 Continue 繼續 步驟四 : 選擇進入 :Options 選項 勾選 :CI for exp(b) 95% 信賴區間 Continue 繼續 步驟五 : 選擇 OK 確定 - 24 -
- 25 -
結果表格 Dependent Variable Encoding Original Value.. Internal Value pressure.. 2. Categorical Variables Codings arameter coding Frequency () (2) 7.. 7.. 6.. 上表中 () 代表在結果中 ( 參下表 )pressure() 這個變數 ;(2) 代表 pressure(2) 這個變數 ;pressure() 及 pressure(2) 是兩個邏輯變數 : 當壓力中等 (pressure=) 時,pressure() 為 pressure(2) 為 ; 當壓力大組 (pressure=2) 時,pressure() 為 pressure(2) 為 以上的表格告訴我們現在壓力程度 (pressure, 自變數 ) 在模式中分別以 pressure() 及 pressure(2) 來表示, 當兩個變數均為 時, 表示為無壓力組 (pressure=) 從模式的解釋上兩個變數為 這一組是用來當作參照組的 註 : 在模式中, 類別變數一般會先轉換為虛擬變數, 若該類別變數有 k 個分類, 則需要 k- 個虛擬變數, 例如 : 在本例中, 職場壓力這個變數有 3 個分類, 故利用 2 (k-=3-) 個虛擬變數 分別為 pressure() 及 pressure(2) 來表示 Variables in the Equation 95.% C.I.for EX(B) pressure 9.98 2.7 Step a B S.E. Wald df Sig. Exp(B) Lower Upper pressure().482.735 4.58.44 4.4.4 8.599 pressure(2) 2.82.925 9.33.2 6.8 2.744 2.866 Constant -.875.532 2.75..47 a. Variable(s) entered on step : pressure. 根據以上的結果, 可以將模式寫成以下的方程式 : log -.875.482 * pressure() 2.82* pressure(2) 也就是 log -.875.482 * ( pressure ) 2.82* ( pressure 2) 代表有睡眠困擾的機率, 因此, 代入各種壓力程度 : sleeptr 表示 () 若 pressure=( 無壓力組 ), log -.875.482 * () 2.82* () exp, 表示當 pressure= (odd) 為 exp ; - 26 -
(2) 若 pressure=( 壓力中等組 ), log -.875.482 * () 2.82* () exp sleeptr, 表示當 pressure= (odd) 為 exp ; (2) 若 pressure=2( 壓力大組 ), log -.875.482 * () 2.82* () 2 exp sleeptr 2, 表示當 pressure=2 (odd) 為 exp 所以, 針對睡眠困擾 : pressure= 相對於 pressure= 的勝算比 (odds ratio)= pressure pressure exp. 482 exp exp exp 4.4 ; pressure=2 相對於 pressure= 的勝算比 (odds ratio)= pressure2 pressure 2 exp 2 2. 82 exp exp exp 6.8 壓力中等組 (pressure=) 為沒有壓力組 (pressure=) 的 4.4 倍 ( 勝算比的信賴區間為.4-8.599), 且有統計上顯著的意義 (p=.44); 壓力大組為無壓力組的 6.8 倍 ( 勝算比的信賴區間為 2.744~2.866), 且有統計上顯著的意義 (p=.2) 填填看 研究問題 目標變數 -- 類別變數 解釋變數 Factor(s) (F) Covariate (c) -- 類別變數 -- 連續變數 建立假設 檢定 方式 檢定值 p 值 年齡 (age) 對睡眠 sleeptr age H : age Wald χ 2 =5.57 p=.23 困擾 (sleeptr) 之 test 影響? 壓力程度 sleeptr ressure() H : pressure() Wald χ 2 =4.58 p=.44 (pressure) 對睡眠 ressure(2) H : pressure(2) test (pressure= v.s pressure=) 困擾 (sleeptr) 之 χ 2 =9.33 p=.2 影響? (pressure=2 v.s pressure=) 練習 : 性別 (sex) 對睡眠 困擾 (sleeptr) 之 影響? - 27 -