ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน

Clinical Epidemiology ResearchMethodology and Research Design THUniqcret doctor knowledges TH
ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน
On this page

อ่านฉบับภาษาอังกฤษ (English version)

บทคัดย่อ

regression model เชื่อได้เพียงใดขึ้นกับว่า assumption ของมันเป็นจริงหรือไม่ บทความนี้ใช้ cohort สังเคราะห์ของผู้ใหญ่ 1,200 คนที่นอนโรงพยาบาลด้วยปอดอักเสบ 327 คนเป็นเบาหวาน แล้วตรวจทุก model ว่าสมมติอะไร ใช้คำสั่ง Stata ใดตรวจ ไม่ผ่านแล้วเป็นอย่างไร และควรไปต่อที่ model ใด residual รูประฆังและความแปรปรวนคงที่เป็นเรื่องของ linear regression เท่านั้น logistic regression ต้องการความเสี่ยงที่ทำนายตรงกับจริง link ที่ถูก และอายุที่เป็นเส้นตรง และพังเมื่อเกิด separation ซึ่ง Firth และ exact logistic regression แก้ได้ ordinal regression ต้องการ proportional odds ซึ่ง oparallel ตรวจได้ แล้วมีบันไดไปต่อจน mlogit model จำนวนนับต้องการความแปรปรวนใกล้ค่าเฉลี่ย และ Cox ต้องการ hazard ที่เป็นสัดส่วนคงที่


ภาพสรุป: อ่านแต่ละแถวจากซ้ายไปขวา คือ model, assumption, คำสั่งตรวจ และทางไปต่อ แถวตรงกับตารางท้ายบทความ

cohort เดียว เจ็ด outcome และคำถามก่อนรายงานผล

กรณีที่เราติดตามตลอดบทความคือ cohort สังเคราะห์ของผู้ใหญ่ 1,200 คนที่นอนโรงพยาบาลด้วยปอดอักเสบ ในจำนวนนี้ 327 คนเป็นเบาหวาน ซึ่งเป็น exposure ที่เราศึกษา ผู้ป่วยกลุ่มเดียวกันนี้มี outcome ถึงเจ็ดแบบ ตั้งแต่จำนวนวันนอนไปจนถึงการเสียชีวิตภายในหนึ่งปี ในตอนที่ 2 ของชุดนี้ (เขียนคำสั่งและอ่านผล) logistic regression ให้ odds ratio ของการเข้า ICU ในผู้ป่วยเบาหวานเท่ากับ 1.65 หลังปรับอายุและเพศแล้ว

ก่อนจะเอาตัวเลข 1.65 ไปใส่ในรายงาน ยังเหลือคำถามอีกข้อหนึ่ง ภาพของข้อมูลที่ model วาดไว้ตรงกับข้อมูลจริงหรือไม่ ทุก model มี assumption (ในบทความนี้เรียกว่า "คำสัญญา" ของ model) อยู่ไม่กี่ข้อ ทั้งเรื่องรูปร่างของ outcome เรื่องวิธีที่อายุเข้ามาใน model และเรื่องที่ผู้ป่วยแต่ละคนเป็นอิสระต่อกัน ถ้าคำสัญญาข้อใดไม่เป็นจริง ตัวเลขก็อาจผิดได้ และ Stata ก็มักจะพิมพ์ตัวเลขนั้นออกมาให้อยู่ดี

บทความนี้ตรวจคำสัญญาเหล่านั้นทีละ model ข้อมูลทั้งหมดสร้างขึ้นด้วยโค้ด จึงไม่มีผู้ป่วยจริงอยู่ในนั้น และตัวเลขในเนื้อความปัดมาจาก output ของ Stata ในกล่องโค้ด

มีงานสองอย่างที่เป็นหน้าที่ของตอนอื่นในชุดนี้ และแต่ละเรื่องมีบทความของตัวเอง

ชุดตรวจ residual ชุดเดียวใช้กับทุก model ไม่ได้

นิสัยที่พบบ่อยคือการแปะ "ชุดตรวจ assumption" ชุดเดียวไว้ท้ายทุก model ทั้ง histogram ของ residual กราฟ normal quantile (qnorm) และกราฟ residual เทียบกับค่าที่ทำนาย (rvfplot) ภาพเหล่านี้ตรวจคำสัญญาสองข้อของ linear regression เท่านั้น คือความกระจายเท่ากันทุกระดับของค่าที่ทำนาย และรูปทรงระฆัง

outcome ของ logistic model มีแค่ 0 หรือ 1 residual จึงไม่มีทางเป็นรูประฆัง และกราฟของ residual ก็ไม่ได้บอกอะไรเกี่ยวกับ odds ratio 1.65 เรื่องเดียวกันนี้ใช้กับ model แบบ ordinal, multinomial, จำนวนนับ และ Cox ด้วย แต่ละ model ในหัวข้อถัดไปจึงถูกตรวจด้วยคำสัญญาของตัวมันเอง

ทุก model: ผู้ป่วยเป็นอิสระต่อกันหรือไม่

มีคำสัญญาข้อหนึ่งที่ทุก model ในบทความนี้มีร่วมกัน คือแต่ละแถวเป็นผู้ป่วยคนละคน และ outcome ของคนหนึ่งไม่ขึ้นกับแถวอื่น ใน cohort ของเราข้อนี้เป็นจริงตั้งแต่การสร้างข้อมูล เพราะผู้ป่วยทั้ง 1,200 คนปรากฏเพียงคนละครั้งและไม่มี cluster ใดเลย ไม่มีบรรทัดไหนใน output ที่ทดสอบข้อนี้ได้ เราต้องรู้เองจากวิธีเก็บข้อมูล

รูปแบบการศึกษาสามแบบทำให้ข้อนี้ไม่เป็นจริง คือ ชุด case-control ที่จับคู่ ซึ่ง case แต่ละคนมาพร้อม control ของตัวเอง ผู้ป่วยที่รวมกลุ่มอยู่ในโรงพยาบาล และการวัดซ้ำที่ผู้ป่วยหนึ่งคนให้ข้อมูลหลายแถว ชุดที่จับคู่ต้องใช้ model ที่เทียบ case กับ control ของตัวเองเท่านั้น เรียกว่า conditional logistic regression (clogit) ข้อมูลที่เป็น cluster ต้องใช้ standard error ที่คำนึงถึง cluster ส่วนการวัดซ้ำต้องใช้ mixed model หรือ GEE (generalized estimating equations) ซึ่งเฉลี่ยผลไปทั่วผู้ป่วย โดยยอมให้แถวของผู้ป่วยคนเดียวกันคล้ายกันได้

บทเรียนเต็มอยู่ที่ ทำไม Logistic และ Conditional Logistic Regression จึงให้ Odds Ratio ต่างกัน? สำหรับชุดที่จับคู่ ทำความเข้าใจ VCE: Robust Standard Error, Sandwich Estimator และ vce(cluster id) สำหรับ cluster standard error และ ทางเลือกแบบ Population-Averaged: GLS, GEE และจุดที่โชคของ linear model หมดลง สำหรับ mixed model เทียบกับ GEE

Linear regression: ความกระจายเท่ากันและรูปทรงระฆัง

จำนวนวันนอนเป็น outcome แบบต่อเนื่อง model คือ regress los i.diabetes c.age i.female และการตรวจทั้งหมดด้านล่างรันต่อจากคำสั่งนี้ทันที linear regression จำลองค่าเฉลี่ยของวันนอนบวกความกระจายแบบสุ่มรอบค่าเฉลี่ยนั้น และสัญญาว่าความกระจายจะกว้างเท่ากันทั้งในคนที่ทำนายว่านอนสั้นและนอนยาว และมีรูปทรงเป็นระฆัง

ความกว้างที่เท่ากันเรียกว่า constant variance (ความแปรปรวนคงที่) เมื่อไม่เป็นจริง residual จะบานออกเป็นรูปพัดเมื่อค่าที่ทำนายสูงขึ้น ซึ่งเรียกว่า heteroskedasticity การทดสอบหนึ่งถามว่าความกระจายของ residual กว้างขึ้นตามค่าที่ทำนายหรือไม่ การทดสอบนี้ชื่อ Breusch-Pagan (estat hettest) ได้ chi2 = 0.02 และ p = 0.8918 จึงไม่มีรูปพัด

สำหรับรูปทรง ให้เก็บ residual ด้วย predict skewness วัดความเบ้ ระฆังที่สมบูรณ์มีค่าเป็น 0 ในที่นี้ได้ 0.0012 ส่วน kurtosis วัดความหนาของหาง ระฆังที่สมบูรณ์มีค่าเป็น 3 ในที่นี้ได้ 2.95

การทดสอบแบบเป็นทางการถามว่า residual น่าจะมาจากรูปทรงระฆังได้หรือไม่ การทดสอบนี้ชื่อ Shapiro-Wilk และให้ผลสอดคล้องกัน (W = 0.99869, p = 0.52666) แต่เมื่อมีผู้ป่วย 1,200 คน การทดสอบนี้จะจับได้แม้ความเบี่ยงเบนเล็กน้อยที่ไม่มีผลอะไร จึงควรอ่านคู่กับ skewness และ kurtosis

ในงานของคุณเองให้วาด rvfplot และ qnorm ด้วย รูปพัดทำให้ standard error ผิด แต่ผลต่างของค่าเฉลี่ยไม่ผิด จึงให้ fit ใหม่ด้วย vce(robust) ส่วน outcome ที่เบ้มาก เช่น ค่าใช้จ่าย อาจเหมาะกับ generalized linear model ที่มี gamma family และ log link ซึ่งจำลองอัตราส่วนของค่าเฉลี่ย ดู Link และ Family: ตัวหนึ่งกำหนดมาตรวัดผล อีกตัวกำหนดค่าคลาดเคลื่อนมาตรฐาน

โค้ด Stata 03_check_models.do (บรรทัด 56-61 จาก 240)
estat hettest
* read: Prob > chi2 (Breusch-Pagan; small p = a fan, unequal spread)
predict los_residual, residuals
label variable los_residual "Residual of regress los (days)"
summarize los_residual, detail
* read: Skewness (near 0) and Kurtosis (near 3) of the residuals
ผลลัพธ์จากการรัน 03_check_models.log
Assumption: Normal error terms
Variable: Fitted values of los

H0: Constant variance

    chi2(1) =   0.02
Prob > chi2 = 0.8918

. * read: Prob > chi2 (Breusch-Pagan; small p = a fan, unequal spread)
. predict los_residual, residuals

. label variable los_residual "Residual of regress los (days)"

. summarize los_residual, detail

               Residual of regress los (days)
-------------------------------------------------------------
      Percentiles      Smallest
 1%    -5.124617      -6.218624
 5%    -3.586443      -6.022003
10%    -2.762799      -5.899545       Obs               1,200
25%    -1.444301      -5.818961       Sum of wgt.       1,200

50%    -.0090843                      Mean          -2.08e-09
                        Largest       Std. dev.       2.14977
75%     1.481376       6.301649
90%     2.860263       6.341672       Variance       4.621512
95%     3.517357       6.558582       Skewness       .0012484
99%     4.749958        7.27951       Kurtosis       2.951542
อ่าน Prob > chi2 ของ estat hettest (0.8918) แล้วดู Skewness กับ Kurtosis ของ residual ไม่มีรูปพัดและ residual เกือบเป็นระฆัง
โค้ด Stata 03_check_models.do (บรรทัด 62-63 จาก 240)
swilk los_residual
* read: W and Prob>z (with n = 1,200 even tiny departures give small p)
ผลลัพธ์จากการรัน 03_check_models.log
    Variable |        Obs       W           V         z       Prob>z
-------------+------------------------------------------------------
los_residual |      1,200    0.99869      0.974    -0.067    0.52666
อ่านแถว los_residual ได้ W = 0.99869 และ Prob>z = 0.52666 residual จึงผ่านการทดสอบ Shapiro-Wilk ด้วย

Logistic regression: ความตรงของความเสี่ยงที่ทำนายและ link

การเข้า ICU มีแค่ใช่หรือไม่ใช่ model คือ logit icu i.diabetes c.age i.female, or ซึ่งให้ odds ratio ของเบาหวานเท่ากับ 1.65 และการตรวจทั้งหมดด้านล่างรันต่อจากคำสั่งนี้ทันที residual ของ model นี้ไม่มีระฆังให้ตรวจ แต่ model สัญญาไว้สามข้อแทน คือความเสี่ยงที่ทำนายตรงกับสิ่งที่เกิดขึ้นจริง (calibration) logit link เป็นมาตราส่วนที่ถูกต้อง และอายุเข้ามาใน model เป็นเส้นตรงบนมาตราส่วน log-odds

วิธีตรวจคำสัญญาข้อแรกคือเรียงผู้ป่วยทั้ง 1,200 คนเป็น 10 กลุ่มตามความเสี่ยงที่ทำนาย แล้วเทียบจำนวนการเข้า ICU ที่ทำนายกับที่เกิดขึ้นจริงในแต่ละกลุ่ม การทดสอบนี้ชื่อ Hosmer-Lemeshow ค่า p ที่สูงแปลว่าไม่มีหลักฐานว่า model ไม่เข้ากับข้อมูล ในที่นี้ได้ chi2(8) = 3.05 และ p = 0.9310

พื้นที่ใต้ ROC curve เท่ากับ 0.6413 ตัวเลขนี้ไม่ใช่การตรวจ assumption แต่บอกว่า model เรียงลำดับผู้ป่วยได้ดีเพียงใด model ที่ถูกต้องก็ยังอาจเรียงได้แค่ปานกลาง

linktest ตรวจคำสัญญาข้อที่สอง โดย fit การเข้า ICU ใหม่บนค่า log-odds ที่ทำนายและค่ายกกำลังสองของมัน ถ้า model ถูกต้อง ค่ายกกำลังสองจะไม่ช่วยอะไรเพิ่ม แถว _hatsq ให้ p = 0.902 ในที่นี้ ถ้า p ต่ำจะชี้ว่า link ผิดหรือขาดส่วนโค้งไป

risk ratio ที่ได้จาก glm y x, family(binomial) link(log) eform ต้องตรวจเพิ่มอีกหนึ่งข้อ เพราะ log-binomial model นี้มักล้มเหลวโดยไม่ขึ้น error กล่องโค้ดที่สองด้านล่างแสดงการ fit ของ ICU risk ratio ของเบาหวานพิมพ์ออกมาโดยมีจุดแทน standard error ท้ายตารางเขียนว่า "Warning: Convergence not achieved" และ display e(converged) แสดงค่า 0 เมื่อเป็นแบบนี้ให้ถอยลงไปใช้ glm y x, family(poisson) link(log) vce(robust) eform คือ modified Poisson model ตามที่ หา Risk Ratio เมื่อผลลัพธ์พบบ่อย: ลำดับขั้นถอยลงเมื่อ Log-Binomial ชนกำแพง อธิบายไว้

โค้ด Stata 03_check_models.do (บรรทัด 67-77 จาก 240)
logit icu i.diabetes c.age i.female, or
estimates store model_icu_logit
* quietly hides the long table; the two display lines print the test.
quietly estat gof, group(10)
display as text "Hosmer-Lemeshow chi2(" r(df) ") = " %4.2f r(chi2)
display as text "Prob > chi2 = " %6.4f r(p)
* read: Prob > chi2 (large p = no misfit seen)
lroc, nograph
* read: Area under ROC curve (ranking, not an assumption check)
linktest
* read: _hatsq row, P>|z| (small p = wrong link or a missing curve)
ผลลัพธ์จากการรัน 03_check_models.log
. logit icu i.diabetes c.age i.female, or

Iteration 0:  Log likelihood = -684.51086
Iteration 1:  Log likelihood = -655.55088
Iteration 2:  Log likelihood = -655.09143
Iteration 3:  Log likelihood = -655.09116
Iteration 4:  Log likelihood = -655.09116

Logistic regression                                     Number of obs =  1,200
                                                        LR chi2(3)    =  58.84
                                                        Prob > chi2   = 0.0000
Log likelihood = -655.09116                             Pseudo R2     = 0.0430

------------------------------------------------------------------------------
         icu | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.646897   .2387784     3.44   0.001     1.239519    2.188162
         age |    1.03403   .0061759     5.60   0.000     1.021996    1.046206
             |
      female |
     Female  |    .636516   .0885237    -3.25   0.001     .4846499    .8359696
       _cons |   .0356252   .0151098    -7.86   0.000     .0155144    .0818048
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. estimates store model_icu_logit

. * quietly hides the long table; the two display lines print the test.
. quietly estat gof, group(10)

. display as text "Hosmer-Lemeshow chi2(" r(df) ") = " %4.2f r(chi2)
Hosmer-Lemeshow chi2(8) = 3.05

. display as text "Prob > chi2 = " %6.4f r(p)
Prob > chi2 = 0.9310

. * read: Prob > chi2 (large p = no misfit seen)
. lroc, nograph

Logistic model for icu

Number of observations =     1200
Area under ROC curve   =   0.6413

. * read: Area under ROC curve (ranking, not an assumption check)
. linktest

Iteration 0:  Log likelihood = -684.51086
Iteration 1:  Log likelihood = -656.06145
Iteration 2:  Log likelihood = -655.08728
Iteration 3:  Log likelihood =  -655.0835
Iteration 4:  Log likelihood =  -655.0835

Logistic regression                                     Number of obs =  1,200
                                                        LR chi2(2)    =  58.85
                                                        Prob > chi2   = 0.0000
Log likelihood = -655.0835                              Pseudo R2     = 0.0430

------------------------------------------------------------------------------
         icu | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        _hat |   .9501319    .425214     2.23   0.025     .1167278    1.783536
      _hatsq |  -.0247296   .2001229    -0.12   0.902    -.4169633     .367504
       _cons |  -.0189437   .2151431    -0.09   0.930    -.4406163     .402729
------------------------------------------------------------------------------
หา odds ratio ของเบาหวาน (1.646897) บรรทัด Hosmer-Lemeshow คือ chi2(8) = 3.05 และ Prob > chi2 = 0.9310 กับแถว _hatsq ของ linktest (0.902) ค่า p ทั้งสองสูง calibration และ link จึงผ่าน
โค้ด Stata 03_check_models.do (บรรทัด 221-224 จาก 240)
* Stata does not stop here. Read the footer and e(converged).
glm icu i.diabetes c.age i.female, family(binomial) link(log) eform nolog
display as text "log-binomial fit: e(converged) = " e(converged)
* read: Warning: Convergence not achieved; e(converged) = 0 (1 = yes)
ผลลัพธ์จากการรัน 03_check_models.log
. glm icu i.diabetes c.age i.female, family(binomial) link(log) eform nolog
convergence not achieved

Generalized linear models                         Number of obs   =      1,200
Optimization     : ML                             Residual df     =      1,199
                                                  Scale parameter =          1
Deviance         =  1652.086292                   (1/df) Deviance =   1.377887
Pearson          =  100001576.4                   (1/df) Pearson  =   83404.15

Variance function: V(u) = u*(1-u)                 [Bernoulli]
Link function    : g(u) = ln(u)                   [Log]

                                                  AIC             =   1.378405
Log likelihood   = -826.0431461                   BIC             =  -6848.916

------------------------------------------------------------------------------
             |                 OIM
         icu | Risk ratio   std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.224657          .        .       .            .           .
         age |   1.014894   1.03e-10  1.5e+08   0.000     1.014894    1.014894
             |
      female |
     Female  |   .3517312    .029269   -12.56   0.000     .2987988    .4140406
       _cons |   .2067673          .        .       .            .           .
------------------------------------------------------------------------------
Note: _cons estimates baseline risk.
Warning: Parameter estimates produce inadmissible mean estimates in one or
         more observations.
Warning: Convergence not achieved.

. display as text "log-binomial fit: e(converged) = " e(converged)
log-binomial fit: e(converged) = 0
ดูจุดที่อยู่แทน standard error ของเบาหวาน บรรทัด Warning ใต้ตาราง และ e(converged) = 0 การ fit ไม่ converge จึงรายงาน risk ratio นี้ไม่ได้

อายุเป็นเส้นตรงบนมาตราส่วน log-odds หรือไม่

อายุเป็นตัวแปรต่อเนื่อง และ model สมมติว่าอายุที่เพิ่มขึ้นทุกหนึ่งปีคูณ odds ของการเข้า ICU ด้วยตัวคูณเดิมเสมอ นั่นคือเส้นตรงบนมาตราส่วน log-odds วิธีทดสอบคือปล่อยให้เส้นโค้งได้ แล้วดูว่าการโค้งช่วยอธิบายข้อมูลหรือไม่

restricted cubic spline ทำสิ่งนี้ได้ mkspline ตัดอายุที่สี่จุด (knot) ในที่นี้คือ 48, 63, 73 และ 87 ปี แล้วสร้างตัวแปรสามชิ้น ชิ้นแรกคือเส้นตรง อีกสองชิ้นทำได้แค่ดัดเส้นให้โค้ง ถ้าสองชิ้นที่ดัดเส้นไม่ช่วยอะไรเลย เส้นตรงก็เพียงพอ

การทดสอบร่วมของสองชิ้นที่ดัดเส้นให้ chi2(2) = 2.69 และ p = 0.2604 อายุจึงยังเป็นเส้นตรงได้ ถ้าการทดสอบไม่ผ่าน ให้เก็บชิ้น spline ไว้ แล้วรายงานความเสี่ยงที่ทำนายในอายุที่เลือกด้วย margins เพราะ odds ratio ต่อปีเพียงค่าเดียวอธิบายเส้นที่โค้งไม่ได้

โค้ด Stata 03_check_models.do (บรรทัด 83-86 จาก 240)
mkspline age_spline = age, cubic nknots(4) displayknots
logit icu i.diabetes age_spline1 age_spline2 age_spline3 i.female, or
estimates store model_icu_logit_age_spline
test age_spline2 age_spline3
ผลลัพธ์จากการรัน 03_check_models.log
. mkspline age_spline = age, cubic nknots(4) displayknots

             |     knot1      knot2      knot3      knot4
-------------+--------------------------------------------
         age |        48         63         73         87

. logit icu i.diabetes age_spline1 age_spline2 age_spline3 i.female, or

Iteration 0:  Log likelihood = -684.51086
Iteration 1:  Log likelihood = -654.90475
Iteration 2:  Log likelihood = -653.65701
Iteration 3:  Log likelihood = -653.65185
Iteration 4:  Log likelihood = -653.65185

Logistic regression                                     Number of obs =  1,200
                                                        LR chi2(5)    =  61.72
                                                        Prob > chi2   = 0.0000
Log likelihood = -653.65185                             Pseudo R2     = 0.0451

------------------------------------------------------------------------------
         icu | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.640798     .23825     3.41   0.001     1.234404    2.180985
 age_spline1 |   1.079703   .0299725     2.76   0.006     1.022528    1.140076
 age_spline2 |   .8982303   .0598333    -1.61   0.107      .788292    1.023501
 age_spline3 |   1.443484    .350857     1.51   0.131     .8964309    2.324381
             |
      female |
     Female  |   .6380295   .0887579    -3.23   0.001      .485767    .8380183
       _cons |   .0034373   .0053226    -3.66   0.000     .0001653    .0714943
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. estimates store model_icu_logit_age_spline

. test age_spline2 age_spline3

 ( 1)  [icu]age_spline2 = 0
 ( 2)  [icu]age_spline3 = 0

           chi2(  2) =    2.69
         Prob > chi2 =    0.2604
หาแถว knot แล้วดูการทดสอบร่วมของ age_spline2 กับ age_spline3 ได้ p = 0.2604 ชิ้นที่ดัดเส้นไม่ช่วยอะไร อายุจึงยังเป็นเส้นตรง

Separation: เมื่อตัวแปรหนึ่งทำนาย outcome ได้สมบูรณ์

cohort ของเราเรียบร้อยเกินกว่าจะแสดงปัญหาถัดไปได้ do-file จึงสร้างข้อมูลตัวอย่างเล็ก ๆ ขึ้นภายในตัวเอง มีผู้ป่วย 30 คน ในจำนวนนี้ 10 คนได้ยา X ทั้ง 10 คนที่ได้ยามี outcome ทุกคน ส่วน 20 คนที่ไม่ได้ยา มี outcome 8 คน และไม่มี 12 คน

ลองคิด odds ratio ด้วยมือดู ในกลุ่มที่ได้ยา odds ของ outcome คือ 10 ต่อ 0 ซึ่งเป็นอนันต์ ดังนั้นจึงไม่มี odds ratio ค่าจำกัดค่าใดที่เข้ากับข้อมูลนี้ได้ดีที่สุด ยิ่งตัวเลขใหญ่ยิ่ง fit ดีขึ้นไปเรื่อย ๆ ไม่มีที่สิ้นสุด สภาพนี้เรียกว่า separation คือตัวแปรหนึ่งตัวหรือหลายตัวรวมกันแบ่ง outcome ออกจากกันได้ขาดโดยไม่มีส่วนทับซ้อน

ยา X เป็น quasi-complete separation เพราะผู้ป่วยที่ไม่ได้ยายังมี outcome ทั้งสองแบบ Stata ไม่หยุด แต่พิมพ์ note ตัดยาและผู้ป่วย 10 คนนั้นออก แล้ว fit ส่วนที่เหลือต่อ: note: drug != 0 predicts success perfectly; drug omitted and 10 obs not used. หัวตารางถัดมาบอกว่า Number of obs = 20 ไม่ใช่ 30 และ exposure ก็หายออกจาก model ไปเงียบ ๆ

complete separation เป็นแบบที่รุนแรงกว่า biomarker ในข้อมูลตัวอย่างมีค่าสูงกว่า 2.2 ในผู้ป่วยทุกคนที่มี outcome และไม่เกิน 2.2 ในผู้ป่วยทุกคนที่ไม่มี ในกรณีนี้ Stata หยุดด้วย r(2000) พร้อมข้อความ outcome = biomarker > 2.2 predicts data perfectly กล่องโค้ดด้านล่างรันคำสั่งนี้ภายใต้ capture noisily do-file จึงพิมพ์ข้อความแล้วทำงานต่อได้

โค้ด Stata 03_check_models.do (บรรทัด 103-111 จาก 240)
tabulate outcome drug

* (a) Quasi-complete: Stata prints a note, drops drug and 10 patients
logit outcome drug
* read: note: drug != 0 predicts success perfectly

* (b) Complete: Stata stops with r(2000); capture noisily goes on
capture noisily logit outcome biomarker
display as text "return code: r(" _rc ")"
ผลลัพธ์จากการรัน 03_check_models.log
. tabulate outcome drug

     DEMO: |   DEMO: took drug X
   outcome |         0          1 |     Total
-----------+----------------------+----------
         0 |        12          0 |        12
         1 |         8         10 |        18
-----------+----------------------+----------
     Total |        20         10 |        30

.
. * (a) Quasi-complete: Stata prints a note, drops drug and 10 patients
. logit outcome drug

note: drug != 0 predicts success perfectly;
      drug omitted and 10 obs not used.

Iteration 0:  Log likelihood = -13.460233
Iteration 1:  Log likelihood = -13.460233

Logistic regression                                     Number of obs =     20
                                                        LR chi2(0)    =   0.00
                                                        Prob > chi2   =      .
Log likelihood = -13.460233                             Pseudo R2     = 0.0000

------------------------------------------------------------------------------
     outcome | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        drug |          0  (omitted)
       _cons |  -.4054651   .4564355    -0.89   0.374    -1.300062     .489132
------------------------------------------------------------------------------

. * read: note: drug != 0 predicts success perfectly
.
. * (b) Complete: Stata stops with r(2000); capture noisily goes on
. capture noisily logit outcome biomarker

outcome = biomarker > 2.2 predicts data perfectly

. display as text "return code: r(" _rc ")"
return code: r(2000)
ดู note ใต้ logit outcome drug และ Number of obs = 20 ยาและผู้ป่วย 10 คนหายไปแล้ว คำสั่งที่สองหยุดพร้อมข้อความ predicts data perfectly จึงไม่มีค่าประมาณเลย

ทางแก้สองทาง: Firth และ exact logistic regression

มีทางแก้สองทางที่เก็บผู้ป่วยไว้ครบทุกคนและให้คำตอบที่เป็นค่าจำกัด ทางแรกคือ penalised likelihood ของ Firth ซึ่งเติมค่าปรับเล็ก ๆ เข้าไปในการ fit ปกติ ค่าปรับนี้ดึงค่าประมาณที่กำลังวิ่งไปสู่อนันต์ให้กลับมาเป็นค่าจำกัด คำสั่งนี้เป็นแบบ user-written ติดตั้งครั้งเดียวด้วย ssc install firthlogit

สำหรับยา X คำสั่ง firthlogit outcome drug, or ให้ odds ratio 30.9 และ 95% CI ตั้งแต่ 1.59 ถึง 600.7 ช่วงนี้กว้างมาก ข้อมูลบอกว่ายาเพิ่ม odds มาก แต่บอกไม่ได้ว่ามากเท่าใด สำหรับ biomarker ได้ 34.1 ต่อหนึ่งหน่วย (95% CI 2.33 ถึง 499.0)

ช่วงทั้งสองเป็น Wald interval คือค่าประมาณบวกลบประมาณสองเท่าของ standard error บนมาตราส่วน log-odds ส่วน Heinze และ Schemper แนะนำ profile penalised-likelihood interval แทน ซึ่งอาจให้ผลต่างออกไป

ทางที่สองคือ exact logistic regression ซึ่ง Stata มีให้ในตัวเป็นคำสั่ง exlogistic วิธีนี้ไล่ดูทุกแบบที่ข้อมูลจะออกมาได้ภายใต้ผลรวมเดิม แล้วนับว่าตารางที่เห็นสุดโต่งเพียงใด ค่าประมาณแบบปกติเป็น +inf Stata จึงรายงานค่ากลางของ odds ratio ที่การคำนวณแบบ exact ยังตัดทิ้งไม่ได้ เรียกว่า median unbiased estimate ได้ odds ratio 17.6 กับ 95% CI ตั้งแต่ 2.36 ถึงอนันต์ และ p = 0.0029

วิธี exact เหมาะกับข้อมูลเล็กแบบตัวอย่างนี้ และจะช้าลงอย่างรวดเร็วเมื่อเพิ่ม covariate มีสองทางที่ไม่ช่วย คือการตัดตัวแปรทิ้ง ซึ่ง note ทำไปแล้ว และการเปลี่ยนไปใช้ clogit ซึ่งตอบโจทย์ของการจับคู่ ไม่ใช่ separation

โค้ด Stata 03_check_models.do (บรรทัด 114-122 จาก 240)
* Remedy 1: Firth penalised likelihood (ssc install firthlogit)
firthlogit outcome drug, or
* read: drug, odds ratio and 95% CI (finite, unlike plain logit)
firthlogit outcome biomarker, or
* read: biomarker, odds ratio and 95% CI

* Remedy 2: exact logistic regression (official Stata)
exlogistic outcome drug
* read: drug, odds ratio marked * = median unbiased estimate
ผลลัพธ์จากการรัน 03_check_models.log
. firthlogit outcome drug, or

Initial:      Penalized log likelihood = -18.968308
Rescale:      Penalized log likelihood = -18.968308
Iteration 0:  Penalized log likelihood = -18.968308
Iteration 1:  Penalized log likelihood = -13.906352
Iteration 2:  Penalized log likelihood = -13.564489
Iteration 3:  Penalized log likelihood = -13.557624
Iteration 4:  Penalized log likelihood = -13.557623

                                                        Number of obs =     30
                                                        Wald chi2(1)  =   5.13
Penalized log likelihood = -13.557623                   Prob > chi2   = 0.0235

------------------------------------------------------------------------------
     outcome | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
        drug |   30.88233   46.76286     2.27   0.023     1.587807    600.6515
       _cons |        .68   .3023111    -0.87   0.386     .2845023    1.625294
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. * read: drug, odds ratio and 95% CI (finite, unlike plain logit)
. firthlogit outcome biomarker, or

Initial:      Penalized log likelihood =  -17.98391
Rescale:      Penalized log likelihood =  -17.98391
Iteration 0:  Penalized log likelihood =  -17.98391
Iteration 1:  Penalized log likelihood = -1.9472574
Iteration 2:  Penalized log likelihood = -1.5886269  (not concave)
Iteration 3:  Penalized log likelihood = -1.4682851
Iteration 4:  Penalized log likelihood = -1.4002217
Iteration 5:  Penalized log likelihood = -1.3739669
Iteration 6:  Penalized log likelihood = -1.3685597
Iteration 7:  Penalized log likelihood = -1.3685335
Iteration 8:  Penalized log likelihood = -1.3685335

                                                        Number of obs =     30
                                                        Wald chi2(1)  =   6.65
Penalized log likelihood = -1.3685335                   Prob > chi2   = 0.0099

------------------------------------------------------------------------------
     outcome | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
   biomarker |   34.09847   46.68389     2.58   0.010     2.330037    499.0074
       _cons |   .0000725   .0002783    -2.48   0.013     3.91e-08    .1343629
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. * read: biomarker, odds ratio and 95% CI
.
. * Remedy 2: exact logistic regression (official Stata)
. exlogistic outcome drug

Enumerating sample-space combinations:
Observation 1:  Enumerations =          2
Observation 2:  Enumerations =          3
Observation 3:  Enumerations =          4
Observation 4:  Enumerations =          5
Observation 5:  Enumerations =          6
Observation 6:  Enumerations =          7
Observation 7:  Enumerations =          8
Observation 8:  Enumerations =          9
Observation 9:  Enumerations =         10
Observation 10: Enumerations =         11
Observation 11: Enumerations =         22
Observation 12: Enumerations =         33
Observation 13: Enumerations =         43
Observation 14: Enumerations =         52
Observation 15: Enumerations =         60
Observation 16: Enumerations =         67
Observation 17: Enumerations =         73
Observation 18: Enumerations =         78
Observation 19: Enumerations =         81
Observation 20: Enumerations =         82
Observation 21: Enumerations =         81
Observation 22: Enumerations =         78
Observation 23: Enumerations =         73
Observation 24: Enumerations =         67
Observation 25: Enumerations =         60
Observation 26: Enumerations =         52
Observation 27: Enumerations =         43
Observation 28: Enumerations =         33
Observation 29: Enumerations =         22
Observation 30: Enumerations =         11
note: CMLE estimate for drug is +inf; computing MUE.

Exact logistic regression                          Number of obs =       30
                                                   Model score   = 9.666667
                                                   Pr >= score   =   0.0041
---------------------------------------------------------------------------
     outcome | Odds ratio       Suff.  2*Pr(Suff.)     [95% conf. interval]
-------------+-------------------------------------------------------------
        drug |   17.63132*        10        0.0029     2.359387       +inf
---------------------------------------------------------------------------
(*) median unbiased estimates (MUE)
เทียบแถว drug ของ firthlogit คือ 30.88233 พร้อมช่วงที่กว้างมาก กับของ exlogistic คือ 17.63132 ที่มีดาวและขอบบน +inf ทั้งสองให้ odds ratio ที่เป็นค่าจำกัด ในขณะที่ logit ธรรมดาให้ไม่ได้

Ordinal logistic regression: odds ratio เดียวสำหรับทุกจุดตัดหรือไม่

ความรุนแรงมีสามระดับเรียงกัน คือ เล็กน้อย ปานกลาง และรุนแรง แบ่งเป็นสองฝั่งได้สองแบบ จุดตัดที่ 1 คือ ปานกลางหรือรุนแรง เทียบกับ เล็กน้อย (Y > 0) จุดตัดที่ 2 คือ รุนแรง เทียบกับ เล็กน้อยหรือปานกลาง (Y > 1)

ordinal logistic regression fit odds ratio ของเบาหวานเพียงค่าเดียวที่ต้องใช้ได้กับทั้งสองจุดตัด model คือ ologit severity i.diabetes c.age i.female, or และการตรวจทั้งหมดด้านล่างรันต่อจากคำสั่งนี้ทันที ใน cohort นี้ cumulative odds ratio ค่าเดียวนั้นเท่ากับ 1.90 แปลว่า odds ที่จะอยู่ในระดับที่สูงกว่า เทียบกับระดับนั้นหรือต่ำกว่า สูงเป็น 1.90 เท่าในผู้ป่วยเบาหวาน ไม่ว่าจะตัดที่จุดใด

"odds ratio เดียวสำหรับทุกจุดตัด" นี้คือ proportional odds assumption วิธีที่เห็นชัดที่สุดคือ fit logistic regression ธรรมดาแยกทีละจุดตัด แล้วเทียบ odds ratio สองค่า ถ้าใกล้กัน ตัวเลขเดียวก็สรุปได้อย่างยุติธรรม ถ้าห่างกันมาก ตัวเลขเดียวจะซ่อนความต่างนั้นไว้

การทดสอบแบบเป็นทางการตัวไหนรันได้ขึ้นกับ Stata ที่คุณมี estat parallel หลัง ologit ต้องใช้ StataNow บน Stata 18 ธรรมดาจะตอบว่า "estat parallel not valid", r(321) ส่วน brant ต้องมีแพ็กเกจ SPost13 ซึ่งไม่มีใน Stata 18 ที่ใช้ในบทความนี้ Stata จึงตอบว่า "command brant is unrecognized", r(199) คำสั่ง user-written oparallel (ssc install oparallel) รันบน Stata 18 ได้และให้ผลทดสอบห้าแบบในครั้งเดียว

สำหรับ severity ทั้งห้าแบบให้ผลตรงกัน likelihood-ratio test ให้ chi2 = 3.435 ที่ 3 degrees of freedom และ p = 0.329 ส่วน Brant test ให้ p = 0.331 จึงไม่มีหลักฐานแย้ง proportional odds ซึ่งเข้ากับวิธีที่ข้อมูลถูกสร้างจากมาตราส่วนแฝงเดียวกัน

การตรวจอีกแบบหนึ่งคือคำสั่ง user-written gologit2 (ssc install gologit2) พร้อม autofit ซึ่งให้ covariate มี odds ratio แยกตามจุดตัดเฉพาะเมื่อข้อมูลบังคับ สำหรับ severity มันคงเบาหวานไว้ที่ odds ratio ร่วมค่าเดียว (p = 0.1605) ตรงกับ oparallel

โค้ด Stata 03_check_models.do (บรรทัด 127-145 จาก 240)
ologit severity i.diabetes c.age i.female, or
estimates store model_severity_ologit

* estat parallel needs StataNow; plain Stata 18 refuses it.
capture noisily estat parallel
display as text "return code: r(" _rc ") (0 = StataNow)"

* brant needs the SPost13 package.
capture noisily brant
display as text "return code: r(" _rc ") (199 = brant not installed)"

* oparallel (ssc install oparallel) works on Stata 18 after ologit
oparallel
* read: all five tests; large p = no evidence against proportional odds

* Partial proportional odds (ssc install gologit2): autofit frees only
* the variables that fail the parallel-lines test.
gologit2 severity i.diabetes c.age i.female, autofit or
* read: Step lines (P Value of each variable) and the final model
ผลลัพธ์จากการรัน 03_check_models.log
. ologit severity i.diabetes c.age i.female, or

Iteration 0:  Log likelihood = -1202.5936
Iteration 1:  Log likelihood = -1160.4847
Iteration 2:  Log likelihood =  -1160.281
Iteration 3:  Log likelihood =  -1160.281

Ordered logistic regression                             Number of obs =  1,200
                                                        LR chi2(3)    =  84.63
                                                        Prob > chi2   = 0.0000
Log likelihood = -1160.281                              Pseudo R2     = 0.0352

------------------------------------------------------------------------------
    severity | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.898396   .2341316     5.20   0.000     1.490758    2.417501
         age |    1.03446   .0051357     6.82   0.000     1.024443    1.044575
             |
      female |
     Female  |   1.081509    .122423     0.69   0.489     .8663174    1.350153
-------------+----------------------------------------------------------------
       /cut1 |   2.638261   .3472221                      1.957719    3.318804
       /cut2 |   4.161577   .3599673                      3.456054      4.8671
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation to odds ratios.

. estimates store model_severity_ologit

.
. * estat parallel needs StataNow; plain Stata 18 refuses it.
. capture noisily estat parallel
estat parallel not valid

. display as text "return code: r(" _rc ") (0 = StataNow)"
return code: r(321) (0 = StataNow)

.
. * brant needs the SPost13 package.
. capture noisily brant
command brant is unrecognized

. display as text "return code: r(" _rc ") (199 = brant not installed)"
return code: r(199) (199 = brant not installed)

.
. * oparallel (ssc install oparallel) works on Stata 18 after ologit
. oparallel

Tests of the parallel regression assumption

                 |   Chi2     df  P>Chi2
-----------------+----------------------
     Wolfe Gould |  3.514      3   0.319
           Brant |  3.424      3   0.331
           score |  3.426      3   0.330
likelihood ratio |  3.435      3   0.329
            Wald |  3.432      3   0.330

. * read: all five tests; large p = no evidence against proportional odds
.
. * Partial proportional odds (ssc install gologit2): autofit frees only
. * the variables that fail the parallel-lines test.
. gologit2 severity i.diabetes c.age i.female, autofit or

------------------------------------------------------------------------------
Testing parallel lines assumption using the .05 level of significance...

Step  1:  Constraints for parallel lines imposed for 1.female (P Value = 0.8843
> )
Step  2:  Constraints for parallel lines imposed for age (P Value = 0.2353)
Step  3:  Constraints for parallel lines imposed for 1.diabetes (P Value = 0.16
> 05)
Step  4:  All explanatory variables meet the pl assumption

Wald test of parallel lines assumption for the final model:

 ( 1)  [Mild]1.female - [Moderate]1.female = 0
 ( 2)  [Mild]1.diabetes - [Moderate]1.diabetes = 0
 ( 3)  [Mild]age - [Moderate]age = 0

           chi2(  3) =    3.43
         Prob > chi2 =    0.3297
หาแถวเบาหวานของ ologit (1.898396) สองคำสั่งที่รันไม่ได้ คือ r(321) และ r(199) ตาราง oparallel ที่ทุกค่า P>Chi2 อยู่ระหว่าง 0.319 ถึง 0.331 และบรรทัด Step ของ gologit2 ที่เบาหวานคง odds ratio ค่าเดียว (P Value 0.1605 ถูกตัดขึ้นบรรทัดใหม่) proportional odds จึงเป็นจริง

เมื่อ proportional odds ไม่ผ่าน

เพื่อให้เห็นตอนที่ไม่ผ่าน do-file สร้างระดับความรุนแรงตัวที่สองชื่อ severity_npo ให้ผู้ป่วยกลุ่มเดิมทั้ง 1,200 คน ในตัวแปรนี้เบาหวานแทบไม่มีผลต่อการพ้นจากระดับเล็กน้อย แต่มีผลมากต่อการไปถึงระดับรุนแรง ผู้ป่วยเบาหวานอยู่ในระดับรุนแรง 40.37% เทียบกับ 13.40% ในผู้ที่ไม่เป็น ส่วนระดับเล็กน้อยต่างกันน้อย คือ 40.06% เทียบกับ 44.79%

ologit ยังพิมพ์ cumulative odds ratio ค่าเดียวที่ดูเรียบร้อย คือ 1.92 และไม่มีอะไรในตารางเตือนคุณเลย แต่ oparallel เตือน ทุกการทดสอบให้ p = 0.000 และ likelihood-ratio test ให้ chi2 = 83.17 ตัวอย่างขนาดใหญ่ทำให้การทดสอบเหล่านี้ปฏิเสธได้แม้ความเบี่ยงเบนเล็กน้อย ค่า p ที่ต่ำจึงเป็นจุดเริ่มของการตัดสินใจ ไม่ใช่จุดจบ

โค้ด Stata 03_check_models.do (บรรทัด 158-165 จาก 240)
tabulate severity_npo diabetes, column

* The same check as for severity, now on severity_npo:
* here oparallel should reject.
ologit severity_npo i.diabetes c.age i.female, or
estimates store model_severity_npo_ologit
oparallel
* read: all five tests; small p = proportional odds fails
ผลลัพธ์จากการรัน 03_check_models.log
. tabulate severity_npo diabetes, column

+-------------------+
| Key               |
|-------------------|
|     frequency     |
| column percentage |
+-------------------+

     DEMO: |
 severity, |
non-propor |
    tional |  Diabetes (exposure)
      odds |        No        Yes |     Total
-----------+----------------------+----------
      Mild |       391        131 |       522
           |     44.79      40.06 |     43.50
-----------+----------------------+----------
  Moderate |       365         64 |       429
           |     41.81      19.57 |     35.75
-----------+----------------------+----------
    Severe |       117        132 |       249
           |     13.40      40.37 |     20.75
-----------+----------------------+----------
     Total |       873        327 |     1,200
           |    100.00     100.00 |    100.00

.
. * The same check as for severity, now on severity_npo:
. * here oparallel should reject.
. ologit severity_npo i.diabetes c.age i.female, or

Iteration 0:  Log likelihood = -1267.3789
Iteration 1:  Log likelihood = -1228.6462
Iteration 2:  Log likelihood = -1228.5084
Iteration 3:  Log likelihood = -1228.5083

Ordered logistic regression                             Number of obs =  1,200
                                                        LR chi2(3)    =  77.74
                                                        Prob > chi2   = 0.0000
Log likelihood = -1228.5083                             Pseudo R2     = 0.0307

------------------------------------------------------------------------------
severity_npo | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.917858   .2462288     5.07   0.000      1.49119    2.466608
         age |   1.031426   .0048408     6.59   0.000     1.021982    1.040958
             |
      female |
     Female  |   .9445405    .104028    -0.52   0.604      .761154    1.172111
-------------+----------------------------------------------------------------
       /cut1 |   1.946518   .3233202                      1.312822    2.580213
       /cut2 |   3.632491   .3362017                      2.973548    4.291434
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation to odds ratios.

. estimates store model_severity_npo_ologit

. oparallel

Tests of the parallel regression assumption

                 |   Chi2     df  P>Chi2
-----------------+----------------------
     Wolfe Gould |  83.58      3   0.000
           Brant |  92.38      3   0.000
           score |  103.5      3   0.000
likelihood ratio |  83.17      3   0.000
            Wald |  95.97      3   0.000
เทียบแถว Severe ระหว่างกลุ่มเบาหวาน (13.40 เทียบกับ 40.37) แล้วดูตาราง oparallel ทุกค่า P>Chi2 เป็น 0.000 cumulative odds ratio ค่าเดียวจึงใช้กับ severity_npo ไม่ได้

ไล่บันไดทีละขั้น

ขั้นที่ 1: ดู odds ratio แยกตามจุดตัด logit ที่ fit แยกกันให้ 1.11 สำหรับจุดตัดที่ 1 และ 4.11 สำหรับจุดตัดที่ 2 odds ratio ที่ใกล้ 1 เทียบกับค่าที่ใกล้ 4 ให้ความหมายทางคลินิกต่างกันมาก เบาหวานแทบไม่ทำให้ผู้ป่วยพ้นจากระดับเล็กน้อย แต่ผลักให้ไปถึงระดับรุนแรงอย่างชัดเจน ตัวเลขเดียว 1.92 ซ่อนเรื่องนี้ไว้

ขั้นที่ 2: ปลดเฉพาะตัวที่ไม่ผ่าน gologit2 พร้อม autofit ทดสอบ covariate ทีละตัว และปลดเฉพาะตัวที่ขัดกับ assumption ในที่นี้มันคงอายุและเพศไว้ที่ odds ratio ร่วมค่าเดียว และปลดเฉพาะเบาหวาน (p = 0.00000) ตอนนี้เบาหวานมี odds ratio สองค่า คือ 1.09 สำหรับจุดตัดที่ 1 และ 4.15 สำหรับจุดตัดที่ 2

model แบบนี้เรียกว่า partial proportional odds model output ของมันตั้งชื่อแต่ละสมการตามระดับที่อยู่ใต้จุดตัด สมการที่ชื่อ Mild จึงเป็นจุดตัดที่ 1 และ Moderate เป็นจุดตัดที่ 2

ขั้นที่ 3: รักษาลำดับไว้ด้วยวิธีอื่น stereotype logit slogit (มีในตัว) ให้คะแนนแต่ละระดับบนมาตราส่วนร่วมเดียวกัน ผลของเบาหวานจึงแรงกว่าในบางระดับได้ ส่วน continuation-ratio model ocratio (ssc install ocratio) ถามทีละระดับว่าผู้ป่วยที่มาถึงระดับนั้นแล้วจะไปเกินระดับนั้นหรือไม่ บทความนี้ไม่ได้รันทั้งสองแบบ

ขั้นที่ 4: mlogit เป็นทางสุดท้าย มันทิ้งลำดับและ fit หนึ่งสมการต่อหนึ่งระดับ จึงใช้เมื่อลำดับไม่สำคัญต่อคำถามของคุณเท่านั้น การเทียบสองตระกูลนี้แบบเต็มอยู่ใน Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes (ฉบับภาษาอังกฤษ)

อ่านไล่ลงมาตามคอลัมน์ซ้าย ที่แต่ละกล่องให้ถามว่า odds ratio ค่าเดียวยังพอหรือไม่ กล่องด้านขวาคือจุดที่หยุดได้ สำหรับ severity_npo คำตอบคือไม่พอทั้งที่กล่อง oparallel และที่ logit แยกจุดตัด (1.11 เทียบกับ 4.11) จึงหยุดที่ gologit2
โค้ด Stata 03_check_models.do (บรรทัด 167-180 จาก 240)
* The two splits as separate logits: compare the diabetes rows.
* Split 1: moderate or severe vs mild. Split 2: severe vs the rest.
generate npo_not_mild = severity_npo >= 1 if !missing(severity_npo)
generate npo_severe = severity_npo == 2 if !missing(severity_npo)
logit npo_not_mild i.diabetes c.age i.female, or
estimates store model_severity_npo_split_1
logit npo_severe i.diabetes c.age i.female, or
estimates store model_severity_npo_split_2

* gologit2 with autofit frees proportional odds only where it fails.
gologit2 severity_npo i.diabetes c.age i.female, autofit or
* read: Step 3 (diabetes not constrained); diabetes in Mild vs Moderate
* gologit2 names each equation after the category BELOW the split:
* "Mild" = Y > 0, "Moderate" = Y > 1.
ผลลัพธ์จากการรัน 03_check_models.log
. generate npo_not_mild = severity_npo >= 1 if !missing(severity_npo)

. generate npo_severe = severity_npo == 2 if !missing(severity_npo)

. logit npo_not_mild i.diabetes c.age i.female, or

Iteration 0:  Log likelihood = -821.60786
Iteration 1:  Log likelihood = -802.95219
Iteration 2:  Log likelihood = -802.93078
Iteration 3:  Log likelihood = -802.93078

Logistic regression                                     Number of obs =  1,200
                                                        LR chi2(3)    =  37.35
                                                        Prob > chi2   = 0.0000
Log likelihood = -802.93078                             Pseudo R2     = 0.0227

------------------------------------------------------------------------------
npo_not_mild | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.107484   .1488367     0.76   0.447     .8510268    1.441226
         age |   1.030276   .0052966     5.80   0.000     1.019947    1.040709
             |
      female |
     Female  |   .9466345   .1128865    -0.46   0.646     .7493353    1.195882
       _cons |    .171901    .060506    -5.00   0.000     .0862326    .3426774
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. estimates store model_severity_npo_split_1

. logit npo_severe i.diabetes c.age i.female, or

Iteration 0:  Log likelihood = -612.75056
Iteration 1:  Log likelihood =  -551.7707
Iteration 2:  Log likelihood = -547.96772
Iteration 3:  Log likelihood = -547.95799
Iteration 4:  Log likelihood = -547.95798

Logistic regression                                     Number of obs =  1,200
                                                        LR chi2(3)    = 129.59
                                                        Prob > chi2   = 0.0000
Log likelihood = -547.95798                             Pseudo R2     = 0.1057

------------------------------------------------------------------------------
  npo_severe | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   4.114223   .6282828     9.26   0.000     3.050007    5.549767
         age |   1.038772   .0070581     5.60   0.000      1.02503    1.052698
             |
      female |
     Female  |   .9934492   .1515543    -0.04   0.966     .7367018    1.339675
       _cons |   .0112169   .0055606    -9.06   0.000     .0042453    .0296375
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. estimates store model_severity_npo_split_2

.
. * gologit2 with autofit frees proportional odds only where it fails.
. gologit2 severity_npo i.diabetes c.age i.female, autofit or

------------------------------------------------------------------------------
Testing parallel lines assumption using the .05 level of significance...

Step  1:  Constraints for parallel lines imposed for 1.female (P Value = 0.8916
> )
Step  2:  Constraints for parallel lines imposed for age (P Value = 0.2443)
Step  3:  Constraints for parallel lines are not imposed for
          1.diabetes (P Value = 0.00000)

Wald test of parallel lines assumption for the final model:

 ( 1)  [Mild]1.female - [Moderate]1.female = 0
 ( 2)  [Mild]age - [Moderate]age = 0

           chi2(  2) =    1.38
         Prob > chi2 =    0.5023

An insignificant test statistic indicates that the final model
does not violate the proportional odds/ parallel lines assumption

If you re-estimate this exact same model with gologit2, instead
of autofit you can save time by using the parameter

pl(0b.female 1.female 0b.diabetes age)

------------------------------------------------------------------------------

Generalized Ordered Logit Estimates                     Number of obs =  1,200
                                                        LR chi2(4)    = 159.53
                                                        Prob > chi2   = 0.0000
Log likelihood = -1187.6123                             Pseudo R2     = 0.0629

 ( 1)  [Mild]1.female - [Moderate]1.female = 0
 ( 2)  [Mild]age - [Moderate]age = 0
------------------------------------------------------------------------------
severity_npo | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
Mild         |
    diabetes |
        Yes  |   1.091097   .1466934     0.65   0.517     .8383454    1.420051
             |
         age |   1.032936   .0049305     6.79   0.000     1.023318    1.042645
             |
      female |
     Female  |   .9568249   .1062962    -0.40   0.691     .7696092    1.189583
             |
       _cons |   .1450439   .0474641    -5.90   0.000     .0763752    .2754522
-------------+----------------------------------------------------------------
Moderate     |
    diabetes |
        Yes  |    4.14703    .629851     9.37   0.000     3.079333    5.584929
             |
         age |   1.032936   .0049305     6.79   0.000     1.023318    1.042645
             |
      female |
     Female  |   .9568249   .1062962    -0.40   0.691     .7696092    1.189583
             |
       _cons |   .0169816   .0059244   -11.68   0.000     .0085708    .0336463
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.
เทียบแถวเบาหวานของ logit สองจุดตัด คือ 1.107484 (npo_not_mild) กับ 4.114223 (npo_severe) แล้วดู Step 3 ของ gologit2 และแถวเบาหวานในสมการ Mild กับ Moderate คือ 1.091097 และ 4.14703 มีเพียงเบาหวานที่ต้องใช้ odds ratio สองค่า

Multinomial logistic regression: ขนาดช่อง base และ IIA

ที่หมายหลังจำหน่ายมีสามกลุ่มที่ไม่เรียงลำดับ คือ บ้าน หน่วยฟื้นฟู และสถานดูแลผู้สูงอายุ mlogit fit หนึ่งสมการต่อหนึ่งกลุ่มยกเว้นกลุ่มอ้างอิง (base) โดย fit ทุกสมการพร้อมกัน และแต่ละสมการเทียบกลุ่มนั้นกับ base สิ่งนี้ต้องจ่ายด้วยพารามิเตอร์ที่มากขึ้น likelihood-ratio test ของมันมี 6 degrees of freedom เทียบกับ 3 ของ ologit ที่ใช้ covariate ชุดเดียวกัน model คือ mlogit dispo i.diabetes c.age i.female ซึ่งตั้งใจเขียนโดยไม่ใส่ baseoutcome()

การตรวจแรกจึงเป็นตารางไขว้ธรรมดาเพื่อดูขนาดของแต่ละช่อง ในผู้ป่วยเบาหวาน 327 คน มี 53 คนไปหน่วยฟื้นฟู ซึ่งเป็นช่องที่เล็กที่สุด และ 74 คนไปสถานดูแลผู้สูงอายุ ช่องที่มีผู้ป่วยไม่กี่คนทำให้สมการไม่เสถียร ให้รวมกลุ่ม หรือบอกไว้ว่าข้อมูลบางเกินไป

การตรวจที่สองคือ base ถ้าไม่เขียน baseoutcome() Stata จะเลือกกลุ่มที่พบบ่อยที่สุด ไม่ใช่รหัสที่ต่ำที่สุด บ้านเป็นทั้งรหัส 0 และกลุ่มที่พบบ่อยที่สุด (854 คน) do-file จึงเปลี่ยนรหัสบ้านเป็น 2 แล้ว fit ใหม่ และ Stata ก็ยังเลือกบ้าน: e(baseout) = 2 ดังนั้นให้เขียน baseoutcome(#) ทุกครั้ง

อายุต้องเป็นเส้นตรงในทุกสมการ การตรวจด้วย spline ข้างบนจึงใช้กับทุกสมการ IIA (independence of irrelevant alternatives) หมายความว่าการเพิ่มหรือตัดกลุ่มหนึ่งออกไม่ควรเปลี่ยน odds ระหว่างอีกสองกลุ่มที่เหลือ เมื่อบ้าน หน่วยฟื้นฟู และสถานดูแลผู้สูงอายุเป็นทางเลือกที่กำหนดตายตัวแบบนี้ เรื่องนี้จึงแทบไม่เป็นปัญหา

โค้ด Stata 03_check_models.do (บรรทัด 184-198 จาก 240)
tabulate dispo diabetes
* Without baseoutcome() Stata uses the most frequent category.
mlogit dispo i.diabetes c.age i.female
display as text "base outcome chosen by Stata, e(baseout) = " e(baseout)

* Home is both code 0 and the most frequent here, so the line above
* cannot tell "lowest code" from "most frequent". Recode home to 2
* (the highest code) and fit the same model again.
generate dispo_home_coded_2 = 2 - dispo     // 0 nursing, 1 rehab, 2 home
label define dispo_home_coded_2_label 0 "Nursing home" 1 "Rehabilitation unit" 2 "Home"
label values dispo_home_coded_2 dispo_home_coded_2_label
label variable dispo_home_coded_2 "DEMO: destination, home = 2"
tabulate dispo_home_coded_2
mlogit dispo_home_coded_2 i.diabetes c.age i.female
display as text "base after recoding, e(baseout) = " e(baseout)
ผลลัพธ์จากการรัน 03_check_models.log
. tabulate dispo diabetes

          Discharge |
        destination |  Diabetes (exposure)
        (unordered) |        No        Yes |     Total
--------------------+----------------------+----------
               Home |       654        200 |       854
Rehabilitation unit |       138         53 |       191
       Nursing home |        81         74 |       155
--------------------+----------------------+----------
              Total |       873        327 |     1,200

. * Without baseoutcome() Stata uses the most frequent category.
. mlogit dispo i.diabetes c.age i.female

Iteration 0:  Log likelihood = -958.73585
Iteration 1:  Log likelihood = -901.67976
Iteration 2:  Log likelihood = -896.44756
Iteration 3:  Log likelihood =   -896.433
Iteration 4:  Log likelihood =   -896.433

Multinomial logistic regression                         Number of obs =  1,200
                                                        LR chi2(6)    = 124.61
                                                        Prob > chi2   = 0.0000
Log likelihood = -896.433                               Pseudo R2     = 0.0650

------------------------------------------------------------------------------
       dispo | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
Home         |  (base outcome)
-------------+----------------------------------------------------------------
Rehabilita~t |
    diabetes |
        Yes  |   .1748404   .1821159     0.96   0.337    -.1821003    .5317811
         age |   .0265636   .0071455     3.72   0.000     .0125586    .0405686
             |
      female |
     Female  |   .1312631   .1617033     0.81   0.417    -.1856695    .4481957
       _cons |  -3.406471   .5028751    -6.77   0.000    -4.392088   -2.420854
-------------+----------------------------------------------------------------
Nursing_home |
    diabetes |
        Yes  |   .9931329   .1877955     5.29   0.000     .6250605    1.361205
         age |   .0749393   .0088318     8.49   0.000     .0576293    .0922493
             |
      female |
     Female  |  -.1243209   .1873336    -0.66   0.507    -.4914881    .2428462
       _cons |  -7.330181   .6683567   -10.97   0.000    -8.640136   -6.020226
------------------------------------------------------------------------------

. display as text "base outcome chosen by Stata, e(baseout) = " e(baseout)
base outcome chosen by Stata, e(baseout) = 0

.
. * Home is both code 0 and the most frequent here, so the line above
. * cannot tell "lowest code" from "most frequent". Recode home to 2
. * (the highest code) and fit the same model again.
. generate dispo_home_coded_2 = 2 - dispo     // 0 nursing, 1 rehab, 2 home

. label define dispo_home_coded_2_label 0 "Nursing home" 1 "Rehabilitation unit
> " 2 "Home"

. label values dispo_home_coded_2 dispo_home_coded_2_label

. label variable dispo_home_coded_2 "DEMO: destination, home = 2"

. tabulate dispo_home_coded_2

 DEMO: destination, |
           home = 2 |      Freq.     Percent        Cum.
--------------------+-----------------------------------
       Nursing home |        155       12.92       12.92
Rehabilitation unit |        191       15.92       28.83
               Home |        854       71.17      100.00
--------------------+-----------------------------------
              Total |      1,200      100.00

. mlogit dispo_home_coded_2 i.diabetes c.age i.female

Iteration 0:  Log likelihood = -958.73585
Iteration 1:  Log likelihood = -901.67976
Iteration 2:  Log likelihood = -896.44756
Iteration 3:  Log likelihood =   -896.433
Iteration 4:  Log likelihood =   -896.433

Multinomial logistic regression                         Number of obs =  1,200
                                                        LR chi2(6)    = 124.61
                                                        Prob > chi2   = 0.0000
Log likelihood = -896.433                               Pseudo R2     = 0.0650

------------------------------------------------------------------------------
dispo_home~2 | Coefficient  Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
Nursing_home |
    diabetes |
        Yes  |   .9931329   .1877955     5.29   0.000     .6250605    1.361205
         age |   .0749393   .0088318     8.49   0.000     .0576293    .0922493
             |
      female |
     Female  |  -.1243209   .1873336    -0.66   0.507    -.4914881    .2428462
       _cons |  -7.330181   .6683567   -10.97   0.000    -8.640136   -6.020226
-------------+----------------------------------------------------------------
Rehabilita~t |
    diabetes |
        Yes  |   .1748404   .1821159     0.96   0.337    -.1821003    .5317811
         age |   .0265636   .0071455     3.72   0.000     .0125586    .0405686
             |
      female |
     Female  |   .1312631   .1617033     0.81   0.417    -.1856695    .4481957
       _cons |  -3.406471   .5028751    -6.77   0.000    -4.392088   -2.420854
-------------+----------------------------------------------------------------
Home         |  (base outcome)
------------------------------------------------------------------------------

. display as text "base after recoding, e(baseout) = " e(baseout)
base after recoding, e(baseout) = 2
ดูช่องที่เล็กที่สุด (53) และ e(baseout) = 0 แล้วดูบรรทัดสุดท้ายหลังเปลี่ยนรหัสบ้านเป็น 2 คือ e(baseout) = 2 Stata เลือกกลุ่มที่พบบ่อยที่สุด ไม่ใช่รหัสที่ต่ำที่สุด

Model จำนวนนับและอัตรา: ความแปรปรวนใกล้ค่าเฉลี่ยหรือไม่

การกลับมานอนโรงพยาบาลซ้ำเป็นจำนวนนับ คือ 0, 1, 2 ครั้งหรือมากกว่าต่อผู้ป่วยหนึ่งคน ภายใต้ระยะติดตามที่ไม่เท่ากัน model คือ Poisson rate model poisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr ซึ่งสมมติว่าในผู้ป่วยที่มี covariate และระยะติดตามเหมือนกัน ความแปรปรวนของจำนวนนับเท่ากับค่าเฉลี่ย

ถ้าดูคร่าว ๆ ก่อน ค่าเฉลี่ยดิบคือ 0.563 ครั้งต่อคน และความแปรปรวนดิบคือ 0.943 จำนวนนับดูกระจายมากกว่าที่ Poisson ยอมให้ ความกระจายส่วนเกินนี้เรียกว่า overdispersion แต่การเทียบตัวเลขดิบนี้เป็นเพียงเบาะแส เพราะระยะติดตามและ covariate ก็ทำให้ความแปรปรวนเปลี่ยนได้เช่นกัน การทดสอบด้านล่างจึงเป็นตัวตัดสิน overdispersion แทบไม่ทำให้ rate ratio เปลี่ยน แต่ทำให้ standard error ช่วงความเชื่อมั่น และค่า p เล็กเกินจริง

หลัง poisson คำสั่ง estat gof ให้การทดสอบความเข้ากันของ model สองแบบ ทั้งสองปฏิเสธ คือ deviance 1443.185 และ Pearson 1769.635 ต่างก็ที่ 1196 degrees of freedom และ p = 0.0000 แต่เมื่อจำนวนนับน้อยขนาดนี้ (ค่าเฉลี่ย 0.563) การทดสอบ chi2 เหล่านี้ให้ผลเพียงโดยประมาณ จึงใช้สนับสนุนการตัดสินใจ ไม่ใช่ตัดสินเอง

การตรวจที่ใช้ตัดสินมาจาก negative binomial model (nbreg) ซึ่งเพิ่มพารามิเตอร์หนึ่งตัวคือ alpha สำหรับความกระจายส่วนเกิน ถ้า alpha = 0 ก็คือ Poisson บรรทัดสุดท้ายของ output ทดสอบเรื่องนี้ตรง ๆ ได้ chibar2(01) = 77.42 และ p = 0.000 สำหรับ rate model ที่ใส่ exposure(fu_years) ค่า alpha เท่ากับ 0.754 (95% CI 0.541 ถึง 1.049) จึงควรเลือก nbreg

rate ratio ของเบาหวานแทบไม่เปลี่ยน คือ 1.58 ภายใต้ Poisson และ 1.51 ภายใต้ nbreg ซึ่งมีช่วง 1.24 ถึง 1.85 ที่สะท้อนความไม่แน่นอนได้ตรงกว่า การคง Poisson ไว้แล้วใส่ vce(robust) ก็แก้ standard error ได้เช่นกัน อย่าใช้ glm กับ family(nbinomial) เพราะมันตรึง alpha ไว้ที่ 1 เว้นแต่จะเขียน family(nbinomial ml) ตัว rate model เองสอนไว้ใน Rates, Poisson Regression, and the Missing Lambda Backbone (ฉบับภาษาอังกฤษ)

โค้ด Stata 03_check_models.do (บรรทัด 202-210 จาก 240)
tabstat readmit_n, statistics(mean variance)
* first look only: follow-up and covariates also move the raw variance
poisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr
estimates store model_readmit_rate_poisson
estat gof
* read: Deviance and Pearson, Prob > chi2 (rough with small counts)
nbreg readmit_n i.diabetes c.age i.female, exposure(fu_years) irr
estimates store model_readmit_rate_nbreg
* read: LR test of alpha=0 (small p = extra spread, prefer nbreg)
ผลลัพธ์จากการรัน 03_check_models.log
. tabstat readmit_n, statistics(mean variance)

    Variable |      Mean  Variance
-------------+--------------------
   readmit_n |  .5633333  .9434418
----------------------------------

. * first look only: follow-up and covariates also move the raw variance
. poisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr

Iteration 0:  Log likelihood = -1206.2177
Iteration 1:  Log likelihood = -1206.2177

Poisson regression                                      Number of obs =  1,200
                                                        LR chi2(3)    =  43.24
                                                        Prob > chi2   = 0.0000
Log likelihood = -1206.2177                             Pseudo R2     = 0.0176

------------------------------------------------------------------------------
   readmit_n |        IRR   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.577806   .1267972     5.67   0.000     1.347871    1.846965
         age |   1.008897     .00335     2.67   0.008     1.002353    1.015485
             |
      female |
     Female  |   1.068134    .082401     0.85   0.393     .9182479    1.242486
       _cons |   .2297324   .0538322    -6.28   0.000     .1451323    .3636474
ln(fu_years) |          1  (exposure)
------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate.

. estimates store model_readmit_rate_poisson

. estat gof

         Deviance goodness-of-fit =  1443.185
         Prob > chi2(1196)        =    0.0000

         Pearson goodness-of-fit  =  1769.635
         Prob > chi2(1196)        =    0.0000

. * read: Deviance and Pearson, Prob > chi2 (rough with small counts)
. nbreg readmit_n i.diabetes c.age i.female, exposure(fu_years) irr

Fitting Poisson model:

Iteration 0:  Log likelihood = -1206.2177
Iteration 1:  Log likelihood = -1206.2177

Fitting constant-only model:

Iteration 0:  Log likelihood = -1181.1677
Iteration 1:  Log likelihood = -1180.6536
Iteration 2:  Log likelihood = -1180.6531
Iteration 3:  Log likelihood = -1180.6531

Fitting full model:

Iteration 0:  Log likelihood =  -1168.134
Iteration 1:  Log likelihood = -1167.5105
Iteration 2:  Log likelihood = -1167.5091
Iteration 3:  Log likelihood = -1167.5091

Negative binomial regression                            Number of obs =  1,200
                                                        LR chi2(3)    =  26.29
Dispersion: mean                                        Prob > chi2   = 0.0000
Log likelihood = -1167.5091                             Pseudo R2     = 0.0111

------------------------------------------------------------------------------
   readmit_n |        IRR   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.514983   .1535783     4.10   0.000     1.241992    1.847977
         age |   1.010164   .0041202     2.48   0.013     1.002121    1.018272
             |
      female |
     Female  |   1.062921   .1008768     0.64   0.520      .882506     1.28022
       _cons |   .2142607   .0612126    -5.39   0.000     .1223942      .37508
ln(fu_years) |          1  (exposure)
-------------+----------------------------------------------------------------
    /lnalpha |  -.2828409   .1688926                     -.6138643    .0481825
-------------+----------------------------------------------------------------
       alpha |   .7536397   .1272842                      .5412552    1.049362
------------------------------------------------------------------------------
Note: Estimates are transformed only in the first equation to incidence-rate
      ratios.
Note: _cons estimates baseline incidence rate.
LR test of alpha=0: chibar2(01) = 77.42                Prob >= chibar2 = 0.000
ให้ค่าเฉลี่ยและความแปรปรวน (.5633333 เทียบกับ .9434418) เป็นแค่การดูคร่าว ๆ LR test of alpha=0 ที่ด้านล่างเป็นตัวตัดสิน และสองบรรทัดของ estat gof สนับสนุน ทั้งหมดชี้ไปที่ nbreg

Cox regression: hazard ยังเป็นสัดส่วนคงที่หรือไม่

ระยะเวลาจนเสียชีวิตภายใน 365 วันเป็น outcome สุดท้ายในรายการ มีผู้ป่วยเสียชีวิต 222 คน ข้อมูลถูกประกาศด้วย stset time_d, failure(died) และ model คือ stcox i.diabetes c.age i.female ซึ่งให้ hazard ratio ของเบาหวานค่าเดียวคือ 1.92 และสมมติว่าค่านี้คงที่ตั้งแต่วันแรกจนวันสุดท้าย นี่คือ proportional hazards assumption

หลัง stcox คำสั่ง estat phtest, detail ทดสอบข้อนี้ ทุกครั้งที่มีผู้เสียชีวิต มันหาผลต่างระหว่างค่า covariate ของผู้ที่เสียชีวิตกับค่าเฉลี่ยของผู้ที่ยังอยู่ในความเสี่ยง ผลต่างเหล่านี้เรียกว่า Schoenfeld residual ถ้าผลต่างมีแนวโน้มเปลี่ยนตามเวลา แปลว่าผลของ covariate เปลี่ยนไปตามเวลา และค่า p ที่ต่ำคือสัญญาณของแนวโน้มนั้น สำหรับเบาหวานได้ rho = 0.00696 และ p = 0.9167 ส่วน global test ให้ chi2 = 0.65 ที่ 3 degrees of freedom และ p = 0.8860

ในที่นี้ hazard จึงยังเป็นสัดส่วนคงที่ ถ้าการทดสอบไม่ผ่าน ให้ปล่อยผลเปลี่ยนตามเวลา โดย fit stcox พร้อม tvc(diabetes) texp(ln(_t)) หรือแบ่งช่วงติดตามด้วย stsplit แล้วประมาณ hazard ratio แยกแต่ละช่วง flexible parametric model คือ stpm2 (ssc install stpm2) ก็รองรับเรื่องนี้ได้ แต่ไม่ได้ติดตั้งไว้ใน Stata 18 ที่ใช้ในบทความนี้ จึงไม่ได้รันให้ดู ตัว Cox model เองสอนไว้ใน Cox Proportional Hazards Regression and Related Survival-Analysis Concepts (ฉบับภาษาอังกฤษ)

โค้ด Stata 03_check_models.do (บรรทัด 214-218 จาก 240)
stset time_d, failure(died)
stcox i.diabetes c.age i.female
estimates store model_death_cox
estat phtest, detail
* read: each covariate row and Global test (small p = not proportional)
ผลลัพธ์จากการรัน 03_check_models.log
. stset time_d, failure(died)

Survival-time data settings

         Failure event: died!=0 & died<.
Observed time interval: (0, time_d]
     Exit on or before: failure

--------------------------------------------------------------------------
      1,200  total observations
          0  exclusions
--------------------------------------------------------------------------
      1,200  observations remaining, representing
        222  failures in single-record/single-failure data
    391,391  total analysis time at risk and under observation
                                                At risk from t =         0
                                     Earliest observed entry t =         0
                                          Last observed exit t =       365

. stcox i.diabetes c.age i.female

        Failure _d: died
  Analysis time _t: time_d

Iteration 0:  Log likelihood = -1552.2399
Iteration 1:  Log likelihood = -1509.9605
Iteration 2:  Log likelihood = -1509.6317
Iteration 3:  Log likelihood = -1509.6317
Refining estimates:
Iteration 0:  Log likelihood = -1509.6317

Cox regression with Breslow method for ties

No. of subjects =   1,200                               Number of obs =  1,200
No. of failures =     222
Time at risk    = 391,391
                                                        LR chi2(3)    =  85.22
Log likelihood = -1509.6317                             Prob > chi2   = 0.0000

------------------------------------------------------------------------------
          _t | Haz. ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.918519   .2619999     4.77   0.000      1.46799    2.507317
         age |   1.039789   .0062316     6.51   0.000     1.027647    1.052075
             |
      female |
     Female  |   .5688773   .0813645    -3.94   0.000     .4298078    .7529445
------------------------------------------------------------------------------

. estimates store model_death_cox

. estat phtest, detail

Test of proportional-hazards assumption

Time function: Analysis time
--------------------------------------------------------
             |        rho     chi2       df    Prob>chi2
-------------+------------------------------------------
 0b.diabetes |          .        .        1           .
  1.diabetes |    0.00696     0.01        1       0.9167
         age |   -0.00683     0.01        1       0.9202
   0b.female |          .        .        1           .
    1.female |    0.05311     0.63        1       0.4282
-------------+------------------------------------------
 Global test |                0.65        3       0.8860
--------------------------------------------------------
อ่านบรรทัด failures ของ stset (222) hazard ratio ของเบาหวาน (1.918519) แล้วดูแถว 1.diabetes และ Global test ของ estat phtest ได้ p = 0.9167 และ 0.8860 hazard จึงคงสัดส่วนตลอด 365 วัน

ทุก model ในบรรทัดเดียว

อ่านแต่ละแถวจากซ้ายไปขวา ตั้งแต่ model และคำสัญญาของมัน จนถึงสัญญาณว่าไม่ผ่านและทางไปต่อ คำสั่ง user-written ต้อง ssc install ก่อน
ModelAssumptionคำสั่งตรวจสัญญาณว่าไม่ผ่านทางไปต่อ
regress (วันนอน)ความแปรปรวนคงที่; residual เป็นรูประฆังestat hettest; rvfplot; qnorm ของ residualp ต่ำ; รูปพัด; residual เบ้มากvce(robust); glm ที่ใช้ log link
logit (ICU)ความเสี่ยงที่ทำนายตรงกับจริง; link ถูกต้อง; X ต่อเนื่องเป็นเส้นตรงบน log-oddsestat gof, group(10); linktest; mkspline แล้ว testp ต่ำ; _hatsq มีนัยสำคัญ; ต้องใช้ชิ้น splineเก็บชิ้น spline ไว้; รายงานด้วย margins
logit ข้อมูลเล็กหรือบางไม่มี separationอ่าน log หา note หรือ r(2000)predicts success perfectly; obs not usedfirthlogit (user-written); exlogistic
glm, binomial family, log linkการ fit convergedisplay e(converged)Convergence not achieved; e(converged) = 0glm y x, family(poisson) link(log) vce(robust) eform
ologit (ความรุนแรง)Proportional odds: odds ratio เดียวสำหรับทุกจุดตัดoparallel (user-written, Stata 18); estat parallel (StataNow)p ต่ำ และ odds ratio แยกจุดตัดห่างกันมากgologit2, autofit (user-written); slogit หรือ ocratio; mlogit เป็นทางสุดท้าย
mlogit (ที่หมายหลังจำหน่าย)ทุกช่องมีผู้ป่วยพอ; base ที่เลือกเองtabulate y x; display e(baseout)ช่องเล็กมาก; base ที่ไม่ได้ตั้งใจรวมกลุ่ม; เขียน baseoutcome(#)
poisson (การนอนซ้ำ)ความแปรปรวนเท่ากับค่าเฉลี่ย เมื่อ covariate และระยะติดตามเท่ากันLR test ของ alpha = 0 หลัง nbreg (tabstat เป็นแค่การดูคร่าว ๆ)p ต่ำสำหรับ alpha = 0nbreg; หรือ poisson พร้อม vce(robust)
stcox (การเสียชีวิต)Proportional hazardsestat phtest, detailp ต่ำในบาง covariate หรือ global testtvc() พร้อม texp(); stsplit; stpm2 (user-written)
ทุก modelผู้ป่วยเป็นอิสระต่อกันรูปแบบการศึกษา ไม่ใช่การทดสอบชุดที่จับคู่ cluster แถวที่วัดซ้ำclogit; vce(cluster id); mixed หรือ GEE

เอกสารอ้างอิง

  1. Firth D. Bias reduction of maximum likelihood estimates. Biometrika 1993;80(1):27-38. https://doi.org/10.1093/biomet/80.1.27
  2. Heinze G, Schemper M. A solution to the problem of separation in logistic regression. Statistics in Medicine 2002;21(16):2409-2419. https://doi.org/10.1002/sim.1047
  3. Brant R. Assessing proportionality in the proportional odds model for ordinal logistic regression. Biometrics 1990;46(4):1171-1178. https://doi.org/10.2307/2532457
  4. Williams R. Generalized ordered logit/partial proportional odds models for ordinal dependent variables. The Stata Journal 2006;6(1):58-82. https://doi.org/10.1177/1536867X0600600104
  5. Grambsch PM, Therneau TM. Proportional hazards tests and diagnostics based on weighted residuals. Biometrika 1994;81(3):515-526. https://doi.org/10.1093/biomet/81.3.515

ประเด็นสำคัญ

  • residual ที่เป็นรูประฆังและความแปรปรวนคงที่เป็นการตรวจของ regress เท่านั้น model อื่นมีการตรวจของตัวเอง
  • separation มาแบบเงียบหรือแบบหยุดทำงาน ให้อ่าน log หา predicts success perfectly แล้ว fit ใหม่ด้วย firthlogit หรือ exlogistic
  • สำหรับ ologit บน Stata 18 ให้รัน oparallel และเทียบ odds ratio แยกจุดตัด ปลดเฉพาะตัวแปรที่ไม่ผ่านด้วย gologit2 ก่อนจะทิ้งลำดับ
  • ความแปรปรวนดิบที่สูงกว่าค่าเฉลี่ยเป็นเพียงเบาะแสของ overdispersion การทดสอบ alpha = 0 ของ nbreg เป็นตัวตัดสิน
  • ความเป็นอิสระมาจากรูปแบบการศึกษา ชุดที่จับคู่ต้องใช้ clogit ส่วน cluster ต้องใช้ vce(cluster id), mixed หรือ GEE

อ่านต่อในวิกิ: Link และ Family: ตัวหนึ่งกำหนดมาตรวัดผล อีกตัวกำหนดค่าคลาดเคลื่อนมาตรฐาน · Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes · ทำไม Logistic และ Conditional Logistic Regression จึงให้ Odds Ratio ต่างกัน? · ทำความเข้าใจ VCE: Robust Standard Error, Sandwich Estimator และ vce(cluster id) · ทางเลือกแบบ Population-Averaged: GLS, GEE และจุดที่โชคของ linear model หมดลง · หา Risk Ratio เมื่อผลลัพธ์พบบ่อย: ลำดับขั้นถอยลงเมื่อ Log-Binomial ชนกำแพง · Rates, Poisson Regression, and the Missing Lambda Backbone · Cox Proportional Hazards Regression and Related Survival-Analysis Concepts

0
ถึงนักอ่านชาวไทยและต่างชาติทำความเข้าใจบริบททางการแพทย์ของผมอ่านต่อ →ถึงนักอ่านชาวไทยและต่างชาติทำความเข้าใจเนื้อหาของผมที่นอกเหนือจากการแพทย์อ่านต่อ →

ความคิดเห็น

ยังไม่มีความคิดเห็น มาเป็นคนแรกกันเลย

เข้าสู่ระบบเพื่อแสดงความคิดเห็น