multiple regression 2560 - @@ home - kku web hosting · 6rxufh _ 66 gi 06 1xpehu ri rev ) 0rgho _...
TRANSCRIPT
1
การวเคราะหการถดถอยพห
(Multiple Regression Analysis)
ผชวยศาสตราจารยนคม ถนอมเสยง
สาขาวชาวทยาการระบาดและชวสถต
คณะสาธารณสขศาสตร มหาวทยาลยขอนแกน
Email: [email protected] Web: http://home.kku.ac.th/nikom
การวเคราะหการถดถอย
เกยวของกบตวแปร 2 ตวแปร ขนไป
ตวแปรอสระ (independent variables) หรอตวแปรอรรถาธบาย
(explanatory variables)
-ตวแปรตาม (dependent variable) หรอตวแปรตอบสนอง
(response variable)
ipx
pxxy ,...,22110
ˆ
การวเคราะหการถดถอยพห (Multiple Regression)
การวเคราะหการถดถอยอยางงาย (Simple Regression)
bxay ˆ
2
วตถประสงคการวเคราะหการถดถอยพห
วดความสมพนธเชงเสนระหวางตวแปรอสระ
(independent variables) หรอตวแปรอธบาย (explanatory variables)
กบตวแปรตาม (dependent variable) หรอ response variable
ทานาย (prediction)
Systolic BPCHOL
TRI
AGE
...
idno sysbp chol age tri idno sysbp chol age tri
1 155 375 66 230 11 132 304 40 140
2 136 290 49 161 12 164 428 51 175
3 133 267 47 187 13 136 282 56 159
4 166 340 55 178 14 73 165 36 44
5 111 282 42 112 15 153 395 51 181
6 150 352 71 125 16 135 324 54 164
7 131 285 39 149 17 149 426 51 205
8 167 383 59 208 18 149 337 57 189
9 166 363 60 208 19 142 347 45 152
10 126 283 48 138 20 148 349 55 194
ตวอยาง การศกษาความสมพนธระหวางอาย ระดบ cholesterol
ระดบ triglyceride กบ systolic blood pressure
3
ขอมลตวแปร sysbp และเมตรกซตวแปรอสระ (chol, age,tri)
148
...
133
136
155
y
194553491
...
187472671
161492901
230663751
x
การคานวณสมประสทธการวเคราะหการถดถอยพห
-ใชวธ least square method โดยใช matrix approach
ipx
pxx
iy ,...,
22110ˆ
วธคานวณ least square โดยใชเมตรกซ
1xpYX1)
pXpXX(
1xpb
4
วธคานวณสมประสทธโดยใชเมตรกซ
Source | SS df MS Number of obs = 20---------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696---------+------------------------------ Adj R-squared = 0.8451
Total | 9133.80 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------chol | .1654515 .0496455 3.333 0.004 .0602077 .2706953age | .5122311 .2802612 1.828 0.086 -.0818961 1.106358tri | .2006968 .0745745 2.691 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.120 0.050 -.0007308 54.31117------------------------------------------------------------------------------
วธคานวณสมประสทธโดยใช STATA
5
(ก.) ความสมพนธเชงเสนระหวางตวแปรตามและ
กลมของตวแปรอสระ
เพอสรปวาตวแปรอสระ k ตวแปรสามารถอธบายความผนแปร
ของตวแปร Y ไดหรอไม
การทดสอบสมมตฐาน
การสรปภาพรวม ใชตารางการวเคราะหความแปรปรวน (ANOVA)
สาหรบการวเคราะหการถดถอย เพอคานวณคา Overall F Test
0210
k
β...β:βH 0:0 ik
βHหรอ
0: ik
βH A
MSR
ตาราง ANOVA สาหรบการวเคราะหการถดถอย
triagecholiY 20.51.17.16.27ˆ
Source | SS df MS Number of obs = 20---------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696---------+------------------------------ Adj R-squared = 0.8451
Total | 9133.80 19 480.726316 Root MSE = 8.6281
หรอ
Overall F Test
6
สมมตฐานสาหรบการทดสอบนยสาคญของสมการถดถอยทงหมด
H0 : ตวแปรอสระ k ตวแปรไมสามารถอธบายความผนแปร
ของตวแปร Y ได
หรอ
HA : ตวแปรอสระ k ตวแปรสามารถอธบายความผนแปร
ของตวแปร Y ได
หรอ HA : อยางนอย 1 ตวแปร
การทดสอบใชสถต F-test
0210
k
β...β:βH
0: ik
βH A
MSE
MSR
error)(or residualsquaremean
model)(or regressionsquaremeanF
ตวแปรอสระแตละตวแปรไมม
ความสมพนธเชงเสนกบตวแปรตาม
ตวแปรอสระอยางนอย 1 ตวแปร ม
ความสมพนธเชงเสนกบตวแปรตาม
0:0 ik
βH
k
kn
R
RF
121
2
SSY
SSR
SSY
SSESSYR
2
หรอคานวณคา F จาก
การคานวณคา
n=ขนาดตวอยาง
k=จานวนตวแปร
R2 = coefficient of determination
เมอ
7
Source | SS df MS Number of obs = 20---------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696---------+------------------------------ Adj R-squared = 0.8451
Total | 9133.80 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
---------+--------------------------------------------------------------------chol | .1654515 .0496455 3.333 0.004 .0602077 .2706953age | .5122311 .2802612 1.828 0.086 -.0818961 1.106358tri | .2006968 .0745745 2.691 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.120 0.050 -.0007308 54.31117------------------------------------------------------------------------------
การวเคราะห ตวแปรอสระไดแก อาย ระดบ cholesterol
ระดบ triglyceride สามารถอธบายการเปลยนแปลง
ระดบความดนชนด systolic blood pressure ได
อยางนยสาคญทางสถต (F= 35.56, p<.0001)(มตวแปรอสระอยางนอย 1 ตวแปรมความสมพนธเชงเสนกบตวแปรตาม)
ข. การวเคราะหความสมพนธเชงเสน ตวแปรอสระแตละตวแปร
มความสมพนธกบตวแปรตาม
การทดสอบสมมตฐาน H0: i = 0; HA: i 0
เมอ คอสมประสทธและ คอ standard error
i
i
S
βt
ˆ i
iS ˆ
. regress sysbp chol age tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.80 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007309 54.31117------------------------------------------------------------------------------
8
. regress sysbp chol age tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.80 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007309 54.31117------------------------------------------------------------------------------
การแปลความหมาย -แปลผลโดยพจารณาเครองหมาย
-พจารณา ความสมพนธระหวางตวแปรอสระกบตวแปรตาม
ตวแปร chol, tri มความสมพนธทางบวกกบ sysbp และมนยสาคญทางสถต
ตวแปร age ไมมความสมพนธกบ sysbp (มความสมพนธแตไมมนยสาคญ
ทางสถต)
การพจารณาตวแปรอสระแตละตวแปรมความสมพนธ
กบตวแปรตามมากนอย
-พจารณาจากสมการทมการปรบตวแปรมหนวยเดยวกน
-ทา Xi ใหเปนคะแนนมาตรฐาน Z-score
yy
xxi
S
Sor
sd
xxz *;
. regress sysbp chol age tri, beta
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.80 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| Beta
-------------+----------------------------------------------------------------chol | .1654515 .0496455 3.33 0.004 .4663705age | .5122311 .2802612 1.83 0.086 .2076355tri | .2006968 .0745745 2.69 0.016 .3805016
_cons | 27.15522 12.80998 2.12 0.050 .------------------------------------------------------------------------------
9
.zscore sysbp chol age tri
.regress z_sysbp z_chol z_age z_tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 16.5222943 3 5.50743142 Prob > F = 0.0000Residual | 2.47770574 16 .154856609 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 19.00 19 1.00 Root MSE = .39352
------------------------------------------------------------------------------z_sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------z_chol | .4663705 .1399396 3.33 0.004 .1697118 .7630292z_age | .2076355 .1136053 1.83 0.086 -.033197 .448468z_tri | .3805016 .1413859 2.69 0.016 .0807768 .6802263_cons | 3.62e-16 .0879934 0.00 1.000 -.1865376 .1865376
------------------------------------------------------------------------------
. di .16545147*(61.802976/21.925472)
.46637049
. di .51223109*(8.8876022/21.925472)
.20763549
. di .20069683*(41.568555/21.925472)
.3805016
กรณทาใหเปนคะแนนมาตรฐาน Z-scoresd
xxz i
Constant มคานอยมาก ~ 0
yy
xx
S
S *
2
2
1
1
ˆ2
21
n
i)Y(Y
n
i)Y
iY(
SSY
SSR
k...x,xy|x
R
i
. regress sysbp chol age tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.80 19 480.726316 Root MSE = 8.6281
0.869594 9133.80
7942.70165
ตวอยาง จากขอมลตวอยางคานวณคาของ coefficient of determination
-ตวแปร chol ,age และ trigyceride สามารถอธบายการเปลยนแปลง
(ความแปรปรวน) ระดบ systolic blood pressure ไดถงรอยละ 86.96
สมการทานายและการประเมนสมการถดถอยพห สมการทานาย: การประเมนสมการถดถอยพห พจารณาจากคาสมประสทธการกาหนด
(coefficient of determination
)(20.0)(51.0)(17.016.27ˆ triagecholyi
10
ในการ fit สมการพบวาเมอจานวนตวแปรอสระมากขน
ทาใหคา R2 สงขน ควรมการปรบคา R2 เรยกวา
“Adjusted coefficient of determination”
SSY
SSR
pn
na
R
12
. regress sysbp chol age tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.80 19 480.726316 Root MSE = 8.6281
Adjusted coefficient of determination
Report Regression Table (Publication Manual of the American Psychological
Association sixth Edition,2010; pp 144)
11
0.050
0.016
0.086
0.004
P-value
Adjusted R2 = .85 , F = 35.56, p-value <.0001, n = 20
.00-54.312.1212.8127.16Constant
.06.87.04-3.36.382.69.07.20Trigyceride
.07.81-.08-1.11.211.83.28.51Age
.75.75.06-.07.473.33.05.17Cholesterol
R2 changeR295%CIWald (t)s.e.bVariable
. regress sysbp chol age triSource | SS df MS Number of obs = 20
-------------+------------------------------ F( 3, 16) = 35.56Model | 7942.70165 3 2647.56722 Prob > F = 0.0000
Residual | 1191.09835 16 74.4436471 R-squared = 0.8696-------------+------------------------------ Adj R-squared = 0.8451
Total | 9133.80 19 480.726316 Root MSE = 8.6281------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007309 54.31117------------------------------------------------------------------------------
*Recommended Report (Lang, et al. (1997). How to report Statistics in Medicine.pp,115
. do "M:\516701_2555\report_mreg.do"
. use "M:\516701_2555\multiple_reg_data.dta", clear
. regress sysbp chol
...Residual | 2267.92107 17 133.407122 R-squared = 0.7516
...
. regress sysbp chol ageResidual | 1729.02942 16 108.064339 R-squared = 0.8106
...
. regress sysbp chol age triResidual | 1191.02416 15 79.4016106 R-squared = 0.8696
...
. regress sysbp chol age tri, betaSource | SS df MS Number of obs = 20
-------------+------------------------------ F( 3, 16) = 35.56Model | 7942.70165 3 2647.56722 Prob > F = 0.0000
Residual | 1191.09835 16 74.4436471 R-squared = 0.8696-------------+------------------------------ Adj R-squared = 0.8451
Total | 9133.8 19 480.726316 Root MSE = 8.6281------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| Beta-------------+----------------------------------------------------------------
chol | .1654515 .0496455 3.33 0.004 .4663705age | .5122311 .2802612 1.83 0.086 .2076355tri | .2006968 .0745745 2.69 0.016 .3805016
_cons | 27.15522 12.80998 2.12 0.050 .------------------------------------------------------------------------------
12
การวเคราะห multiple regression เมอมตวแปรกลม เชน เพศ อาชพ
ทาใหเปนตวแปรหน (dummy variables) ดงน
pp
k
ljljl xDxy
j
1
10 1
ˆ
กรณมตวแปรม k ระดบ สรางตวแปรหนไดเทากบ k-1 ตวแปร(k=ระดบ, กลม)
0
1
0
D1
ตวแปรหน (dummy variable)
1Code = 3
0code = 2
0code = 1
D2ตวแปร
)(1
ˆ 654320 gender)(occβ)(occβ(tri)β(age)β(chol)ββy officecomm
ตวอยาง ตวแปรอาชพ (เกษตรกรรม, คาขาย, ขาราชการ) เปนตวแปรกลม
ใหทาเปน ตวแปรหน k-1=3-1 = 2 ตวแปร ดงน
STATA ระบ xi: regresst sysbp age tri i.occ i.gender
0
1
0
D1
ตวแปรหน (dummy variable)
1รบราชการ = 3
0คาชาย = 2
0เกษตรกรรม = 1
D2อาชพ
*** กรณม 2 กลม เพศ รหสเปน 0, 1 วเคราะหในโปรแกรม STATA ไดเลย
ถามรหส 1, 2 กาหนดเปน ตวแปรหน
13
. xi: regress sysbp chol age tri i.occ i.gender
. xi: regress sysbp chol age tri i.occ i.genderi.occ _Iocc_1-3 (naturally coded; _Iocc_1 omitted)i.gender _Igender_1-2 (naturally coded; _Igender_1 omitted)
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 6, 13) = 16.99
Model | 8101.00425 6 1350.16737 Prob > F = 0.0000Residual | 1032.79575 13 79.4458272 R-squared = 0.8869
-------------+------------------------------ Adj R-squared = 0.8347Total | 9133.8 19 480.726316 Root MSE = 8.9132
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1745477 .0564986 3.09 0.009 .0524899 .2966054age | .504353 .3139673 1.61 0.132 -.173932 1.182638tri | .2081322 .0796249 2.61 0.021 .036113 .3801514
_Iocc_2 | 5.242509 5.77858 0.91 0.381 -7.241355 17.72637_Iocc_3 | -1.13821 5.298263 -0.21 0.833 -12.58441 10.30799
_Igender_2 | -4.495496 4.72941 -0.95 0.359 -14.71276 5.721772_cons | 24.02471 13.96057 1.72 0.109 -6.135272 54.18469
------------------------------------------------------------------------------
. list+-------------------------------------------------------------------------------+| idno sysbp chol age tri occ gender _Iocc_2 _Iocc_3 _Igend~2 ||-------------------------------------------------------------------------------|
1. | 1 155 375 66 230 3 2 0 1 1 |2. | 2 136 290 49 161 1 1 0 0 0 |3. | 3 133 267 47 187 1 1 0 0 0 |4. | 4 166 340 55 178 2 1 1 0 0 |5. | 5 111 282 42 112 2 2 1 0 1 |
|-------------------------------------------------------------------------------|6. | 6 150 352 71 125 3 1 0 1 0 |7. | 7 131 285 39 149 2 2 1 0 1 |8. | 8 167 383 59 208 3 1 0 1 0 |9. | 9 166 363 60 208 1 1 0 0 0 |
10. | 10 126 283 48 138 2 2 1 0 1 ||-------------------------------------------------------------------------------|
11. | 11 132 304 40 140 3 1 0 1 0 |12. | 12 164 428 51 175 2 2 1 0 1 |13. | 13 136 282 56 159 3 1 0 1 0 |14. | 14 73 165 36 44 1 1 0 0 0 |15. | 15 153 395 51 181 1 2 0 0 1 |
|-------------------------------------------------------------------------------|16. | 16 135 324 54 164 2 1 1 0 0 |17. | 17 149 426 51 205 3 1 0 1 0 |18. | 18 149 337 57 189 1 1 0 0 0 |19. | 19 142 347 45 152 3 2 0 1 1 |20. | 20 148 349 55 194 3 2 0 1 1 |
+-------------------------------------------------------------------------------+
14
การคดเลอกตวแปรอสระเขาในสมการ: การวเคราะหการถดถอยพห
1. Forward selection Procedure
- พจารณานาเขาตวแปรอสระทละ 1 ตวแปร
2. Backward elimination procedure
- พจารณาขจดออกทละ 1 ตวแปร
3. The Stepwise regression procedure
- ใชวธ Forward & Backward
* การพจารณาตวแปรจาก คาสถต และ P-value
Probability to Entry (Pe)
Probability to Remove (Pr)
วธการขจดออก (Backward elimination procedure)
ขนท 1 สรางสมการถดถอยประกอบดวย ตวแปรอสระทกตวแปร
SYSBP = 27.16 + 0.165CHOL + 0.512AGE + 0.201TRI
ขนท 2 คานวณคาสถต Partial t และ p-value ตวแปรอสระทกตวแปรในโมเดล
ขนท 3 พจารณาตวแปรทมคา p-value มากทสด
. regress sysbp chol age tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.80 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007309 54.31117------------------------------------------------------------------------------
15
ขนท 4 เปรยบเทยบคา p-value กบ ระดบนยสาคญ
ทกาหนด ( เชน Pr = 0.05)
ถา p-value > ระดบนยสาคญทกาหนด จะตดตวแปร
นนออกจากสมการ
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007309 54.31117------------------------------------------------------------------------------
ขจดตวแปร age ออก (p-value = .086 > 0.05)
ทาการทดสอบตามขนตอนท 1 ถง ขนตอนท 4 ใหมกบ
ตวแปรทเหลอจนกวาไมมตวแปรใดมากกวาระดบนยสาคญ
ทกาหนด (เชน Pr=0.05)
. regress sysbp chol tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 2, 17) = 45.42
Model | 7694.02578 2 3847.01289 Prob > F = 0.0000Residual | 1439.77422 17 84.6926011 R-squared = 0.8424
-------------+------------------------------ Adj R-squared = 0.8238Total | 9133.80 19 480.726316 Root MSE = 9.2029
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10278------------------------------------------------------------------------------
16
วธการขจดออก (Backward elimination procedure). sw regress sysbp chol age tri, pr(.05)
begin with full modelp = 0.0863 >= 0.0500 removing age
Source | SS df MS Number of obs = 20---------+------------------------------ F( 2, 17) = 45.42
Model | 7694.02578 2 3847.01289 Prob > F = 0.0000Residual | 1439.77422 17 84.6926011 R-squared = 0.8424---------+------------------------------ Adj R-squared = 0.8238
Total | 9133.80 19 480.726316 Root MSE = 9.2029------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]---------+--------------------------------------------------------------------
chol | .1875776 .0513543 3.653 0.002 .0792295 .2959258tri | .238911 .0763522 3.129 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.503 0.003 15.91068 64.10278------------------------------------------------------------------------------
. stepwise, pr(.05) : regress sysbp chol age tribegin with full model
p = 0.0863 >= 0.0500 removing age...
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
วธนาเขา (Forward selection procedure)
ขนท 1 เลอกตวแปรอสระตวแรกเขามาในสมการ โดยมคาสหสมพนธ
กบตวแปรตามมากทสด และ P-Value < ระดบนยสาคญ
ทกาหนด (เชน Pe=0.05)
-จากตวอยางพบวาสหสมพนธเปนดงน
rSYSBP-CHOL = .8669
rSYSBP-AGE = .6873
rSYSBP-TRI = .8477
-ดงนนตวแปร CHOL เปนตวแปรอสระตวแปรแรกทนาเขาในสมการ
*หรอ fit สมการการถดถอยอยางงายทละตวแปร
. pwcorr sysbp chol age tri, sig| sysbp chol age tri
-------------+------------------------------------sysbp | 1.0000
|chol | 0.8669 1.0000
| 0.0000|
age | 0.6873 0.5609 1.0000| 0.0008 0.0101|
tri | 0.8477 0.7467 0.5732 1.0000| 0.0000 0.0002 0.0082
17
. regress sysbp cholSource | SS df MS Number of obs = 20
-------------+------------------------------ F( 1, 18) = 54.46Model | 6864.79657 1 6864.79657 Prob > F = 0.0000
Residual | 2269.00343 18 126.055746 R-squared = 0.7516-------------+------------------------------ Adj R-squared = 0.7378
Total | 9133.8 19 480.726316 Root MSE = 11.227
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .3075584 .0416769 7.38 0.000 .2199986 .3951183
_cons | 39.95941 13.93348 2.87 0.010 10.68625 69.23256------------------------------------------------------------------------------
. regress sysbp tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 1, 18) = 45.98
Model | 6564.09077 1 6564.09077 Prob > F = 0.0000Residual | 2569.70923 18 142.761624 R-squared = 0.7187
-------------+------------------------------ Adj R-squared = 0.7030Total | 9133.8 19 480.726316 Root MSE = 11.948
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------tri | .4471421 .0659423 6.78 0.000 .3086025 .5856817
_cons | 67.34391 11.2005 6.01 0.000 43.81254 90.87528------------------------------------------------------------------------------
. regress sysbp age
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 1, 18) = 16.12
Model | 4315.03667 1 4315.03667 Prob > F = 0.0008Residual | 4818.76333 18 267.709074 R-squared = 0.4724
-------------+------------------------------ Adj R-squared = 0.4431Total | 9133.8 19 480.726316 Root MSE = 16.362
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------age | 1.695629 .4223477 4.01 0.001 .8083094 2.582949
_cons | 53.60554 22.09811 2.43 0.026 7.179137 100.032------------------------------------------------------------------------------
18
-และสรางสมการถดถอยระหวางตวแปรตามกบตวแปรอสระทนาเขา
สรางสมการ SYSBP กบ CHOL และคานวณคา Overall F
จากตาราง ANOVA
SYSBP = 39.96 + .308CHOL และมคา Overall F เทากบ 54.45
-ถาคา Overall F จากตาราง ANOVA ไมมนยสาคญทางสถต
แสดงวาไมมตวแปรใดอยในสมการถดถอย จะหยดการนาเขา
-กรณทคา Overall F จากตาราง ANOVA มนยสาคญทางสถต
จะนาเขาตวแปรอสระตอไป
. regress sysbp chol
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 1, 18) = 54.46
Model | 6864.79657 1 6864.79657 Prob > F = 0.0000Residual | 2269.00343 18 126.055746 R-squared = 0.7516
-------------+------------------------------ Adj R-squared = 0.7378Total | 9133.80 19 480.726316 Root MSE = 11.227
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .3075584 .0416769 7.38 0.000 .2199986 .3951183
_cons | 39.95941 13.93348 2.87 0.010 10.68625 69.23256------------------------------------------------------------------------------
-คา Overall F จากตาราง ANOVA มนยสาคญทางสถต จะนาเขา
ตวแปรอสระ อนๆ เขาไปในสมการ ตอไป
19
ขนท 2 พจารณาตวแปรท 2 เขาโมเดลคานวณสถต Partial t (p-value) ของตวแปรอสระทเหลออย โดยพจารณาสราง (fit) โมเดลตวแปรทเหลอกบตวแปรตามและตวแปรอสระทอยในโมเดล เชน-Partial t =3.13 (p-value=.006) จาก sysbp tri chol
regress sysbp tri cholSource | SS df MS Number of obs = 20
-------------+------------------------------ F( 2, 17) = 45.42Model | 7694.02578 2 3847.01289 Prob > F = 0.0000
Residual | 1439.77422 17 84.6926011 R-squared = 0.8424-------------+------------------------------ Adj R-squared = 0.8238
Total | 9133.8 19 480.726316 Root MSE = 9.2029------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
tri | .238911 .0763522 3.13 0.006 .0778219 .4chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
. pcorr sysbp tri chol(obs=20)Partial correlation of sysbp with
Variable | Corr. Sig.-------------+------------------
tri | 0.6045 0.006chol | 0.6631 0.002
)1)(1( 22XZYZ
XZYZYXYX|Z
rr
rrrr
*ใชวธ partial correlation ไดใหผลเชนเดยวกน
)1)(1( 22choltricholsysbp
choltricholsysbptrisysbptri|cholsysbp
rr
rrrr
ขนท 2 พจารณาตวแปรท 2 เขาโมเดลคานวณสถต Partial t (p-value) ของตวแปรอสระทเหลออย โดยพจารณาสราง (fit) โมเดลตวแปรทเหลอกบตวแปรตามและตวแปรอสระทอยในโมเดล เชน-Partial t =2.30 (p-value=.034) จาก sysbp age chol
. regress sysbp age cholSource | SS df MS Number of obs = 20
-------------+------------------------------ F( 2, 17) = 36.37Model | 7403.52843 2 3701.76422 Prob > F = 0.0000
Residual | 1730.27157 17 101.780681 R-squared = 0.8106-------------+------------------------------ Adj R-squared = 0.7883
Total | 9133.8 19 480.726316 Root MSE = 10.089------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
age | .7236989 .3145605 2.30 0.034 .0600341 1.387364chol | .2491839 .0452355 5.51 0.000 .1537453 .3446225
_cons | 21.81301 14.79754 1.47 0.159 -9.407062 53.03308------------------------------------------------------------------------------
. pcorr sysbp age chol(obs=20)Partial correlation of sysbp with
Variable | Corr. Sig.-------------+------------------
age | 0.4873 0.034chol | 0.8006 0.000
)1)(1( 22XZYZ
XZYZYXYX|Z
rr
rrrr
*ใชวธ partial correlation ไดใหผลเชนเดยวกน
)1)(1( 22cholagecholsysbp
cholagecholsysbpagesysbpage|cholsysbp
rr
rrrr
20
จากขอมลตวอยางตวแปร TRI มคา Partial t มากทสดและ
p-value นอยกวา (pe=0.05) ใหนาตวแปร TRI เพอไปลอง fit
ในโมเดล สมการถดถอย
.regress sysbp tri chol…------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
tri | .238911 .0763522 3.13 0.006 .0778219 .4chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
. regress sysbp age chol…------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
age | .7236989 .3145605 2.30 0.034 .0600341 1.387364chol | .2491839 .0452355 5.51 0.000 .1537453 .3446225
_cons | 21.81301 14.79754 1.47 0.159 -9.407062 53.03308------------------------------------------------------------------------------
ขนท 3 พจารณาตวแปรอสระทนาเขาหาคา Partial t และ p-value
รวมกบตวแปรอสระทนาเขากอน
ถา
(ก.) P-value < ระดบนยสาคญทางสถตทกาหนด (Pe) ใหนาเขา
ตวแปรดงกลาวในโมเดลสมการถดถอย
(ข.) P-value > ระดบนยสาคญทางสถตทกาหนด (Pe) คงใชโมเดล
ในขอท 1
21
ขนท 4 ทาตามขนตอนท 2-3 ซากบตวแปรทเหลอ ทาเชนนจนครบทก
ตวแปรอสระ จนไมมตวแปรใดท มนยสาคญทางสถตทกาหนด ใหยต
การนาเขา (1) ใช Multiple Regression (sysbp age chol tri). regress sysbp age chol tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.8 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007311 54.31117------------------------------------------------------------------------------
. pcorr sysbp age chol tri(obs=20)Partial correlation of sysbp with
Variable | Corr. Sig.-------------+------------------
age | 0.4156 0.086chol | 0.6401 0.004tri | 0.5582 0.016
หรอ (2) ใช Partial Correlation
ดท Partial t โดย p-value = 0.086 > นยสาคญทางสถตทกาหนด
(pe=0.05) คงใชโมเดลเดม
. regress sysbp age chol tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.8 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007311 54.31117------------------------------------------------------------------------------
22
. regress sysbp chol tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 2, 17) = 45.42
Model | 7694.02578 2 3847.01289 Prob > F = 0.0000Residual | 1439.77422 17 84.6926011 R-squared = 0.8424
-------------+------------------------------ Adj R-squared = 0.8238Total | 9133.80 19 480.726316 Root MSE = 9.2029
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10278------------------------------------------------------------------------------
ดท Partial t โดย p-value = 0.086 > นยสาคญทางสถตทกาหนด
(pe=0.05) คงใชโมเดลเดม
วธนาเขา (Forward selection procedure). sw regress sysbp chol age tri, pe(.05)
begin with empty modelp = 0.0000 < 0.0500 adding cholp = 0.0061 < 0.0500 adding tri
Source | SS df MS Number of obs = 20---------+------------------------------ F( 2, 17) = 45.42
Model | 7694.02578 2 3847.01289 Prob > F = 0.0000Residual | 1439.77422 17 84.6926011 R-squared = 0.8424---------+------------------------------ Adj R-squared = 0.8238
Total | 9133.80 19 480.726316 Root MSE = 9.2029------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]---------+--------------------------------------------------------------------
chol | .1875776 .0513543 3.653 0.002 .0792295 .2959258tri | .238911 .0763522 3.129 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.503 0.003 15.91068 64.10278------------------------------------------------------------------------------
. stepwise, pe(.05) : regress sysbp chol age tribegin with empty model
p = 0.0000 < 0.0500 adding cholp = 0.0061 < 0.0500 adding tri
...------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
23
วธสมการถดถอยแบบขนตอน (Stepwise regression procedure). sw regress sysbp chol age tri, pr(0.1) pe(.05) forward
begin with empty modelp = 0.0000 < 0.0500 adding cholp = 0.0061 < 0.0500 adding tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 2, 17) = 45.42
Model | 7694.02578 2 3847.01289 Prob > F = 0.0000Residual | 1439.77422 17 84.6926011 R-squared = 0.8424
-------------+------------------------------ Adj R-squared = 0.8238Total | 9133.8 19 480.726316 Root MSE = 9.2029
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
. stepwise, pr(.10) pe(.05) forward: regress sysbp chol age tribegin with empty model
p = 0.0000 < 0.0500 adding cholp = 0.0061 < 0.0500 adding tri
...------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
วธสมการถดถอยแบบขนตอน (Stepwise regression procedure)
เปนวธทคดเลอกตวแปรอสระรวมกน ระหวางวธขจดออกและวธนาเขา
ขนท 1 เลอกตวแปรอสระตวแรกเขามาในสมการ โดยมคาสหสมพนธ
กบตวแปรตามมากทสด และ P-Value < ระดบนยสาคญ
ทกาหนด (เชน Pe=0.05)
-จากตวอยางพบวาสหสมพนธเปนดงน
rSYSBP-CHOL = .8669
rSYSBP-AGE = .6873
rSYSBP-TRI = .8477
-ดงนนตวแปร CHOL เปนตวแปรอสระตวแปรแรกทนาเขาในสมการ
*หรอ fit สมการการถดถอยอยางงายทละตวแปร
. pwcorr sysbp chol age tri, sig| sysbp chol age tri
-------------+------------------------------------sysbp | 1.0000
|chol | 0.8669 1.0000
| 0.0000|
age | 0.6873 0.5609 1.0000| 0.0008 0.0101|
tri | 0.8477 0.7467 0.5732 1.0000| 0.0000 0.0002 0.0082
24
fit สมการการถดถอยอยางงายทละตวแปร เลอกตวแปรอสระทมความสมพนธกบ
ตวแปรตามสงกอน. regress sysbp chol...------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
chol | .3075584 .0416769 7.38 0.000 .2199986 .3951183_cons | 39.95941 13.93348 2.87 0.010 10.68625 69.23256
------------------------------------------------------------------------------
. regress sysbp age
...------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
age | 1.695629 .4223477 4.01 0.001 .8083094 2.582949_cons | 53.60554 22.09811 2.43 0.026 7.179137 100.032
------------------------------------------------------------------------------
. regress sysbp tri
...------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
tri | .4471421 .0659423 6.78 0.000 .3086025 .5856817_cons | 67.34391 11.2005 6.01 0.000 43.81254 90.87528
------------------------------------------------------------------------------
ขนท 2 พจารณาตวแปรท 2 เขาโมเดล คานวณสถต Partial t (p-value) ของตวแปรอสระทเหลออย โดยพจารณาสราง (fit) โมเดลตวแปรทเหลอกบตวแปรตามและตวแปรอสระทอยในโมเดล เชน-Partial t =3.13 (p-value=.006) จาก sysbp tri chol
regress sysbp tri cholSource | SS df MS Number of obs = 20
-------------+------------------------------ F( 2, 17) = 45.42Model | 7694.02578 2 3847.01289 Prob > F = 0.0000
Residual | 1439.77422 17 84.6926011 R-squared = 0.8424-------------+------------------------------ Adj R-squared = 0.8238
Total | 9133.8 19 480.726316 Root MSE = 9.2029------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
tri | .238911 .0763522 3.13 0.006 .0778219 .4chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
. pcorr sysbp tri chol(obs=20)Partial correlation of sysbp with
Variable | Corr. Sig.-------------+------------------
tri | 0.6045 0.006chol | 0.6631 0.002
)1)(1( 22XZYZ
XZYZYXYX|Z
rr
rrrr
*ใชวธ partial correlation ไดใหผลเชนเดยวกน
)1)(1( 22choltricholsysbp
choltricholsysbptrisysbptri|cholsysbp
rr
rrrr
25
ขนท 2 พจารณาตวแปรท 2 เขาโมเดล คานวณสถต Partial t (p-value) ของตวแปรอสระทเหลออย โดยพจารณาสราง (fit) โมเดลตวแปรทเหลอกบตวแปรตามและตวแปรอสระทอยในโมเดล เชน-Partial t =2.30 (p-value=.034) จาก sysbp age chol
. regress sysbp age cholSource | SS df MS Number of obs = 20
-------------+------------------------------ F( 2, 17) = 36.37Model | 7403.52843 2 3701.76422 Prob > F = 0.0000
Residual | 1730.27157 17 101.780681 R-squared = 0.8106-------------+------------------------------ Adj R-squared = 0.7883
Total | 9133.8 19 480.726316 Root MSE = 10.089------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
age | .7236989 .3145605 2.30 0.034 .0600341 1.387364chol | .2491839 .0452355 5.51 0.000 .1537453 .3446225
_cons | 21.81301 14.79754 1.47 0.159 -9.407062 53.03308------------------------------------------------------------------------------
. pcorr sysbp age chol(obs=20)Partial correlation of sysbp with
Variable | Corr. Sig.-------------+------------------
age | 0.4873 0.034chol | 0.8006 0.000
)1)(1( 22XZYZ
XZYZYXYX|Z
rr
rrrr
*ใชวธ partial correlation ไดใหผลเชนเดยวกน
)1)(1( 22cholagecholsysbp
cholagecholsysbpagesysbpage|cholsysbp
rr
rrrr
จากขอมลตวอยาง ตวแปร triglyceride มคา Partial t มากทสดและ p-value
นอยกวา (Pe < 0.05) ใหนาตวแปร trigyceride เพอไป fit ในโมเดล สมการถดถอยพห
.regress sysbp tri chol…------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
tri | .238911 .0763522 3.13 0.006 .0778219 .4chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
. regress sysbp age chol…------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
age | .7236989 .3145605 2.30 0.034 .0600341 1.387364chol | .2491839 .0452355 5.51 0.000 .1537453 .3446225
_cons | 21.81301 14.79754 1.47 0.159 -9.407062 53.03308------------------------------------------------------------------------------
ขนท 2 พจารณาตวแปรท 2 เขาโมเดล
26
ขนท 3 พจารณาขจดตวแปรออกจากโมเดล fit โมเดลสมการถดถอยแลวพจารณาคา Partial t (P-value) ตวแปรอสระทอยในสมการถดถอย
พจารณาคา Partial t และ p-value (Pr) Probability to Remove (Pr) > ระดบนยสาคญทกาหนด (p-value) จะตดตวแปรนน
ออกจากสมการ Probability to Remove (Pr) < ระดบนยสาคญทกาหนด (p-value) คงตวแปรอย
ในสมการ. regress sysbp chol tri...------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
คา Probability to Remove (Pr) ตวแปร cholesterol, trigyceride < ระดบนยสาคญ
ทกาหนด (0.05) คงตวแปรทง 2 อยในสมการ
ขนท 4 ทาตามขนตอนท 2-3 ซากบตวแปรทเหลอ ในทนคอ ageพจารณานาเขา (ขนตอนท 2)
พจารณาคา Partial t, p-value (Pe) จากสมการถดถอย
กรณ Pribability to Entry (Pe) < ระดบนยสาคญทกาหนด (0.05) ยตการนาเขา
กรณทสามารถนาเขาตวแปรอสระได ใหทาขนตอน 2-3 จนครบทกตวแปร จนไมม
ตวแปรใดท Pe นอยกวาระดบนยสาคญทกาหนด ใหยตการนาเขา. regress sysbp age chol tri
…------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007311 54.31117------------------------------------------------------------------------------
คา Probability to Entry (Pe) ตวแปร age (0.086) > ระดบนยสาคญทกาหนด (0.05)
ยตการนาเขา (ไมตองทาขนตอนท 3)
27
. regress sysbp chol tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 2, 17) = 45.42
Model | 7694.02578 2 3847.01289 Prob > F = 0.0000Residual | 1439.77422 17 84.6926011 R-squared = 0.8424
-------------+------------------------------ Adj R-squared = 0.8238Total | 9133.80 19 480.726316 Root MSE = 9.2029
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10278------------------------------------------------------------------------------
ใชโมเดลเดม SYSBP = 40.01 + .188CHOL + .239TRI
วธสมการถดถอยแบบขนตอน (Stepwise regression procedure). sw regress sysbp chol age tri, pr(0.1) pe(.05) forward
begin with empty modelp = 0.0000 < 0.0500 adding cholp = 0.0061 < 0.0500 adding tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 2, 17) = 45.42
Model | 7694.02578 2 3847.01289 Prob > F = 0.0000Residual | 1439.77422 17 84.6926011 R-squared = 0.8424
-------------+------------------------------ Adj R-squared = 0.8238Total | 9133.8 19 480.726316 Root MSE = 9.2029
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
. stepwise, pr(.10) pe(.05) forward: regress sysbp chol age tribegin with empty model
p = 0.0000 < 0.0500 adding cholp = 0.0061 < 0.0500 adding tri
...------------------------------------------------------------------------------
sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]-------------+----------------------------------------------------------------
chol | .1875776 .0513543 3.65 0.002 .0792295 .2959258tri | .238911 .0763522 3.13 0.006 .0778219 .4
_cons | 40.00673 11.42093 3.50 0.003 15.91068 64.10279------------------------------------------------------------------------------
28
. stepwise, forward lockterm1 pr(.10) pe(.05): regress sysbp (age) chol tribegin with term 1 model
p = 0.0000 < 0.0500 adding cholp = 0.0161 < 0.0500 adding tri
Source | SS df MS Number of obs = 20-------------+------------------------------ F( 3, 16) = 35.56
Model | 7942.70165 3 2647.56722 Prob > F = 0.0000Residual | 1191.09835 16 74.4436471 R-squared = 0.8696
-------------+------------------------------ Adj R-squared = 0.8451Total | 9133.8 19 480.726316 Root MSE = 8.6281
------------------------------------------------------------------------------sysbp | Coef. Std. Err. t P>|t| [95% Conf. Interval]
-------------+----------------------------------------------------------------age | .5122311 .2802612 1.83 0.086 -.0818961 1.106358chol | .1654515 .0496455 3.33 0.004 .0602076 .2706953tri | .2006968 .0745745 2.69 0.016 .042606 .3587876
_cons | 27.15522 12.80998 2.12 0.050 -.0007311 54.31117------------------------------------------------------------------------------
lockterm1 = keep the first term
*กรณตวแปรหน (Dummy Variable) ใชพจารณาเปนกลมตวแปร
โดยใช (...)
Report Regression Table (Publication Manual of the American Psychological Association sixth Edition,2010;pp 145.)
29
Stepwise logistic regression พจารณาคา p-value
Hosmer & Lemeshow (2000) ควรกาหนด
p-value for entry (Pe).15-.25 , p-value for remove (Pr) > Pe
การกาหนด p-value for entry สงหรอตาเกนไป
-use more tradition level (.05)fails to identify variables known
to be important ?
-higher level has disadvantage of including variables that are of
questionable importance at the model building stage
(Original: Mickey & Greenland,1977:p125-137;
Cite in : Hosmer & Lemeshow (2000):p95 )
ขอกาหนดในการวเคราะหสมการถดถอยพห (Assumption)
พจารณาจากสวนทเหลอ (Residual: ei หรอ )
คา residual (ei) มการแจกแจงแบบปกต
คา residual (ei) มคา variance คงท (homoscedasticity)
คา residual (ei) ไมมความสมพนธกบคาอนๆ (no auto-correlation)
พจารณา Independent
ไมม Multicollinearity
ii yy ˆ
30
คา residual (ei) มการแจกแจงแบบปกต
Normal probability plot, Box-Whisker plot, Stem & leaf etc.
Shapiro-Wilk Test หรอ Lilifor Test
. quietly regress sysbp chol age tri
. predict e,residual
. swilk eShapiro-Wilk W test for normal data
Variable | Obs W V z Prob>z-------------+-------------------------------------------------
e | 20 0.95467 1.073 0.142 0.44361
. pnorm e
. quietly regress sysbp chol age tri
. predict e,residual
. swilk eShapiro-Wilk W test for normal data
Variable | Obs W V z Prob>z-------------+-------------------------------------------------
e | 20 0.95467 1.073 0.142 0.44361. pnorm e
31
คา residual (ei) มคา variance คงท (homoscedasticity)-การฟลอตกราฟ ระหวางคา residual (ei) กบ
-ทดสอบ Cook-Weisberg test for heteroscedasticity
Stataestat hettest tests for heteroskedasticityestat imtest information matrix testestat ovtest Ramsey regression specification-error
test for omitted variablesestat szroeter Szroeter's rank test for
heteroskedasticity
rvfplot residual-versus-fitted plot
iY
คา residual (ei) มคา variance คงท (homoscedasticity)
การฟลอตกราฟ ระหวางคา residual (ei) กบ
ทดสอบ Cook-Weisberg test for heteroscedasticityiy
. rvfplot, ylin(0)
. estat hettestBreusch-Pagan / Cook-Weisberg test for heteroskedasticity
Ho: Constant varianceVariables: fitted values of sysbpchi2(1) = 1.32Prob > chi2 = 0.2500
32
. estat szroeter , rhs mtest(holm)
Szroeter's test for homoskedasticity
Ho: variance constantHa: variance monotonic in variable
---------------------------------------Variable | chi2 df p
-------------+-------------------------chol | 1.45 1 0.4557 #age | 0.46 1 0.4984 #tri | 1.88 1 0.5107 #
---------------------------------------# Holm adjusted p-values
. hettest , rhs mtest(bonf)
Breusch-Pagan / Cook-Weisberg test for heteroskedasticityHo: Constant variance
---------------------------------------Variable | chi2 df p
-------------+-------------------------chol | 1.23 1 0.7995 #age | 0.37 1 1.0000 #tri | 1.26 1 0.7842 #
-------------+-------------------------simultaneous | 1.45 3 0.6939---------------------------------------
# Bonferroni adjusted p-values
. hettestCook-Weisberg test for heteroskedasticity using fitted values of y
Ho: Constant variancechi2(1) = 7.44Prob > chi2 = 0.0064
. rvfplot, border yline(0)
. hettestCook-Weisberg test for heteroskedasticity using fitted values of y
Ho: Constant variancechi2(1) = 0.00Prob > chi2 = 1.0000
. rvfplot, border yline(0)
33
คา residual (ei) ไมมความสมพนธกบคาอนๆ (no auto-correlation) **ใชเฉพาะขอมลแบบ Time-Series
- ความสมพนธระหวางคาระหวางรายขอมลของตวแปรเดยวกน คา error รายท i จะมความสมพนธกบ error รายท i-1
- การคานวณ สถต Durbin-Watson test (d)- d < 2 พบวาเกด positive autocorrelation- d>2 เกด negative autocorrelation
n
ii
e
n
i)
ie(e
d
1
2
2
21
id age time expose lt1 42 15 1 54 2 46 14 2 7.3 3 43 8 4 3 4 25 3 3 2 5 26 13 4 5.4 6 55 12 4 5 7 23 10 4 3.7 8 24 11 4 5 9 38 7 3 2.8
10 24 4 4 2.2 11 28 6 4 2.5 12 38 9 4 3.1 13 26 5 4 2.5 14 28 1 4 .8 15 26 2 2 1.2
ตวอยาง การศกษาการไดรบสาร Beryllium ในคนงานเหมองถานหนโดยศกษาตวแปร age exposure กบ higher rate of blastogeniclymphocyte transformation (lt ratio)
34
. tsset timetime variable: time, 1 to 15
delta: 1 unit
. qui regress lt age expose
. estat dwatson
Durbin-Watson d-statistic( 3, 15) = 1.98835
. estat durbinaltDurbin's alternative test for autocorrelation--------------------------------------------------------------------
lags(p) | chi2 df Prob > chi2-------------+------------------------------------------------------
1 | 1.843 1 0.1746--------------------------------------------------------------------
H0: no serial correlation
0:;0:0 AHHif D > dU conclude H0If D < dL conclude HAIf dL D dU the test inconclusive
ภาวะรวมเสนตรง* (Collinearity)
ความสมพนธระหวางตวแปรอสระดวยกน มคาสง
(r2 > 0.90; r > 0.95 Kleinbaum, Muller, Nizam; 1998, 241
ชออน “Multicollinearity”
การลดหรอเพมตวแปรในโมเดล ทาใหเปลยนแปลงคาสมประสทธ
ทงขนาดและ/หรอเครองหมาย
คา R2 มคาสงแตการทดสอบทางสถตกบสมประสทธ พบวา
ไมมนยสาคญ
ทาใหคา Standard error สง ซงสงผลใหคาสถตมคาตาเชน t, z
และทาใหคาชวงเชอมนของสมประสทธมคากวาง
*พจนานกรมศพทคณตศาสตร ฉบบราชบณฑตยสถาน, 2552
35
การตรวจสอบ Collinearity หรอ Multicollinearity
Pearson Correlation (informal method)
-ตรวจสอบความสมพนธทกตวแปร โดยใชสถต Pearson correlation
พจารณาตวแปรทมความสมพนธกบตวแปรอนๆ สง
. corr chol age age tri(obs=20)
| chol age age tri-------------+------------------------------------
chol | 1.0000age | 0.5609 1.0000age | 0.5609 1.0000 1.0000tri | 0.7467 0.5732 0.5732 1.0000
Variance Inflation Factors (VIF: formal method)
พจารณาคา VIF > 10 และคาเฉลยของ VIF มากกวา 1 มปญหาการเกด Multicolinearity
. collin age chol triCollinearity Diagnostics
SQRT R-Variable VIF VIF Tolerance Squared
----------------------------------------------------age 1.58 1.26 0.6315 0.3685chol 2.40 1.55 0.4162 0.5838tri 2.45 1.57 0.4077 0.5923
----------------------------------------------------Mean VIF 2.15
CondEigenval Index
---------------------------------1 3.9477 1.00002 0.0303 11.42063 0.0126 17.73024 0.0094 20.4609
---------------------------------Condition Number 20.4609 Eigenvalues & Cond Index computed from scaled raw sscp (w/ intercept)Det(correlation matrix) 0.2794
21
11)21(
iRi
Ri
VIF
1
1
1)(
p-
p-
iK
VIF
VIF
36
r r2 vif.1 0.01 1.01 .2 0.04 1.04 .3 0.09 1.10 .4 0.16 1.19 .5 0.25 1.33 .6 0.36 1.56 .7 0.49 1.96 .8 0.64 2.78 .9 0.81 5.26 .91 0.83 5.82 .92 0.85 6.51 .93 0.86 7.40 .94 0.88 8.59 .95 0.90 10.26.96 0.92 12.76 .97 0.94 16.92 .98 0.96 25.25 .99 0.98 50.25
1 1.00 .
ความสมพนธระหวาง VIF vs คา correlation
.95
Indication of Multicollinearity ดวยวธ Variance inflation factors*- VIF > 10 indication that Multicollinearity- Mean VIF provides information about the severity of the
multicollinearity- if Mean VIF > 1 are indicative of serious multicollinearity
problems*Neter, Wasserman, Kutner (1987; p.392)Marquardt (1970); Belsley, Kuh & Welsch (1980)
- tolerence <0.20 or 0.10 and/or VIF>5 or 10+ (O’Brien, 2007)
Statacollin [varlist…]estat vif variance inflation factors for the
independent variables
)2i
R(1i
tolerance
37
. quietly regress sysbp chol age tri
. vifVariable | VIF 1/VIF -------------+----------------------
tri | 2.45 0.407722chol | 2.40 0.416193age | 1.58 0.631508
-------------+----------------------Mean VIF | 2.15
หรอ. estat vif
Variable | VIF 1/VIF -------------+----------------------
tri | 2.45 0.407722chol | 2.40 0.416193age | 1.58 0.631508
-------------+----------------------Mean VIF | 2.15
. di (2.45+2.40+1.58)/32.1433333
Conditional Index & Variance Decomposition Proportionคา Conditional Index (CI) และคา Variance Decomposition Proportion (VDP) เปนคาทคานวณจาก eigenvalue จากการวเคราะหเมตรกซสหสมพนธ ของตวแปรอสระ โดย Conditional Index คานวณจาก
คา Conditional Index มคา 10-30 แสดงวามภาวะรวมเสนตรง คา conditional index > 30 แสดงวามปญหาภาวะรวมเสนตรง Conditional Index > 100 แสดงวามภาวะรวมเสนตรงสงมากๆ (Belsley, 1991a)
between 10 and 30, there is moderate to strong multicollinearity and if it exceeds 30 there is severe multicollinearity. (Gujarati, 2002)
Eigenvaluek MinMax ;/
38
Conditional Index & Variance Decomposition Proportion
คา Variance Decomposition Proportion แนะนาโดย
Belsley et al. (1980) และ Belsley (1991a)
พจารณา VDP มากกวา 0.5
คานวณคาสดสวนของความแปรปรวน (proposed calculation of
the proportions of variance) ของแตละตวแปรสมพนธกบ
คาองคประกอบ (principal component) เปรยบเสมอน
องคประกอบของคาสมประสทธความแปรปรวนในแตละมต
(decomposition of the coefficient variance for each dimension)
kj
jkjk VIF
Vp
2
(Fox,1984)
. coldiag2 tri chol age, force w(5)
Condition number using scaled variables = 20.46
Condition Indexes and Variance-Decomposition Proportions
conditionindex _cons tri chol age
1 1.00 0.00 0.00 0.00 0.002 11.42 0.32 0.38 0.01 0.03 3 17.73 0.32 0.00 0.14 0.95 4 20.46 0.36 0.61 0.85 0.02
. prnt_cx, force w(5)
Condition Indexes and Variance-Decomposition Proportionscondition
index _cons tri chol age 1 1.00 . . . . 2 11.42 0.32 0.38 . . 3 17.73 0.32 . . 0.95 4 20.46 0.36 0.61 0.85 .
Variance-Decomposition Proportions less than .3 have been printed as "."