เขียนคำสั่ง regression ใน Stata ตามชนิด outcome และอ่าน coefficient แต่ละตัว

Clinical Epidemiology ResearchMethodology and Research Design THUniqcret doctor knowledges TH
เขียนคำสั่ง regression ใน Stata ตามชนิด outcome และอ่าน coefficient แต่ละตัว
On this page

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

บทคัดย่อ

บทความนี้ fit regression model หนึ่งตัวต่อ outcome แต่ละชนิด บนข้อมูลจำลองของผู้ป่วยผู้ใหญ่ 1,200 คนที่นอนโรงพยาบาลด้วยปอดอักเสบ ซึ่ง 327 คนเป็นเบาหวาน ทุก model มีคำสั่ง Stata บรรทัด output เพียงบรรทัดเดียวที่ต้องอ่าน และประโยคเดียวที่แปล coefficient เป็นภาษาคลินิก วันนอนโรงพยาบาลให้ผลต่างของค่าเฉลี่ย 1.44 วัน การเข้า ICU ให้ตัวเลขสามตัวจากตารางเดียว แล้วได้ odds ratio 1.65 จาก logit เมื่อ log-binomial model ไม่ converge modified Poisson ให้ risk ratio 1.41 และ identity link ให้ risk difference 0.094 ระดับความรุนแรงให้ cumulative odds ratio 1.90 ส่วนปลายทางเมื่อจำหน่ายให้ relative risk ratio และ margins แปลงทั้งสองแบบเป็นความน่าจะเป็นที่ทำนายได้ การกลับมานอนซ้ำให้ incidence rate ratio โดยใช้ exposure() เมื่อต้องการอัตรา การเสียชีวิตให้ hazard ratio 1.92 หลัง stset และ vce(cluster hospital) เปลี่ยนเฉพาะ standard error


ภาพสรุป: outcome ทั้งเจ็ดแบบของผู้ป่วยปอดอักเสบ 1,200 คน แต่ละแบบมีคำสั่ง Stata และตัวเลขที่พิมพ์ออกมาสำหรับเบาหวาน

ผู้ป่วยชุดเดียว outcome เจ็ดแบบ

ลองนึกถึงผู้ป่วยผู้ใหญ่ 1,200 คนที่นอนโรงพยาบาลด้วยโรคปอดอักเสบ ในจำนวนนี้ 327 คนเป็นเบาหวาน และ 873 คนไม่เป็น คำถามของเราไม่เคยเปลี่ยน คือผู้ป่วยเบาหวานต่างจากผู้ป่วยที่ไม่เป็นเบาหวานแค่ไหน เมื่ออายุและเพศเท่ากัน

สิ่งที่เปลี่ยนคือ outcome ผู้ป่วยกลุ่มเดียวกันนี้ถูกวัดผลเจ็ดแบบ ได้แก่ วันนอนโรงพยาบาล การเข้า ICU ระดับความรุนแรง ปลายทางเมื่อจำหน่าย จำนวนครั้งที่กลับมานอนซ้ำ อัตราการกลับมานอนซ้ำต่อ person-year (จำนวนครั้งหารด้วยจำนวนปีที่ติดตามผู้ป่วยแต่ละคน) และเวลาจนเสียชีวิตภายใน 365 วัน outcome แต่ละแบบต้องใช้คำสั่งของตัวเอง และแต่ละคำสั่งพิมพ์ตัวเลขคนละชนิด

ทุก model ด้านล่างปรับด้วย c.age และ i.female ใน Stata ตัว c ใน c.age บอกคำสั่งว่าอายุเป็นตัวเลขต่อเนื่อง ส่วนตัว i ใน i.female บอกว่าเพศเป็นกลุ่ม (category) แต่ละกลุ่มยกเว้นกลุ่มอ้างอิง (base) จึงได้แถวของตัวเองใน output ข้อมูลชุดนี้สร้างขึ้นด้วย do-file จึงไม่มีผู้ป่วยจริงอยู่ในนั้นเลย

เบาหวานเข้า model แบบเดียวกันคือ i.diabetes บรรทัดที่ต้องอ่านจึงเป็นแถว Yes ใต้ diabetes มีสามที่ที่ต่างออกไปและจะบอกไว้เมื่อถึงตรงนั้น คือตารางสองคูณสองแบบดิบไม่มีการปรับ mlogit มีแถว Yes หนึ่งแถวต่อปลายทางแต่ละแห่ง และ margins ให้แถว Yes หนึ่งแถวต่อกลุ่มที่ทำนายแต่ละกลุ่ม

บทความนี้เป็นบทที่สองจากสามบท บทแรกคือการเลือก model ที่ เลือก regression model ตัวไหน: flow จาก design และ outcome (Y) ถึงคำสั่ง Stata บทที่สองคือการ fit model ซึ่งก็คือบทความนี้ และบทที่สามคือการตรวจว่า model เชื่อถือได้หรือไม่ ที่ ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน

ไล่ดูกล่องทั้งสี่จากบนลงล่างกับทุก model ในบทความนี้ ตัวอย่าง ICU แสดงให้เห็นรูปแบบ คือคอลัมน์ Odds ratio บอกชื่อของตัวเลข และช่วงความเชื่อมั่นอยู่เหนือ 1 จึงแปลว่าเบาหวานทำให้ odds ของการเข้า ICU เป็นประมาณ 1.65 เท่า

วันนอนโรงพยาบาล: ผลต่างของค่าเฉลี่ย

วันนอนโรงพยาบาลนับเป็นจำนวนวัน คำสั่ง regress ลากเส้นตรงผ่านข้อมูล coefficient จึงมีหน่วยเป็นวันเช่นกัน คือผลต่างของค่าเฉลี่ยวันนอนระหว่างผู้ป่วยที่เป็นและไม่เป็นเบาหวานที่มีอายุและเพศเดียวกัน

Stata พิมพ์ 1.436325 (95% CI 1.160553 ถึง 1.712098) พูดเป็นภาษาคลินิกได้ว่า เมื่ออายุและเพศเท่ากัน ผู้ป่วยเบาหวานนอนโรงพยาบาลนานกว่าโดยเฉลี่ยประมาณ 1.44 วัน การตรวจเส้นตรงและ residual เป็นเรื่องของ regress เท่านั้น และอยู่ใน ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน

โค้ด Stata 02_fit_models.do (บรรทัด 37-42 จาก 187)
* ---- 2. Continuous Y (length of stay): linear regression ----
* b for diabetes = difference in mean length of stay (days), same age and sex.
* b ของเบาหวาน = ผลต่างของค่าเฉลี่ยวันนอน (วัน) ที่อายุและเพศเดียวกัน
regress los i.diabetes c.age i.female
estimates store model_los_regress
* line to read: Diabetes Yes, Coefficient [95% conf. interval]
ผลลัพธ์จากการรัน 02_fit_models.log
. regress los i.diabetes c.age i.female

      Source |       SS           df       MS      Number of obs   =     1,200
-------------+----------------------------------   F(3, 1196)      =    100.02
       Model |  1390.25663         3  463.418878   Prob > F        =    0.0000
    Residual |  5541.19262     1,196   4.6331042   R-squared       =    0.2006
-------------+----------------------------------   Adj R-squared   =    0.1986
       Total |  6931.44926     1,199  5.78102523   Root MSE        =    2.1525

------------------------------------------------------------------------------
         los | Coefficient  Std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.436325   .1405606    10.22   0.000     1.160553    1.712098
         age |   .0655404   .0052618    12.46   0.000      .055217    .0758638
             |
      female |
     Female  |  -.3359886   .1253015    -2.68   0.007    -.5818238   -.0901535
       _cons |   2.696336   .3631627     7.42   0.000     1.983829    3.408843
------------------------------------------------------------------------------
ดูแถว Yes ใต้ diabetes: 1.436325 วันคือผลต่างของค่าเฉลี่ยวันนอนหลังปรับด้วยอายุและเพศ

การเข้า ICU: ตัวเลขสามตัวจากตารางเดียว

การเข้า ICU มีแค่สองค่า คือเข้าหรือไม่เข้า ก่อนจะ fit model ใด ๆ ให้จัดผู้ป่วย 1,200 คนลงในตารางสองคูณสองก่อน ในผู้ป่วยเบาหวาน 327 คน มี 112 คนที่เข้า ICU ส่วนผู้ป่วยที่ไม่เป็นเบาหวาน 873 คน มี 197 คนที่เข้า

ตารางเดียวนี้ให้ตัวเลขสามตัว และแต่ละตัวตอบคำถามคนละข้อ risk difference ถามว่าในผู้ป่วยทุกร้อยคนมีคนเข้า ICU เพิ่มขึ้นกี่คน risk ratio ถามว่าความเสี่ยงเป็นกี่เท่า ส่วน odds ratio ถามว่า odds เป็นกี่เท่า โดย odds คือจำนวนคนที่เข้า ICU หารด้วยจำนวนคนที่ยังอยู่หอผู้ป่วยสามัญ

คำนวณตัววัดทั้งสามด้วยมือ

ผู้ป่วยเบาหวานเข้า ICU 112 คนและไม่เข้า 215 คน ผู้ป่วยที่ไม่เป็นเบาหวานเข้า 197 คนและไม่เข้า 676 คน

  1. ขั้นที่ 1 ความเสี่ยงเมื่อเป็นเบาหวาน

    112 / 327 = 0.3425

  2. ขั้นที่ 2 ความเสี่ยงเมื่อไม่เป็นเบาหวาน

    197 / 873 = 0.2257

  3. ขั้นที่ 3 risk difference

    0.3425 ลบ 0.2257 = 0.1168 คือเข้า ICU เพิ่มขึ้นประมาณ 11.7 คนในผู้ป่วยทุก 100 คน

  4. ขั้นที่ 4 risk ratio

    0.3425 / 0.2257 = 1.52 คือความเสี่ยงประมาณ 1.52 เท่า

  5. ขั้นที่ 5 odds ratio

    odds เมื่อเป็นเบาหวานคือ 112 / 215 = 0.5209 และเมื่อไม่เป็นคือ 197 / 676 = 0.2914 แล้ว 0.5209 / 0.2914 = 1.79

ผลลัพธ์: คำสั่ง cs ของ Stata พิมพ์ตัวเลขชุดเดียวกัน คือ risk difference .116849 risk ratio 1.517813 และ odds ratio 1.787558

โค้ด Stata 02_fit_models.do (บรรทัด 44-49 จาก 187)
* ---- 3. Binary Y (ICU admission): the crude 2x2 table first ----
* One table gives all three measures: risk difference, risk ratio and odds ratio.
* ตารางเดียวให้ครบสามตัววัด: risk difference, risk ratio และ odds ratio
tabulate icu diabetes, column
cs icu diabetes, or
* lines to read: Risk difference, Risk ratio, Odds ratio (crude, no adjustment)
ผลลัพธ์จากการรัน 02_fit_models.log
. tabulate icu diabetes, column

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

       ICU |  Diabetes (exposure)
 admission |        No        Yes |     Total
-----------+----------------------+----------
        No |       676        215 |       891
           |     77.43      65.75 |     74.25
-----------+----------------------+----------
       Yes |       197        112 |       309
           |     22.57      34.25 |     25.75
-----------+----------------------+----------
     Total |       873        327 |     1,200
           |    100.00     100.00 |    100.00

. cs icu diabetes, or

                 |  Diabetes [exposure]   |
                 |   Exposed   Unexposed  |      Total
-----------------+------------------------+-----------
           Cases |       112         197  |        309
        Noncases |       215         676  |        891
-----------------+------------------------+-----------
           Total |       327         873  |       1200
                 |                        |
            Risk |  .3425076    .2256586  |      .2575
                 |                        |
                 |      Point estimate    |    [95% conf. interval]
                 |------------------------+------------------------
 Risk difference |          .116849       |    .0584161    .1752819
      Risk ratio |         1.517813       |    1.250112    1.842841
 Attr. frac. ex. |         .3411573       |    .2000714    .4573595
 Attr. frac. pop |         .1236557       |
      Odds ratio |         1.787558       |    1.354116    2.359829 (Cornfield)
                 +-------------------------------------------------
                               chi2(1) =    16.99  Pr>chi2 = 0.0000
ไล่อ่านแถว Risk, Risk difference, Risk ratio และ Odds ratio: ตรงกับที่คำนวณด้วยมือ ก่อนปรับด้วยตัวแปรใด ๆ

odds ratio: logit พร้อม option or

logit fit ค่า coefficient b บนสเกล log ของ odds สำหรับเบาหวานจึงได้ b = 0.4989 ก่อน ตัวเลขนี้อ่านยาก option or จึงแปลงกลับด้วย exp(0.4989) = 1.6469 ซึ่งก็คือ odds ratio หัวคอลัมน์จึงเขียนว่า Odds ratio

Stata พิมพ์ 1.646897 (95% CI 1.239519 ถึง 2.188162) ช่วงนี้ไม่ครอบคลุม 1 ซึ่งเป็นค่าที่แปลว่าไม่มีความต่าง odds จึงสูงกว่าเมื่อเป็นเบาหวาน พูดเป็นภาษาคลินิกได้ว่า เมื่ออายุและเพศเท่ากัน ผู้ป่วยเบาหวานมี odds ของการเข้า ICU ประมาณ 1.65 เท่า เทียบกับค่าดิบ 1.79

odds ratio ใช้ได้ไม่ว่า outcome จะพบบ่อยแค่ไหน ในข้อมูลแบบ case-control ก็ยังใช้ logistic regression และ Stata ก็ยังพิมพ์ odds ratio แต่ odds ratio นั้นประมาณค่าอะไรใน cohort (odds ratio, risk ratio หรือ rate ratio) ขึ้นกับวิธีสุ่มเลือก control ดู การเลือก Control ใน Stata: คำถามวิจัย วิธีสุ่ม Control และโมเดล เป็นสามเรื่องที่ต่างกัน

โค้ด Stata 02_fit_models.do (บรรทัด 51-56 จาก 187)
* ---- 4. Binary Y, measure = odds ratio: logistic regression ----
* exp(b) = odds ratio of ICU admission, diabetes vs no diabetes.
* exp(b) = odds ratio ของการเข้า ICU ผู้ป่วยเบาหวานเทียบกับไม่เป็นเบาหวาน
logit icu i.diabetes c.age i.female, or
estimates store model_icu_logit
* line to read: Diabetes Yes, Odds ratio [95% conf. interval]
ผลลัพธ์จากการรัน 02_fit_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.
คอลัมน์ Odds ratio แถว Yes: 1.646897 คือ odds ratio ของการเข้า ICU หลังปรับด้วยอายุและเพศ

risk ratio: ลอง log-binomial ก่อน และดูให้ออกเมื่อมันล้มเหลว

risk ratio ได้มาจาก binomial model ที่ใช้ log link โดย family บอกชนิดของ outcome ในที่นี้คือเข้าหรือไม่เข้า ส่วน link บอกสเกลที่ตัวแปรต่าง ๆ บวกกัน ในที่นี้คือ log ของความเสี่ยง exp(b) จึงเป็น risk ratio เรื่อง family และ link สอนไว้เต็ม ๆ ที่ Link และ Family: ตัวหนึ่งกำหนดมาตรวัดผล อีกตัวกำหนดค่าคลาดเคลื่อนมาตรฐาน

ความเสี่ยงต้องไม่เกิน 1 แต่เมื่อ outcome พบบ่อย log link อาจดันความเสี่ยงที่ทำนายของผู้ป่วยบางคนให้เกิน 1 การ fit จึงไม่ converge หมายความว่าการค้นหาค่าประมาณที่ดีที่สุดหยุดลงก่อนจะหาเจอ และ Stata ไม่หยุดด้วย error แต่ยังพิมพ์ตารางออกมาตามปกติ

มีสัญญาณสามอย่างที่บอกว่าล้มเหลว บรรทัด convergence not achieved อยู่เหนือตาราง standard error ในแถว Yes เป็นจุด และท้ายตารางเขียนว่า Warning: Convergence not achieved. จากนั้น display e(converged) พิมพ์ 0 แทนที่จะเป็น 1 ตัวเลขในแถวนั้นจึงไม่ใช่ผลลัพธ์

โค้ด Stata 02_fit_models.do (บรรทัด 58-70 จาก 187)
* ---- 5. Binary Y, measure = risk ratio: log-binomial GLM, then modified Poisson ----
* Log-binomial first. If it fails (no convergence), the failure is shown and the run goes on.
* nolog hides up to 300 iteration lines; the table footer still prints "Convergence not achieved".
* Watch out: Stata does NOT stop with an error here. Read the footer and e(converged) (1 = yes).
* ลอง log-binomial ก่อน ถ้าไม่ converge จะแสดงให้เห็นแล้วรันต่อ nolog ซ่อนบรรทัด iteration
* ระวัง: Stata ไม่หยุดด้วย error ต้องอ่านท้ายตารางและ e(converged) (1 = converge)
capture noisily glm icu i.diabetes c.age i.female, family(binomial) link(log) eform nolog
local return_code_log_binomial = _rc
display as text "log-binomial GLM: return code = `return_code_log_binomial' (0 = it ran)"
if `return_code_log_binomial' == 0 display as text "log-binomial GLM: e(converged) = " e(converged)
* line to read (only if e(converged) = 1): Diabetes Yes, Risk ratio [95% conf. interval]
* In this cohort it does NOT converge (Stata also warns of inadmissible mean estimates, i.e. a fitted
* risk above 1 for some patients), so the risk ratio is read from the next model.
ผลลัพธ์จากการรัน 02_fit_models.log
. capture noisily 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.

. local return_code_log_binomial = _rc

. display as text "log-binomial GLM: return code = `return_code_log_binomial' (
> 0 = it ran)"
log-binomial GLM: return code = 0 (0 = it ran)

. if `return_code_log_binomial' == 0 display as text "log-binomial GLM: e(conve
> rged) = " e(converged)
log-binomial GLM: e(converged) = 0
สัญญาณล้มเหลวสามอย่าง: บรรทัดแรก จุดในแถว Yes และคำเตือนท้ายตาราง ส่วน e(converged) = 0 ด้านล่างยืนยันอีกครั้ง

risk ratio: modified Poisson

เมื่อ log-binomial ล้มเหลว ให้ fit Poisson model ที่ใช้ log link แม้ outcome จะมีแค่เข้าหรือไม่เข้า model นี้เป็นแค่เครื่องมือทำงาน (working model) มันให้ risk ratio ที่ถูกต้อง แต่ standard error ตามปกติของมันผิดสำหรับ outcome แบบเข้าหรือไม่เข้า จึงต้องสั่งให้ Stata คำนวณ robust standard error ด้วย vce(robust) ซึ่งไม่เชื่อสูตรความแปรปรวนของ Poisson การใช้สองอย่างนี้คู่กันเรียกว่า modified Poisson regression และไม่ใช่ log-binomial

Stata ตั้งชื่อคอลัมน์ว่า IRR แต่สำหรับ outcome แบบเข้าหรือไม่เข้า ค่านี้คือ risk ratio คือ 1.413388 (95% CI 1.166529 ถึง 1.712487) พูดเป็นภาษาคลินิกได้ว่า เมื่ออายุและเพศเท่ากัน ผู้ป่วยเบาหวานมีความเสี่ยงที่จะเข้า ICU ประมาณ 1.41 เท่า

odds ratio หลังปรับ 1.65 อยู่สูงกว่า 1.41 นี้พอสมควร เมื่อผู้ป่วย 25.75% เข้า ICU การอ่าน odds ratio ราวกับเป็น risk ratio จะทำให้ผลดูมากเกินจริง risk ratio สำหรับ outcome ที่พบบ่อยสอนไว้ที่ หา Risk Ratio เมื่อผลลัพธ์พบบ่อย: ลำดับขั้นถอยลงเมื่อ Log-Binomial ชนกำแพง

โค้ด Stata 02_fit_models.do (บรรทัด 72-77 จาก 187)
* Modified Poisson: a Poisson working model with a robust variance (NOT log-binomial).
* It is the fallback when log-binomial fails; it is shown always so the two can be compared.
* modified Poisson คือ Poisson working model กับ robust variance (ไม่ใช่ log-binomial)
glm icu i.diabetes c.age i.female, family(poisson) link(log) vce(robust) eform
estimates store model_icu_modified_poisson
* line to read: Diabetes Yes, IRR column = risk ratio here [95% conf. interval]
ผลลัพธ์จากการรัน 02_fit_models.log
. glm icu i.diabetes c.age i.female, family(poisson) link(log) vce(robust) efor
> m

Iteration 0:  Log pseudolikelihood = -722.66696
Iteration 1:  Log pseudolikelihood = -706.88398
Iteration 2:  Log pseudolikelihood = -706.87128
Iteration 3:  Log pseudolikelihood = -706.87128

Generalized linear models                         Number of obs   =      1,200
Optimization     : ML                             Residual df     =      1,196
                                                  Scale parameter =          1
Deviance         =  795.7425607                   (1/df) Deviance =   .6653366
Pearson          =  886.4595257                   (1/df) Pearson  =   .7411869

Variance function: V(u) = u                       [Poisson]
Link function    : g(u) = ln(u)                   [Log]

                                                  AIC             =   1.184785
Log pseudolikelihood = -706.8712804               BIC             =  -7683.989

------------------------------------------------------------------------------
             |               Robust
         icu |        IRR   std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.413388    .138426     3.53   0.000     1.166529    1.712487
         age |   1.024199   .0040683     6.02   0.000     1.016257    1.032204
             |
      female |
     Female  |   .7234893   .0732169    -3.20   0.001     .5933225     .882213
       _cons |   .0496235   .0144917   -10.28   0.000     .0279968    .0879562
------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate.
คอลัมน์เขียนว่า IRR แต่สำหรับ outcome ที่มีแค่เข้าหรือไม่เข้า แถว Yes คือ 1.413388 เป็น risk ratio หลังปรับ

risk difference: identity link

risk difference ได้มาจาก binomial model ที่ใช้ identity link ซึ่งบวกตัวแปรต่าง ๆ บนความเสี่ยงโดยตรง coefficient จึงเป็นผลต่างของความเสี่ยง เขียนในรูปสัดส่วน

model นี้ converge แล้ว e(converged) จึงเป็น 1 และพิมพ์ .0937788 (95% CI .0352486 ถึง .152309) พูดเป็นภาษาคลินิกได้ว่า เมื่ออายุและเพศเท่ากัน ในผู้ป่วยเบาหวานทุก 100 คน มีคนเข้า ICU เพิ่มขึ้นประมาณ 9.4 คน (95% CI 3.5 ถึง 15.2 คนต่อ 100 คน)

ถ้า identity link ล้มเหลว ให้ใช้ linear probability model คือ regress บน outcome ที่เป็น 0 หรือ 1 คู่กับ vce(robust) ในข้อมูลนี้ได้ .0971603 ใกล้กับคำตอบของ binomial model

โค้ด Stata 02_fit_models.do (บรรทัด 79-92 จาก 187)
* ---- 6. Binary Y, measure = risk difference: identity-link binomial GLM, then LPM ----
* Identity-binomial first. If it fails, the error is shown and the run goes on.
* ลอง binomial identity link ก่อน ถ้าไม่ converge จะแสดง error แล้วรันต่อ
capture noisily glm icu i.diabetes c.age i.female, family(binomial) link(identity)
local return_code_identity_binomial = _rc
display as text "identity-binomial GLM: return code = `return_code_identity_binomial' (0 = it ran)"
if `return_code_identity_binomial' == 0 display as text "identity-binomial GLM: e(converged) = " e(converged)
* line to read (only if e(converged) = 1): Diabetes Yes, Coefficient = risk difference (proportion) [95% CI]

* Linear probability model with robust SE: the fallback for the risk difference, shown always.
* linear probability model กับ robust SE เป็นทางสำรองของ risk difference แสดงทุกครั้ง
regress icu i.diabetes c.age i.female, vce(robust)
estimates store model_icu_linear_prob
* line to read: Diabetes Yes, Coefficient = risk difference (proportion) [95% CI]
ผลลัพธ์จากการรัน 02_fit_models.log
------------------------------------------------------------------------------
             |                 OIM
         icu | Coefficient  std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   .0937788   .0298629     3.14   0.002     .0352486     .152309
         age |   .0056011   .0008977     6.24   0.000     .0038416    .0073607
             |
      female |
     Female  |  -.0693855   .0238538    -2.91   0.004    -.1161381   -.0226329
       _cons |  -.1171567   .0612593    -1.91   0.056    -.2372226    .0029093
------------------------------------------------------------------------------
Coefficients are the risk differences.

. local return_code_identity_binomial = _rc

. display as text "identity-binomial GLM: return code = `return_code_identity_b
> inomial' (0 = it ran)"
identity-binomial GLM: return code = 0 (0 = it ran)

. if `return_code_identity_binomial' == 0 display as text "identity-binomial GL
> M: e(converged) = " e(converged)
identity-binomial GLM: e(converged) = 1

. * line to read (only if e(converged) = 1): Diabetes Yes, Coefficient = risk d
> ifference (proportion) [95% CI]
.
. * Linear probability model with robust SE: the fallback for the risk differen
> ce, shown always.
. * linear probability model กับ robust SE เป็นทางสำรองของ risk difference แสดง
> ทุกครั้ง
. regress icu i.diabetes c.age i.female, vce(robust)

Linear regression                               Number of obs     =      1,200
                                                F(3, 1196)        =      20.90
                                                Prob > F          =     0.0000
                                                R-squared         =     0.0480
                                                Root MSE          =     .42736

------------------------------------------------------------------------------
             |               Robust
         icu | Coefficient  std. err.      t    P>|t|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   .0971603   .0295794     3.28   0.001      .039127    .1551935
         age |   .0059742   .0009909     6.03   0.000     .0040301    .0079184
             |
      female |
     Female  |  -.0814194   .0246059    -3.31   0.001     -.129695   -.0331438
       _cons |  -.1392389   .0658511    -2.11   0.035    -.2684354   -.0100424
------------------------------------------------------------------------------
model ที่ใช้ identity link converge แล้ว e(converged) = 1 และแถว Yes คือ .0937788 เป็น risk difference หลังปรับ ส่วน linear probability model ด้านล่างให้ .0971603

ระดับความรุนแรง: cumulative odds ratio

ความรุนแรงมีสามระดับที่เรียงลำดับกันได้ คือ mild (0) moderate (1) และ severe (2) สเกลนี้ตัดได้สองจุด คือ moderate หรือ severe เทียบกับ mild และ severe เทียบกับ mild หรือ moderate

ologit fit ทั้งสองจุดตัดพร้อมกัน และสมมติว่าเบาหวานคูณ odds ด้วยตัวคูณเดียวกันทุกจุดตัด คือ odds ที่จะเป็น moderate หรือ severe แทนที่จะเป็น mild และ odds ที่จะเป็น severe แทนที่จะเป็น moderate หรือ mild ต่างเพิ่มขึ้นด้วยตัวคูณตัวเดียวกันนั้น ตัวคูณที่ใช้ร่วมกันนี้เรียกว่า cumulative odds ratio Stata เขียน model ว่า logit P(Y > k) = xb ลบด้วย cut_k โดย xb คือส่วนที่ขึ้นกับเบาหวาน อายุ และเพศ ส่วน cut_k คือค่าเกณฑ์ของจุดตัดที่ k

Stata พิมพ์ 1.898396 (95% CI 1.490758 ถึง 2.417501) พูดเป็นภาษาคลินิกได้ว่า เมื่ออายุและเพศเท่ากัน ผู้ป่วยเบาหวานมี odds ที่จะอยู่ในระดับที่แย่กว่าประมาณ 1.90 เท่า ไม่ว่าจุดตัดไหน ส่วนแถว /cut1 (2.638261) และ /cut2 (4.161577) เป็นค่าเกณฑ์ระหว่างระดับ ไม่ใช่ผลของตัวแปร

P(Y > k) แปลว่าระดับที่แย่กว่าได้ก็เพราะรหัสที่สูงกว่าคือระดับที่แย่กว่าในข้อมูลนี้ ถ้า outcome เรียงกลับด้านให้ recode ก่อน การเปรียบเทียบ ordinal model กับ multinomial model สอนไว้เต็ม ๆ ที่ Multinomial vs Ordinal Logistic Regression [mlogit & ologit]: Choosing the Right Model for Categorical Outcomes (อ่านได้เฉพาะภาษาอังกฤษ)

โค้ด Stata 02_fit_models.do (บรรทัด 94-99 จาก 187)
* ---- 7. Ordered Y (severity): ordinal logistic regression ----
* exp(b) = cumulative odds ratio: odds of a higher grade vs that grade or lower, same at every split.
* exp(b) = cumulative odds ratio: odds ของระดับที่สูงกว่าเทียบกับระดับนั้นหรือต่ำกว่า เท่ากันทุกจุดตัด
ologit severity i.diabetes c.age i.female, or
estimates store model_severity_ologit
* line to read: Diabetes Yes, Odds ratio [95% CI]; /cut1 and /cut2 are thresholds, not effects
ผลลัพธ์จากการรัน 02_fit_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.
odds ratio ของเบาหวานมีค่าเดียวคือ 1.898396 ใช้ร่วมกันทั้งสองจุดตัด ส่วน /cut1 และ /cut2 เป็นค่าเกณฑ์ ไม่ใช่ผลของตัวแปร

cumulative odds ratio แปลว่าอะไรกับผู้ป่วย: margins

cumulative odds ratio 1.90 อธิบายข้างเตียงได้ยาก ความน่าจะเป็นที่ทำนายได้เข้าใจง่ายกว่า หลัง ologit คำสั่ง margins ตั้งให้ผู้ป่วยทุกคนไม่เป็นเบาหวานก่อน แล้วจึงตั้งให้ทุกคนเป็นเบาหวาน โดยผู้ป่วยแต่ละคนคงอายุและเพศของตัวเองไว้ แล้วเฉลี่ยความน่าจะเป็นที่ทำนายได้ของแต่ละระดับจากผู้ป่วยทั้ง 1,200 คน

อ่านแถวทีละคู่ mild (1#) ได้ .5720471 เมื่อไม่เป็นเบาหวาน และ .4190982 เมื่อเป็น moderate (2#) ได้ .2822321 และ .3391309 ส่วน severe (3#) ได้ .1457208 และ .241771

พูดเป็นภาษาคลินิกได้ว่า เมื่อเป็นเบาหวาน สัดส่วนที่ทำนายว่าเป็น mild ลดลงจาก 57.2% เหลือ 41.9% และสัดส่วนที่ทำนายว่าเป็น severe เพิ่มจาก 14.6% เป็น 24.2%

โค้ด Stata 02_fit_models.do (บรรทัด 101-104 จาก 187)
* Predicted probability of each grade, diabetes No vs Yes (age and sex as observed).
* ความน่าจะเป็นของแต่ละระดับ เบาหวาน No เทียบ Yes (อายุและเพศตามข้อมูลจริง)
margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))
* lines to read: _predict 1 = Mild, 2 = Moderate, 3 = Severe; each row No / Yes
ผลลัพธ์จากการรัน 02_fit_models.log
. margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))

Predictive margins                                       Number of obs = 1,200
Model VCE: OIM

1._predict: Pr(severity==0), predict(outcome(0))
2._predict: Pr(severity==1), predict(outcome(1))
3._predict: Pr(severity==2), predict(outcome(2))

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    _predict#|
    diabetes |
       1#No  |   .5720471    .016309    35.08   0.000     .5400821    .6040121
      1#Yes  |   .4190982    .025041    16.74   0.000     .3700187    .4681777
       2#No  |   .2822321   .0131492    21.46   0.000     .2564601     .308004
      2#Yes  |   .3391309   .0158437    21.40   0.000     .3080778    .3701839
       3#No  |   .1457208   .0108448    13.44   0.000     .1244654    .1669762
      3#Yes  |    .241771   .0198377    12.19   0.000     .2028897    .2806522
------------------------------------------------------------------------------
อ่านแถวทีละคู่ No แล้ว Yes: 1# คือ mild 2# คือ moderate และ 3# คือ severe คอลัมน์ Margin คือสัดส่วนที่ทำนายได้

logit แยกสองตัววางข้าง ologit ตัวเดียว

ค่า 1.90 ตัวเดียวสมมติว่าทั้งสองจุดตัดใช้ odds ratio ร่วมกัน วิธีดูอย่างเร็วคือ fit แต่ละจุดตัดเป็น logit แยกกัน moderate หรือ severe เทียบกับ mild ได้ 2.049064 ส่วน severe เทียบกับที่เหลือได้ 1.650193 และ 1.90 อยู่ระหว่างสองค่านี้ สองค่านี้ห่างกันได้แค่ไหนเป็นเรื่องของการตรวจ model ซึ่งอยู่ใน ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน

โค้ด Stata 02_fit_models.do (บรรทัด 106-117 จาก 187)
* The two splits as separate logits: the single ologit OR should sit near both.
* แยกเป็น logit สองตัวตามจุดตัด OR เดียวของ ologit ควรอยู่ใกล้ทั้งสองค่า
generate severity_above_mild = severity >= 1 if !missing(severity)       // moderate or severe vs mild
generate severity_above_moderate = severity == 2 if !missing(severity)   // severe vs mild or moderate
label variable severity_above_mild "Severity moderate or severe (Y > 0)"
label variable severity_above_moderate "Severity severe (Y > 1)"
logit severity_above_mild i.diabetes c.age i.female, or
estimates store model_severity_split_1
* line to read: Diabetes Yes, Odds ratio for Y > 0
logit severity_above_moderate i.diabetes c.age i.female, or
estimates store model_severity_split_2
* line to read: Diabetes Yes, Odds ratio for Y > 1
ผลลัพธ์จากการรัน 02_fit_models.log
------------------------------------------------------------------------------
severity_a~d | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   2.049064   .2775216     5.30   0.000     1.571341    2.672027
         age |   1.036067   .0054689     6.71   0.000     1.025403    1.046841
             |
      female |
     Female  |   1.094906   .1322875     0.75   0.453     .8640399    1.387457
       _cons |   .0631488   .0232498    -7.50   0.000     .0306884     .129944
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. estimates store model_severity_split_1

. * line to read: Diabetes Yes, Odds ratio for Y > 0
. logit severity_above_moderate i.diabetes c.age i.female, or

Iteration 0:  Log likelihood = -554.91824
Iteration 1:  Log likelihood = -539.90815
Iteration 2:  Log likelihood = -539.59871
Iteration 3:  Log likelihood = -539.59856
Iteration 4:  Log likelihood = -539.59856

Logistic regression                                     Number of obs =  1,200
                                                        LR chi2(3)    =  30.64
                                                        Prob > chi2   = 0.0000
Log likelihood = -539.59856                             Pseudo R2     = 0.0276

------------------------------------------------------------------------------
severity_a~e | Odds ratio   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.650193   .2683054     3.08   0.002     1.199879    2.269509
แต่ละจุดตัดมี odds ratio ของตัวเอง: 2.049064 สำหรับ moderate หรือ severe เทียบกับ mild และ 1.650193 สำหรับ severe เทียบกับที่เหลือ

ปลายทางเมื่อจำหน่าย: relative risk ratio

ปลายทางเมื่อจำหน่ายมีสามกลุ่มที่ไม่มีลำดับ คือกลับบ้าน (home 0) หน่วยฟื้นฟู (rehabilitation unit 1) และสถานดูแลระยะยาว (nursing home 2) คำสั่ง mlogit ใช้กลุ่มหนึ่งเป็น base แล้ว fit สมการหนึ่งสมการให้แต่ละกลุ่มที่เหลือเทียบกับ base ทั้งหมดอยู่ใน model เดียว

ให้เขียน base ด้วยรหัสตัวเลข คือ baseoutcome(0) ส่วน option rrr พิมพ์ exp(b) ซึ่งเรียกว่า relative risk ratio คือตัวคูณที่อัตราส่วน P(nursing home) / P(home) เปลี่ยนไปเมื่อเป็นเบาหวาน ค่านี้ไม่ใช่ความเสี่ยงที่จะไปสถานดูแลระยะยาว และไม่ใช่ risk ratio ของปลายทางนั้น

Stata พิมพ์ 2.699679 สำหรับ nursing home (95% CI 1.868359 ถึง 3.900892) และ 1.191056 สำหรับ rehabilitation (95% CI .8335177 ถึง 1.701961) พูดเป็นภาษาคลินิกได้ว่า เมื่ออายุและเพศเท่ากัน เบาหวานทำให้อัตราส่วนสถานดูแลระยะยาวต่อบ้านเพิ่มขึ้นประมาณ 2.70 เท่า ส่วนอัตราส่วนของหน่วยฟื้นฟูเปลี่ยนไป 1.19 เท่า และช่วงความเชื่อมั่นครอบคลุม 1

โค้ด Stata 02_fit_models.do (บรรทัด 119-124 จาก 187)
* ---- 8. Unordered Y (discharge destination): multinomial logistic regression ----
* exp(b) = relative risk ratio: the factor by which P(Y=j)/P(Y=home) changes with diabetes.
* exp(b) = relative risk ratio: ตัวคูณของ P(Y=j)/P(Y=บ้าน) เมื่อเป็นเบาหวาน
mlogit dispo i.diabetes c.age i.female, baseoutcome(0) rrr
estimates store model_dispo_mlogit
* lines to read: Diabetes Yes in the Rehabilitation unit block and in the Nursing home block
ผลลัพธ์จากการรัน 02_fit_models.log
. mlogit dispo i.diabetes c.age i.female, baseoutcome(0) rrr

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 |        RRR   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
Home         |  (base outcome)
-------------+----------------------------------------------------------------
Rehabilita~t |
    diabetes |
        Yes  |   1.191056   .2169103     0.96   0.337     .8335177    1.701961
         age |    1.02692   .0073379     3.72   0.000     1.012638    1.041403
             |
      female |
     Female  |   1.140268    .184385     0.81   0.417     .8305481    1.565485
       _cons |    .033158   .0166743    -6.77   0.000     .0123749    .0888457
-------------+----------------------------------------------------------------
Nursing_home |
    diabetes |
        Yes  |   2.699679   .5069876     5.29   0.000     1.868359    3.900892
         age |   1.077819   .0095191     8.49   0.000     1.059322    1.096638
             |
      female |
     Female  |   .8830964   .1654336    -0.66   0.507     .6117154    1.274873
       _cons |   .0006555   .0004381   -10.97   0.000     .0001769    .0024291
------------------------------------------------------------------------------
Note: _cons estimates baseline relative risk for each outcome.
Home เป็น base ให้อ่านแถว Yes ในส่วน Rehabilitation คือ 1.191056 และในส่วน Nursing_home คือ 2.699679

ความน่าจะเป็นหลัง mlogit: margins

เพราะ relative risk ratio เปรียบเทียบสองกลุ่มพร้อมกัน มันจึงอาจทำให้เข้าใจผิดเกี่ยวกับกลุ่มใดกลุ่มหนึ่งได้ คำสั่ง margins ชุดเดิมให้ความน่าจะเป็นที่ทำนายได้ของแต่ละปลายทาง กลับบ้านลดลงจาก .7430646 เหลือ .6354724 และสถานดูแลระยะยาวเพิ่มจาก .0967852 เป็น .2057105 ส่วนหน่วยฟื้นฟูแทบไม่ขยับ คือ .1601502 และ .1588171

ดังนั้นอัตราส่วนของหน่วยฟื้นฟู 1.19 เพิ่มขึ้นเพราะกลุ่มกลับบ้านซึ่งเป็น base หดลง ไม่ใช่เพราะมีผู้ป่วยไปหน่วยฟื้นฟูมากขึ้น พูดเป็นภาษาคลินิกได้ว่า เมื่อเป็นเบาหวาน ผู้ป่วยที่ทำนายว่าจะไปสถานดูแลระยะยาวมีประมาณ 20.6% แทนที่จะเป็น 9.7% และที่ได้กลับบ้านมี 63.5% แทนที่จะเป็น 74.3%

โค้ด Stata 02_fit_models.do (บรรทัด 126-129 จาก 187)
* Predicted probability of each destination, diabetes No vs Yes.
* ความน่าจะเป็นของแต่ละปลายทาง เบาหวาน No เทียบ Yes
margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))
* lines to read: _predict 1 = Home, 2 = Rehabilitation unit, 3 = Nursing home
ผลลัพธ์จากการรัน 02_fit_models.log
. margins diabetes, predict(outcome(0)) predict(outcome(1)) predict(outcome(2))

Predictive margins                                       Number of obs = 1,200
Model VCE: OIM

1._predict: Pr(dispo==Home), predict(outcome(0))
2._predict: Pr(dispo==Rehabilitation_unit), predict(outcome(1))
3._predict: Pr(dispo==Nursing_home), predict(outcome(2))

------------------------------------------------------------------------------
             |            Delta-method
             |     Margin   std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    _predict#|
    diabetes |
       1#No  |   .7430646   .0145694    51.00   0.000     .7145091    .7716201
      1#Yes  |   .6354724   .0252601    25.16   0.000     .5859636    .6849812
       2#No  |   .1601502   .0124594    12.85   0.000     .1357302    .1845703
      2#Yes  |   .1588171   .0200992     7.90   0.000     .1194235    .1982107
       3#No  |   .0967852   .0099076     9.77   0.000     .0773666    .1162037
      3#Yes  |   .2057105   .0205245    10.02   0.000     .1654833    .2459377
------------------------------------------------------------------------------
1# คือ home 2# คือ rehabilitation unit และ 3# คือ nursing home ให้เทียบ No กับ Yes ในแต่ละคู่

กลุ่มไหนเป็น base

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

โค้ด Stata 02_fit_models.do (บรรทัด 131-145 จาก 187)
* Without baseoutcome(): Stata picks the most frequent category as the base.
* ถ้าไม่เขียน baseoutcome() Stata ใช้กลุ่มที่พบบ่อยที่สุดเป็น base
mlogit dispo i.diabetes c.age i.female
display as text "base outcome chosen by Stata, e(baseout) = " e(baseout)
tabulate dispo

* Here Home is both the lowest code and the most frequent, so the two rules agree.
* Give Home the highest code (2) and fit again: the default base follows the frequency.
* ให้ Home เป็นรหัสสูงสุด (2) แล้ว fit ใหม่ base ที่ Stata เลือกตามความถี่ ไม่ใช่ตามรหัสต่ำสุด
recode dispo (0 = 2) (1 = 0) (2 = 1), generate(dispo_home_coded_2)
label define dispo_home_coded_2 0 "Rehabilitation unit" 1 "Nursing home" 2 "Home"
label values dispo_home_coded_2 dispo_home_coded_2
tabulate dispo_home_coded_2
quietly mlogit dispo_home_coded_2 i.diabetes c.age i.female
display as text "home coded 2: base outcome chosen by Stata, e(baseout) = " e(baseout)
ผลลัพธ์จากการรัน 02_fit_models.log
. display as text "base outcome chosen by Stata, e(baseout) = " e(baseout)
base outcome chosen by Stata, e(baseout) = 0

. tabulate dispo

          Discharge |
        destination |
        (unordered) |      Freq.     Percent        Cum.
--------------------+-----------------------------------
               Home |        854       71.17       71.17
Rehabilitation unit |        191       15.92       87.08
       Nursing home |        155       12.92      100.00
--------------------+-----------------------------------
              Total |      1,200      100.00

.
. * Here Home is both the lowest code and the most frequent, so the two rules a
> gree.
. * Give Home the highest code (2) and fit again: the default base follows the
> frequency.
. * ให้ Home เป็นรหัสสูงสุด (2) แล้ว fit ใหม่ base ที่ Stata เลือกตามความถี่ ไม
> ่ใช่ตามรหัสต่ำสุด
. recode dispo (0 = 2) (1 = 0) (2 = 1), generate(dispo_home_coded_2)
(1,200 differences between dispo and dispo_home_coded_2)

. label define dispo_home_coded_2 0 "Rehabilitation unit" 1 "Nursing home" 2 "H
> ome"

. label values dispo_home_coded_2 dispo_home_coded_2

. tabulate dispo_home_coded_2

    RECODE of dispo |
         (Discharge |
        destination |
       (unordered)) |      Freq.     Percent        Cum.
--------------------+-----------------------------------
Rehabilitation unit |        191       15.92       15.92
       Nursing home |        155       12.92       28.83
               Home |        854       71.17      100.00
--------------------+-----------------------------------
              Total |      1,200      100.00

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

. display as text "home coded 2: base outcome chosen by Stata, e(baseout) = " e
> (baseout)
home coded 2: base outcome chosen by Stata, e(baseout) = 2
Home เป็นกลุ่มที่พบบ่อยที่สุด Stata จึงเลือกเป็น base ไม่ว่ารหัสของมันจะเป็น 0 หรือ 2

การกลับมานอนซ้ำ: จำนวนครั้งและอัตรา

การกลับมานอนซ้ำนับเป็นจำนวนครั้งต่อผู้ป่วย คำสั่ง poisson สร้าง model ให้กับ log ของจำนวนครั้งที่คาดไว้ และ option irr พิมพ์ exp(b) ซึ่งเรียกว่า incidence rate ratio Stata พิมพ์ 1.524033 (95% CI 1.302227 ถึง 1.783619) พูดเป็นภาษาคลินิกได้ว่า เมื่ออายุและเพศเท่ากัน ผู้ป่วยเบาหวานกลับมานอนซ้ำมากกว่าประมาณ 1.52 เท่า แต่ตัวเลขนี้ยังไม่คิดว่าผู้ป่วยถูกติดตามนานไม่เท่ากัน อัตราต่อ person-year ในหัวข้อถัดไปจึงเป็นการเปรียบเทียบที่ยุติธรรม

Poisson model สมมติว่าความแปรปรวนเท่ากับค่าเฉลี่ย เมื่อจำนวนครั้งกระจายมากกว่านั้น nbreg จะเพิ่ม dispersion parameter ชื่อ alpha ที่วัดการกระจายส่วนเกิน ในข้อมูลนี้ nbreg ให้ incidence rate ratio 1.513345

alpha ของมัน (model จำนวนครั้ง ไม่ได้ใส่ exposure(fu_years)) เท่ากับ 1.08104 ถ้า alpha = 0 จะแปลว่าไม่มีการกระจายส่วนเกิน และการทดสอบ alpha = 0 ของ Stata ปฏิเสธข้อนั้น (chibar2(01) = 126.13, P น้อยกว่า 0.001) จำนวนครั้งในข้อมูลนี้จึงกระจายมากกว่าที่ Poisson ยอมให้ แต่ผลของเบาหวานแทบไม่ขยับ ส่วนจะทำอย่างไรกับการกระจายส่วนเกินนี้อยู่ที่ ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน

โค้ด Stata 02_fit_models.do (บรรทัด 147-152 จาก 187)
* ---- 9. Count Y (readmissions): Poisson, then negative binomial ----
* exp(b) = incidence rate ratio of readmissions per patient.
* exp(b) = incidence rate ratio ของจำนวนครั้งการกลับมานอนซ้ำต่อผู้ป่วย
poisson readmit_n i.diabetes c.age i.female, irr
estimates store model_readmit_poisson
* line to read: Diabetes Yes, IRR [95% CI]
ผลลัพธ์จากการรัน 02_fit_models.log
. poisson readmit_n i.diabetes c.age i.female, irr

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

Poisson regression                                      Number of obs =  1,200
                                                        LR chi2(3)    =  40.36
                                                        Prob > chi2   = 0.0000
Log likelihood = -1276.6788                             Pseudo R2     = 0.0156

------------------------------------------------------------------------------
   readmit_n |        IRR   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.524033   .1223012     5.25   0.000     1.302227    1.783619
         age |   1.009459   .0033395     2.85   0.004     1.002934    1.016025
             |
      female |
     Female  |   1.106422   .0853719     1.31   0.190     .9511338    1.287063
       _cons |   .2462585   .0575233    -6.00   0.000     .1557973    .3892445
------------------------------------------------------------------------------
Note: _cons estimates baseline incidence rate.
แถว Yes คือ 1.524033: กลับมานอนซ้ำมากกว่าประมาณ 1.52 เท่าเมื่ออายุและเพศเท่ากัน โดยยังไม่คิดระยะเวลาติดตาม
โค้ด Stata 02_fit_models.do (บรรทัด 153-155 จาก 187)
nbreg readmit_n i.diabetes c.age i.female, irr
estimates store model_readmit_nbreg
* lines to read: Diabetes Yes, IRR [95% CI]; /lnalpha and alpha; LR test of alpha=0
ผลลัพธ์จากการรัน 02_fit_models.log
Negative binomial regression                            Number of obs =  1,200
                                                        LR chi2(3)    =  23.64
Dispersion: mean                                        Prob > chi2   = 0.0000
Log likelihood = -1213.6133                             Pseudo R2     = 0.0096

------------------------------------------------------------------------------
   readmit_n |        IRR   Std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.513345   .1599163     3.92   0.000     1.230243    1.861594
         age |   1.009042   .0042533     2.14   0.033      1.00074    1.017413
             |
      female |
     Female  |   1.107698      .1093     1.04   0.300     .9129155    1.344039
       _cons |   .2537936    .074885    -4.65   0.000     .1423387    .4525206
-------------+----------------------------------------------------------------
    /lnalpha |   .0779231   .1413004                     -.1990205    .3548668
-------------+----------------------------------------------------------------
       alpha |    1.08104   .1527513                      .8195331    1.425991
------------------------------------------------------------------------------
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) = 126.13               Prob >= chibar2 = 0.000
incidence rate ratio แทบไม่ขยับคือ 1.513345 ส่วน alpha และ LR test ของ alpha=0 บอกการกระจายส่วนเกิน

ต่อ person-year: option exposure()

ผู้ป่วยถูกติดตามนานไม่เท่ากัน การเปรียบเทียบที่ยุติธรรมจึงเป็นจำนวนครั้งที่กลับมานอนซ้ำต่อ person-year option exposure(fu_years) ใส่ log ของระยะเวลาติดตามของผู้ป่วยแต่ละคนเข้าไปโดยตรึง coefficient ไว้ที่ 1 พจน์ที่ตรึงไว้นี้เรียกว่า offset ซึ่งเปลี่ยนจำนวนครั้งให้เป็นอัตรา และ output จะกำกับด้วยคำว่า (exposure)

Stata พิมพ์ 1.577806 (95% CI 1.347871 ถึง 1.846965) พูดเป็นภาษาคลินิกได้ว่า ผู้ป่วยเบาหวานกลับมานอนซ้ำในอัตราต่อ person-year ประมาณ 1.58 เท่า ช่วงความเชื่อมั่นนี้สมมติว่าความแปรปรวนเท่ากับค่าเฉลี่ย แต่จำนวนครั้งในหัวข้อก่อนหน้ากระจายมากกว่านั้น

เวอร์ชัน nbreg ในช่องที่สองด้านล่างให้ 1.514983 (95% CI 1.241992 ถึง 1.847977) ซึ่งช่วงกว้างกว่า ควรรายงานช่วงไหนอธิบายไว้ในบทที่สาม ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน เรื่องอัตราและ offset สอนไว้ที่ Rates, Poisson Regression, and the Missing Lambda Backbone (อ่านได้เฉพาะภาษาอังกฤษ)

โค้ด Stata 02_fit_models.do (บรรทัด 157-162 จาก 187)
* ---- 10. Rate Y (readmissions per person-year): Poisson with exposure() ----
* exposure(fu_years) puts log follow-up in as an offset, so exp(b) = ratio of rates per person-year.
* exposure(fu_years) ใส่ log ของระยะติดตามเป็น offset exp(b) จึงเป็นอัตราส่วนของ rate ต่อ person-year
poisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr
estimates store model_readmit_rate_poisson
* line to read: Diabetes Yes, IRR [95% CI]; ln(fu_years) shown with (exposure)
ผลลัพธ์จากการรัน 02_fit_models.log
. 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.
ln(fu_years) มีคำว่า (exposure) กำกับ แถว Yes คือ 1.577806 จึงกลายเป็นอัตราส่วนของอัตราการกลับมานอนซ้ำต่อ person-year
โค้ด Stata 02_fit_models.do (บรรทัด 164-168 จาก 187)
* The same rate with a negative binomial model (the counts are overdispersed, see 03).
* rate เดียวกันด้วย negative binomial (count กระจายเกิน ดู 03)
nbreg readmit_n i.diabetes c.age i.female, exposure(fu_years) irr
estimates store model_readmit_rate_nbreg
* line to read: Diabetes Yes, IRR [95% CI]
ผลลัพธ์จากการรัน 02_fit_models.log
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
rate model แบบ negative binomial: แถว Yes คือ 1.514983 ใกล้กับค่า Poisson 1.577806 แต่ช่วงความเชื่อมั่น 1.241992 ถึง 1.847977 กว้างกว่า

เวลาจนเสียชีวิต: stset ก่อน แล้วจึง stcox

เวลาจนเสียชีวิตต้องใช้ข้อมูลสองอย่าง คือผู้ป่วยแต่ละคนถูกติดตามนานเท่าไร และการติดตามจบลงด้วยการเสียชีวิตหรือไม่ คำสั่ง stset time_d, failure(died) ประกาศทั้งสองอย่างเพียงครั้งเดียว แล้ว stcox จึงรับแค่ตัวแปรอิสระ การเขียน outcome ลงใน stcox เป็นความผิดพลาด

output ของ stset ยืนยันว่ามีผู้เสียชีวิต 222 คน ในเวลาเสี่ยงรวม 391,391 วัน Cox regression พิมพ์ hazard ratio 1.918519 (95% CI 1.46799 ถึง 2.507317) พูดเป็นภาษาคลินิกได้ว่า ณ เวลาใดก็ตามในหนึ่งปีหลังรับไว้ ผู้ป่วยเบาหวานเสียชีวิตในอัตราประมาณ 1.92 เท่าของผู้ป่วยที่ไม่เป็นเบาหวานซึ่งอายุและเพศเดียวกัน

Cox regression สอนไว้ที่ Cox Proportional Hazards Regression and Related Survival-Analysis Concepts (อ่านได้เฉพาะภาษาอังกฤษ) ส่วนการตรวจว่าอัตราส่วนนี้คงที่ตลอดเวลาหรือไม่อยู่ใน ตรวจ regression model: assumption, diagnostic และทางไปต่อเมื่อไม่ผ่าน

โค้ด Stata 02_fit_models.do (บรรทัด 170-176 จาก 187)
* ---- 11. Time-to-event Y (death within 365 days): Cox regression ----
* stset declares time and event once; stcox then takes only the covariates.
* stset บอกเวลาและเหตุการณ์ครั้งเดียว แล้ว stcox ใส่เฉพาะตัวแปรอิสระ
stset time_d, failure(died)
stcox i.diabetes c.age i.female
estimates store model_death_cox
* line to read: Diabetes Yes, Haz. ratio [95% CI]
ผลลัพธ์จากการรัน 02_fit_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
------------------------------------------------------------------------------
stset รายงาน failure 222 ราย แถว Yes ของ stcox คือ 1.918519 เป็น hazard ratio ของเบาหวาน

ผู้ป่วยจากโรงพยาบาลเดียวกัน: vce(cluster hospital) เปลี่ยนอะไร

ผู้ป่วย 1,200 คนมาจากโรงพยาบาล 12 แห่ง และผู้ป่วยในโรงพยาบาลเดียวกันใช้แพทย์ชุดเดียวกันและนโยบายรับเข้า ICU แบบเดียวกัน vce(cluster hospital) ใช้ model เดิม แต่คำนวณ standard error จากระดับโรงพยาบาลแทนผู้ป่วยรายคน

ลอง fit logit ของ ICU สองครั้ง ค่า odds ratio ยังคงเป็น 1.646897 standard error เพิ่มจาก .2387784 เป็น .2858684 ช่วงความเชื่อมั่นกว้างขึ้นจาก 1.239519 ถึง 2.188162 เป็น 1.171965 ถึง 2.314291 และ p-value ขยับจาก 0.001 เป็น 0.004

ตารางเล็กท้ายช่อง output วาง fit เดียวกันไว้บน log-odds scale ค่า b = 0.4989 ในทั้งสอง fit ขณะที่ standard error เปลี่ยนจาก 0.1450 เป็น 0.1736 standard error ของ odds ratio ก็คือตัวเลขนี้คูณด้วย odds ratio

พูดเป็นภาษาคลินิกได้ว่า ค่าประมาณไม่เปลี่ยน แต่เรามั่นใจในค่านั้นน้อยลง เมื่อมีโรงพยาบาลแค่ 12 แห่ง ตัว standard error แบบ cluster เองก็ยังหยาบอยู่ ควร cluster เมื่อไรสอนไว้ที่ ทำความเข้าใจ VCE: Robust Standard Error, Sandwich Estimator และ vce(cluster id)

โค้ด Stata 02_fit_models.do (บรรทัด 178-187 จาก 187)
* ---- 12. Clustered patients (hospital): plain SE next to cluster-robust SE ----
* Same logistic model twice; only the standard error changes, the OR stays the same.
* logistic model เดียวกันสองครั้ง เปลี่ยนแค่ standard error ค่า OR เท่าเดิม
logit icu i.diabetes c.age i.female, or
estimates store model_icu_logit_plain
logit icu i.diabetes c.age i.female, or vce(cluster hospital)
estimates store model_icu_logit_cluster
* side by side on the log-odds scale: b and SE for diabetes, plain vs cluster
* วางคู่กันบน log-odds scale: b และ SE ของเบาหวาน แบบธรรมดาเทียบ cluster
estimates table model_icu_logit_plain model_icu_logit_cluster, keep(1.diabetes) b(%9.4f) se(%9.4f)
ผลลัพธ์จากการรัน 02_fit_models.log
. logit icu i.diabetes c.age i.female, or vce(cluster hospital)

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

Logistic regression                                     Number of obs =  1,200
                                                        Wald chi2(3)  =  43.97
                                                        Prob > chi2   = 0.0000
Log pseudolikelihood = -655.09116                       Pseudo R2     = 0.0430

                              (Std. err. adjusted for 12 clusters in hospital)
------------------------------------------------------------------------------
             |               Robust
         icu | Odds ratio   std. err.      z    P>|z|     [95% conf. interval]
-------------+----------------------------------------------------------------
    diabetes |
        Yes  |   1.646897   .2858684     2.87   0.004     1.171965    2.314291
         age |    1.03403   .0069643     4.97   0.000      1.02047    1.047771
             |
      female |
     Female  |    .636516   .0679878    -4.23   0.000     .5162861    .7847442
       _cons |   .0356252   .0184391    -6.44   0.000     .0129177    .0982489
------------------------------------------------------------------------------
Note: _cons estimates baseline odds.

. estimates store model_icu_logit_cluster

. * side by side on the log-odds scale: b and SE for diabetes, plain vs cluster
. * วางคู่กันบน log-odds scale: b และ SE ของเบาหวาน แบบธรรมดาเทียบ cluster
. estimates table model_icu_logit_plain model_icu_logit_cluster, keep(1.diabete
> s) b(%9.4f) se(%9.4f)

--------------------------------------
    Variable | model_i~n   model_i~r
-------------+------------------------
    diabetes |
        Yes  |    0.4989      0.4989
             |    0.1450      0.1736
--------------------------------------
                          Legend: b/se
odds ratio เท่าเดิมคือ 1.646897 แต่ standard error ใหญ่ขึ้นเป็น .2858684 จาก cluster ของโรงพยาบาล 12 แห่ง ตารางด้านล่างวาง b และ SE ไว้คู่กัน

สรุป: จาก outcome ถึงประโยคเดียว

ทุกตัวเลขมาจากแถว Yes ของเบาหวานในผลการรันด้านบน ปรับด้วยอายุและเพศ ยกเว้นแถวที่เขียนว่าค่าดิบ
Outcomeคำสั่งตัวเลขที่ Stata พิมพ์ชื่อของตัวเลขพูดอย่างไร
วันนอนโรงพยาบาล (วัน)regress los i.diabetes c.age i.female1.436325ผลต่างของค่าเฉลี่ย (Coefficient)ผู้ป่วยเบาหวานนอนนานกว่าประมาณ 1.44 วัน
การเข้า ICU ค่าดิบcs icu diabetes, or.116849; 1.517813; 1.787558risk difference; risk ratio; odds ratioคำตอบสามแบบจากตารางเดียว ก่อนปรับ
การเข้า ICUlogit icu i.diabetes c.age i.female, or1.646897odds ratioodds ของการเข้า ICU ประมาณ 1.65 เท่า
การเข้า ICUglm icu i.diabetes c.age i.female, family(poisson) link(log) vce(robust) eform1.413388risk ratio (คอลัมน์เขียนว่า IRR)ความเสี่ยงที่จะเข้า ICU ประมาณ 1.41 เท่า
การเข้า ICUglm icu i.diabetes c.age i.female, family(binomial) link(identity).0937788risk differenceเข้า ICU เพิ่มขึ้นประมาณ 9.4 คนในผู้ป่วยทุก 100 คน
ระดับความรุนแรงologit severity i.diabetes c.age i.female, or1.898396cumulative odds ratioodds ที่จะอยู่ในระดับที่แย่กว่าประมาณ 1.90 เท่า ไม่ว่าจุดตัดไหน
ปลายทางเมื่อจำหน่ายmlogit dispo i.diabetes c.age i.female, baseoutcome(0) rrr2.699679 (nursing home)relative risk ratio เทียบกับ homeอัตราส่วนสถานดูแลระยะยาวต่อบ้านมากขึ้นประมาณ 2.70 เท่า
การกลับมานอนซ้ำ (จำนวนครั้ง)poisson readmit_n i.diabetes c.age i.female, irr1.524033incidence rate ratioกลับมานอนซ้ำมากกว่าประมาณ 1.52 เท่า โดยยังไม่คิดระยะเวลาติดตาม แถวอัตราด้านล่างเป็นการเปรียบเทียบที่ยุติธรรม
การกลับมานอนซ้ำต่อ person-yearpoisson readmit_n i.diabetes c.age i.female, exposure(fu_years) irr1.577806incidence rate ratio (อัตรา)อัตราการกลับมานอนซ้ำประมาณ 1.58 เท่า ช่วงความเชื่อมั่นสมมติว่าความแปรปรวนเท่ากับค่าเฉลี่ย ซึ่งไม่จริงในข้อมูลนี้ (ดู nbreg ด้านบน)
เสียชีวิตภายใน 365 วันstset time_d, failure(died) แล้วจึง stcox i.diabetes c.age i.female1.918519hazard ratioเสียชีวิตในอัตราประมาณ 1.92 เท่า ณ เวลาใดก็ตามในปีนั้น
การเข้า ICU โรงพยาบาล 12 แห่งlogit icu i.diabetes c.age i.female, or vce(cluster hospital)1.646897 (SE .2858684)odds ratio เท่าเดิม กับ cluster-robust standard errorค่าประมาณเท่าเดิม ช่วงความเชื่อมั่นกว้างขึ้น

คำสั่งที่รันไม่ผ่าน หรืออ่านผิดความหมาย

  • ใส่ comma ตัวที่สองก่อน option

    glm icu i.diabetes, family(binomial), eform มี comma สองตัว และ Stata จะไม่ยอมรันบรรทัดนี้

    วิธีแก้: เขียน comma ตัวเดียว แล้วตามด้วย option ทุกตัวคั่นด้วยเว้นวรรค เช่น glm icu i.diabetes c.age i.female, family(binomial) link(log) eform

  • เขียน outcome ลงใน stcox

    stcox ไม่รับ outcome เวลาและเหตุการณ์มาจาก stset ตัวแปรที่เขียนไว้ตัวแรกจึงถูกอ่านเป็นตัวแปรอิสระอีกตัวหนึ่ง

    วิธีแก้: รัน stset time_d, failure(died) ครั้งเดียว แล้วจึงรัน stcox i.diabetes c.age i.female

  • อ่าน family(nbinomial) ว่าเป็น model ของการกระจายส่วนเกิน

    glm ที่ใช้ family(nbinomial) ตรึงค่า dispersion ไว้ที่ 1 ถ้าไม่เขียน family(nbinomial ml) จึงไม่ได้ประมาณการกระจายส่วนเกิน

    วิธีแก้: ใช้ nbreg ซึ่งประมาณ alpha และทดสอบ alpha = 0 ให้

  • ไม่ระบุ base หรือใช้คำแทนรหัสของ base

    mlogit ที่ไม่มี baseoutcome() ใช้กลุ่มที่พบบ่อยที่สุดเป็น base และ base(reference) ไม่ใช่คำสั่งของ Stata

    วิธีแก้: เขียน baseoutcome(#) โดยใส่รหัสตัวเลขของกลุ่มที่ต้องการ

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

  1. Zou G. A modified Poisson regression approach to prospective studies with binary data. American Journal of Epidemiology 2004;159(7):702-706. https://doi.org/10.1093/aje/kwh090
  2. McCullagh P. Regression models for ordinal data. Journal of the Royal Statistical Society, Series B 1980;42(2):109-142. https://doi.org/10.1111/j.2517-6161.1980.tb01109.x
  3. Cox DR. Regression models and life-tables. Journal of the Royal Statistical Society, Series B 1972;34(2):187-220. https://doi.org/10.1111/j.2517-6161.1972.tb00899.x
  4. Long JS, Freese J. Regression Models for Categorical Dependent Variables Using Stata. 3rd edition. College Station, TX: Stata Press; 2014.

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

  • ทุก model ให้อ่านแถว Yes ใต้ diabetes แล้วอ่านหัวคอลัมน์ Stata บอกชื่อของตัวเลขไว้ให้แล้ว
  • ตาราง ICU ตารางเดียวให้คำตอบสามแบบ คือ risk difference .116849 risk ratio 1.517813 และ odds ratio 1.787558
  • log-binomial อาจล้มเหลวแบบเงียบ ๆ ให้มองหา convergence not achieved จุดในตำแหน่ง standard error และ e(converged) = 0 แล้วจึงใช้ modified Poisson
  • หลัง ologit และ mlogit ให้รัน margins เพราะ cumulative odds ratio 1.90 และ relative risk ratio 1.19 จะเข้าใจได้ก็ต่อเมื่อแปลงเป็นความน่าจะเป็นที่ทำนายได้
  • เขียน baseoutcome(#) ใช้ exposure() เมื่อต้องการอัตรา และ stset ก่อน stcox ส่วน vce(cluster) เปลี่ยน standard error ไม่ได้เปลี่ยนค่าประมาณ

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

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

ความคิดเห็น

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

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