การอนุมานสำหรับข้อมูลเชิงตัวเลขใน R
Mine Cetinkaya-Rundel
Associate Professor of the Practice, Duke University
คำถามที่ต้องการศึกษา: การรักษาด้วยเซลล์ต้นกำเนิดจากตัวอ่อน (embryonic stem cells) ช่วยให้การทำงานของหัวใจฟื้นตัวหลังหัวใจวายได้ดีกว่าการรักษาแบบดั้งเดิมหรือไม่?
ข้อมูล: ชุดข้อมูล stem.cell จากแพ็กเกจ openintro
library(openintro)
data(stem.cell)
trmt before after
1 ctrl 35.25 29.50
2 ctrl 36.50 29.50
3 ctrl 39.75 36.25
... ... ...
n esc 53.75 51.00
ขั้นที่ 1 คำนวณ change ของแกะแต่ละตัว: ผลต่างระหว่างความสามารถในการสูบฉีดเลือดก่อนและหลังการรักษา
trmt before after change
1 ctrl 35.25 29.50 ?
2 ctrl 36.50 29.50 ?
3 ctrl 39.75 36.25 ?
... ... ...
n esc 53.75 51.00 ?
ขั้นที่ 2 ตั้งสมมติฐาน:
$H_0: \mu_{esc} = \mu_{ctrl}$; ไม่มีความแตกต่างระหว่างค่าเฉลี่ยการเปลี่ยนแปลงของกลุ่มทดลองและกลุ่มควบคุม
$H_A: \mu_{esc} > \mu_{ctrl}$; มีความแตกต่างระหว่างค่าเฉลี่ยการเปลี่ยนแปลงของกลุ่มทดลองและกลุ่มควบคุม
ขั้นที่ 3 ดำเนินการทดสอบสมมติฐาน
change ลงบนบัตรดัชนี 18 ใบchange ระหว่างสองกลุ่มใช้แพ็กเกจ infer ในการทดสอบ:
library(infer)
เริ่มต้นด้วย data frame แล้ว ระบุ โมเดล:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
...
ประกาศสมมติฐานหลัก คือไม่มีความแตกต่างระหว่างค่าเฉลี่ย:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
...
สร้าง ตัวอย่างซ้ำโดยสมมติว่า $H_0$ เป็นจริง:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
generate(reps = __, type = __) %>% # "bootstrap", "permute", or "simulate"
...
คำนวณ สถิติทดสอบ:
library(infer)
diff_ht_mean <- stem.cell %>%
specify(__) %>% # y ~ x
hypothesize(null = __) %>% # "independence" or "point"
generate(reps = _N_, type = __) %>%# "bootstrap", "permute", or "simulate"
calculate(stat = "diff in means") # type of statistic to calculate
คำนวณ p-value ในรูปสัดส่วนของการจำลองที่ผลต่างระหว่างค่าเฉลี่ยของกลุ่มตัวอย่างสุดขั้วไม่น้อยกว่าที่สังเกตได้
$$P ((\bar{x}_{esc,sim} - \bar{x}_{ctrl,sim}) \ge (\bar{x}_{esc,obs} - \bar{x}_{ctrl,obs}))$$
การอนุมานสำหรับข้อมูลเชิงตัวเลขใน R