top of page

Logistic Regression สำหรับข้อมูล Binary: ทำไมใช้ได้ แม้ Y มีแค่ 0 กับ 1

Updated: Jul 7

🔍 ปัญหาเริ่มต้น: “ถ้า Y มีแค่ 1 หรือ 0 แล้วจะวิเคราะห์ยังไง?”

หลายคนสงสัยว่า ถ้า Y มีแค่ “มีโรค” (1) หรือ “ไม่มีโรค” (0) จะสามารถวิเคราะห์ด้วย regression ได้หรือไม่ เพราะดูเหมือนไม่สามารถลากเส้นตรงแบบ linear regression ได้

คำตอบ: ใช้ Logistic Regression ได้ และเป็นวิธีหลักสำหรับข้อมูลลักษณะนี้

Logistic regression ใช้ในการวิเคราะห์ความสัมพันธ์ระหว่างตัวแปรอิสระ (X) กับ โอกาส (probability) ที่ Y = 1 เช่น โอกาสที่ผู้ป่วยจะเสียชีวิต, เกิดโรค, หรือมีผลลัพธ์เชิงลบใดๆ

🧠 หลักการของ Logistic Regression



🔢 ตัวอย่างคำสั่งใน Stata

logistic died age sex hypertension

หรือแบบ Generalized Linear Model:

glm died age sex hypertension, family(binomial) link(logit) eform robust

ผลลัพธ์จะเป็น odds ratio (OR) เช่น OR = 2 หมายความว่า X เพิ่ม 1 หน่วย → odds ของ Y = 1 เพิ่ม 2 เท่า

📈 แล้ววาดกราฟได้อย่างไร? (ในเมื่อ Y เป็น 0 กับ 1 เท่านั้น)

แม้ Y มีค่าเพียง 0 กับ 1 แต่ โมเดล logistic จะคำนวณ “โอกาสที่ Y=1” ได้ทุกค่า X

สามารถใช้คำสั่ง Stata ต่อไปนี้เพื่อดูแนวโน้มโอกาส:

margins, at(age=(20(5)80)) predict(pr)
marginsplot

เส้นกราฟที่ได้จะเป็นโค้ง sigmoid แสดงโอกาสเสียชีวิตตามอายุ

🧭 ใช้เมื่อใดในงานวิจัยทางคลินิก?

ประเภท Y

ใช้ Regression แบบไหน

หน่วยวัดผลลัพธ์

Continuous

regress

β coefficient

Binary (0/1)

logistic หรือ glm ..., binomial

Odds ratio (OR)

Count

poisson

Incidence Rate Ratio (IRR)

Time-to-event

stcox

Hazard ratio (HR)


🧠 สรุปสั้น ๆ

  • Logistic regression เหมาะสำหรับ outcome ที่เป็น binary

  • สามารถวิเคราะห์อิทธิพลของหลายตัวแปรต่อโอกาสเกิด outcome ได้

  • วาดกราฟได้โดยใช้ margins → marginsplot

  • แปลผลด้วย odds ratio พร้อม confidence interval

หากคุณสนใจกรณีตัวอย่างหรือการเปรียบเทียบระหว่าง OR, RR, RD — สามารถขอได้ครับ.

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
Post: Blog2_Post

​Message for International and Thai Readers Understanding My Medical Context in Thailand

Message for International and Thai Readers Understanding My Broader Content Beyond Medicine

bottom of page