Professional Documents
Culture Documents
Basic Stata For Biostatistics
Basic Stata For Biostatistics
่ สน
ปรับแต่งหน้าตา Stata เพิมสี ่ ้
ั ก่อนเริมใช
งาน
11
12
13
Data management
Type of data (1) 14
NOMINAL DATA
► values that the data may have do not have specific order
► values act as labels with no real meaning
► categories, states
► Binomial: two possible values
► Multinomial: more than two possible values
e.g. Health status healthy =1 sick=2
e.g. Treatment new regimen = 1 standard regimen = 2
e.g. hair color brown =1 blond =2 black =100
ORDINAL DATA
► values with some kind of ordering
► data that has been measured or counted
e.g. social class: upper=1 middle = 2 working = 3
e.g. glioblastoma tumor grade: 1 2 3 4 5
e.g. position in a race: 1st 2nd 3rd
Type of data (3) 15
DISCRETE
► distinct or separate parts, with no finite detail
e.g. children in family
CONTINUOUS
► between any two values, there would be a third
e.g. between meters there are centimeters
INTERVAL
► equal intervals between values and an arbitrary zero on the scale
e.g. temperature gradient
RATIO
► equal intervals between values and an absolute zero
e.g. weight, body mass index
Examples of coding 16
Cat. 1 2 99
Type of data 17
่ อตั
► คลิกขวาทีชื ่ วแปร แล ้วกด
drop
► พิมพ ์โค ้ด drop ตามด ้วยชือ่
ตัวแปร
พูดจาภาษา stata (1) 28
► Gen มาจาก generate หมายถึง สร ้างตัวแปร
Ex. Gen bmi = weight/(height^2)
ใหม่ สร ้างตัวแปรชือ่ bmi เท่ากับ
► Replace หมายถึง แทนที ค่าในตัวแปรชือ่ weight หาร ( ค่าในตัวแปรชือ่ height ยกกกาลัง 2)
► Recode หมายถึงแทนค่า Ex. Gen diff = pre-post if age !=. & (pre-post)>0
่ ง if ต ้องเป็ น == สร ้างตัวแปรชือ่ diff เท่ากับ ค่าในตัวแปรชือ่ pre ลบด ้วย ค่าในตัวแปรชือ่
► If หมายถึง ถ ้า โดย = ทีมาหลั
► & หมายถึง และ post เมือ ่ age ไม่เท่ากับค่าว่าง และ ค่าใน pre ลบด ้วย post มากกว่า 0
► |(อยู่ตรง ข.ไข่) หมายถึง หรือ Ex. Replace age = . If age == 999 | age > 100
► . “” หมายถึง ค่าว่าง แทนที่ ตัวแปรชือ่ age ให ้เท่ากับค่าว่าง ถ ้า ตัวแปรชือ่ age เท่ากับ 999
► != หมายถึง ไม่เท่ากับ หรือมากกว่า 100
► + - * / ^ บวก ลบ คูณ หาร ยกกาลัง Ex. Recode age min/20=1 21/60=2 61/max=3, gen (agegr)
้
► Clear หมายถึงล ้างข ้อมูลทังหมด แปลงค่า age ค่าน้อยสุดถึง20เท่ากับ 1 ค่า21ถึง60เท่ากับ 2 ค่า61ถึงสูงสุด
► Use หมายถึงใช ้ข ้อมูลหรือเปิ ดข ้อมูล เท่ากับ 3
สร ้างเป็ นตัวแปรชือ่ agegr
► Disp หรือ display แปลว่า แสดงผล
► Tab หรือ tabulate หมายถึงตาราง Ex. Disp 52/5*100 แสดงผล 52 หารด ้วย 5 คูณ 100
Ex. Tab var1 var2 สร ้างตาราง var1 เป็ น row และ var2 เป็ น
Terminology 29
► Constants ค่าคงที่
► Variable ตัวแปร
► Independent ตัวแปรตาม
► Dependent ตัวแปรต ้น
► Extraneous ตัวแปรภายนอก
► Confounding
► มีความสม ั พันธ์กบ
ั ทัง้ predictive และ outcome
variable โดยต ้องเป็ น cause of outcome แต่
ไม่ได ้มี predictor เป็ น cause (ไม่ได ้เป็ น
intermediate) หลังจาก adjust ต่างจาก crude
► Effect modifier/Interaction
► ั พันธ์ ระหว่าง predictor กับ
ทาให ้ ความสม
outcome เสยี homogeneity
► stratified specific risk ratio แตกต่างกัน
30
Study Design
Type of study 31
► Observational
► Descriptive (Parameter Estimation)
► Cross-sectional
► Analytic (Hypothesis testing)
► Cross-sectional
► Case-control
► Cohort
► Experimental
► True experimental >> RCT, non-RCT
► Quasi experimental
Observational study 32
Cohort
Case Non-case Total Exposure 🡪 Outcome ปัจจัยไปหาผลลัพท ์
้
บอก causality ได ้ ศึกษาได ้ทังไปข ้างหน้าและ
Exposed A B A+B ยอ้ นหลัง
ใช ้ศึกษากับ outcome ทีเป็ ่ น incidence
่ กษาจากตอนทียั
เริมศึ ่ งไม่เริมป่
่ วย
Not C D C+D
exposed
Smoking (y/n)🡪 Cancer (y/n)
Total A+C B+D A+B+C+D
Diabetes(y/n)🡪 Chronic kidney
disease
Case-Control
Outcome 🡪 Exposure Cross-sectional
บอก causality ได ้ Exposure <-> Outcome
่ น prevalence
ใช ้ศึกษากับ outcome ทีเป็ บอกได ้แค่สม
ั พันธ ์กันหรือไม่ บอกค่าเป็ น
เหตุผลไม่ได ้
Cancer (y/n)🡪 Smoking (y/n)
Stroke after surgery(y/n)🡪 surgery Smoking (y/n)<-> Cancer (y/n)
time Depress <-> Quality of life
Cross-sectional 33
Population Sampling
Exposed A B A+B
Representative
at risk sample Not C D C+D
exposed
Total A+C B+D A+B+C+D
Cross-sectional 34
► Single point in time (Snapshot) -> Exposure and Outcome
► measured at one point in time or over a period
► No Follow up
► ้
ทาง่าย ใชเวลาน ้อย
► ข ้อมูล Individual
► Measure of frequency : Prevalence
► Measure of association: Prevalence ratio (PR),Prevalence Odds ratio(POR)
► ใชกั้ บ โรคทีไ่ ม่ทราบ onset ex. โรคเรือ
้ รัง
► ได ้ข ้อมูล POR <- Overestimate risk มากกว่า PR
► No Temporal sequence บอกได้แค่วา
่ มีAssociation ไม่ได้บอกว่าอะไรเป็นสาเหตุ
► ใข ้กับRare exposure หรือ Rare outcome ยาก
► Prevalence-incidence bias (Length Bias / Survival bias)-> เจอโรคทีม
่ ี long durationได ้มากกว่า
Case-control 35
► causality
► Outcome 🡪 Exposure
Case Non-case Total ► Odds ratio
Exposed A B A+B
Not C D C+D
Target population
exposed V
Total A+C B+D A+B+C+D Source population
V
Sampling Eligible
population(Characteristics )
V
Case Non-case
population population Study Participants
Case-control 36
Disease Exclude
Cohort 38
► Fixed Exposure (ex Blood group), ► บอกCause -> Effect Relation (Temporality) ได ้ดีกว่า
Case-Control
► Time-dependent Exposure (ex Blood Sugar)
► Con
► Hard Outcome ex. Death , Disease
► ้
แพง ใชเวลามาก
► Intermediate Outcome ex. CD4
► Loss Follow up
► Comparison group ต ้องมี as similar as possible
► Measure of frequency : Incidence
► ดีสด
ุ ต ้องInternal Comparison
(เปรียบเทียบในCohortเดียวกัน) ► Measurements Association : Relative Risk
แต่ถ ้าไม่ได ้ก็ใช ้ Comparison Group
(External Comparison)
39
Types of statistic
π
Types of statistic P
X
Sampling
Technique
μ
40
s
By Level of Generalization
► Descriptive Statistics Generalization/
Inferential Statistics
► Inferential Statistics
▪ Parameter Estimation
π1 = π2
▪ Hypothesis Testing μ1 = μ2
• Comparison
Generalization
• Association /
• Multivariable data analysis
• Multivariate data analysis
Epidemiological study design 41
Time
Person
Epidemiology
Causality
determinant Analytic
Risk factor
Epidemiological study design 42
Case report
Cross-
sectional
Observation
Cross-
sectional
Analytic
Case-
control
Cohort
Descriptive study 43
Shapiro-Wilk test
Histogram
ไม่ใช่ normal
distribution
• Median = 23 Normal distribution
• Q1 = 21 • Mean = 23.58
• Q3 =26 • S.D. = 3.40
• IQR = Q3-Q1= 5
47
Measures in epidemiology
การวัดทางระบาดวิทยา
Aims of Epidemiologic Research 48
Measures of frequency
่
การวัดความถี/การกระจาย
Measure of FREQUENCY 50
► Ratio
► relative magnitude of two quantities or a comparison of any two values
► The numerator and denominator need not be related
► =A/B
► Proportion
► the comparison of a part to the whole
► It is a type of ratio in which the numerator is included in the denominator
► =A/(A+B)
► Rate
► Measure an event occurs in a defined population over a specified period of
time
► = A/time
Proportion สัดส่วน ตัวตัง้ เป็ น ส่วนหนึ่ งของ 51
ตัวหาร
Ratio อัตราส่วน ตัวตัง้ ไม่ใช่ ส่วนหนึ่ ง 52
ของตัวหาร
Prevalence
Prevalence (1) ความชุก 55
►
Prevalence (2) 56
►
Point Prevalence 57
►
Period Prevalence 59
60
Incidence
Incidence (1) อุบต
ั ก
ิ ารณ์ 61
1. Incidence proportion
2. Incidence rate ; เวลาเป็ นตัวหาร
Incidence (2) 62
►
Incidence proportion 63
= 2/6 = 33.33%
Incidence proportion 65
Incidence (3) 66
้
Example: ในระหว่างการระบาดของเชือไวร ัสโคโรนา 2019 ผูป้ ่ วย 50
จาก 2000 คนเสียชีวต
ิ
่ อการเสียชีวต
จงหาความเสียงต่ ิ ในผู ้ป่ วยกลุ่มนี ้
= 50/2000 = 0.025 =25 per 1000 = 2.5%
Incidence (4) 67
►
Incidence rate 68
X 2
4
Other measure of frequency 69
►
Attack rate (AR) (2) 71
Male AR =25.25%
Female AR = 27.32%
Overall AR=26.04%
Pr>0.05 ไม่มค
ี วามแตกต่างกัน AR ระหว่าง male และ fe
Attack rate (AR) (3) 72
Case-fatality rate
74
Comparison testing
Comparison between group 75
► Categorical outcome
• Chi-square (χ2) test
► Continuous Variable
❖ Normal Distribution
• t-test (2 groups) F-test/ANOVA (>= 2 groups)
❖ Not normal Distribution
• Wilcoxon test, Mann-Whitney U test
Chi-square (c2) test 76
t-test (2 groups) 77
F-test/ANOVA (>= 2 groups) 78
Wilcoxon test, 79
80
Measures of association
การวัดความสัมพันธ ์
Measures of association 81
►
Case Non-case Total
Exposed A B A+B
Not C D C+D
exposed
Total A+C B+D A+B+C+D
Prevalence difference (PD) 83
Risk Ratio
Risk ratio / Relative risk (RR) (1) 85
► ี
ท้องเสย ไม่ม ี Total
ท้องเสยี
กินไข่ตม
้ 60 40 100
ไม่ได้กน
ิ 10 90 100
ไข่ตม
้
่ อการเกิดอาการท ้องเสียในกลุม
ความเสียงต่ ่ นไข่ต ้มเป็ น 6 เท่าของ
่ ทีกิ
่ ได ้กิน
คนทีไม่
Risk ratio / Relative risk (RR) (2) 86
►
่ อการติดเชือในคนที
ความเสียงต่ ้ ่ วค
ได้ ั ซีนเป็ น 0.7 เท่าของคนที่
ไม่ได้วค ั ซีน
่ อการติดเชือในคนที
ความเสียงต่ ้ ไม่่ ได้วค
ั ซีนเป็ น 1.43 เท่าของค
ได้วค
ั ซีน
Risk ratio / Relative risk (RR) (3) 87
่ อการติดเชือในคนที
ความเสียงต่ ้ ่ วค
ได้ ั ซีนเป็ น 0.7 เท่าของคนที่
ไม่ได้วคั ซีน
Risk ratio / Relative risk (RR) (4) 88
่ อการติดเชือในคนที
ความเสียงต่ ้ ่ วค
ได้ ั ซีนเป็ น 0.7 เท่าของคนที่
ไม่ ได้ว ัคซีนEfficacy (VE) = 1- RR = 1-0.7 = 0.3 = 30%
Vaccine
้ ้ร ้อยละ 30
วัคซีนมีประสิทธิภาพป้ องกันการติดเชือได
Vaccine Efficacy(VE) 89
►
Risk difference (RD, attributable risk) 90
► difference of two incidence proportions (exposed vs unexposed group)
► Cohort study
► 𝐼𝐸 − 𝐼𝑢
► = (51/238) – (74/242)
► =21.43-30.58
► = -0.09 = 9%
► ี่ งต่อการติดเชอ
ความเสย ื้ ในคนทีไ่ ด ้วัคซน
ี คือ 9% น ้อยกว่าคนทีไ่ ม่ได ้วัคซน
ี
Rate ratio / Incidence rate ratio 91
(IRR) (1)
► A ratio of two incidence rates No. of sick Person-time Incidence
rate
► Used in RCT or Cohort study (with
person-time data) Exposed A TE A/TE
Unexposed B TU B/TU
► Rate ratio (IRR) = [A/TE] / [B/TU ]
Total A+B TE+TU (A+B)/(TE+TU)
92
Exposed A B A+B
Not C D C+D
exposed
Total A+C B+D A+B+C+D
(cohort study)
►
Case Non-case Total
Exposed A B A+B
Not C D C+D
exposed
Total A+C B+D A+B+C+D
Exposure odds ratio 95
(case-control study)
►
Case Non-case Total
Exposed A B A+B
Not C D C+D
exposed
Total A+C B+D A+B+C+D
96
97
Odds ratio 98
► ใน Case-control study
► ถ ้า ึ ษาทีส
Case และ control ในการศก ่ ามารถเป็ นตัวแทนทีด
่ ใี น
ประชากร
► Exposure OR = Disease OR
► ถ ้าใน rare disease OR ≈ RR
► เราสามารถแปลผล OR แบบ RR ได ้
Odds ratio in Logistic regression 99
► OR = exp β
100
Odds ratio in Logistic regression 101
Regression model
Regression model 103
► Linear Regression
❖ Y = continuous + normal distribution
❖ Injury severity score
► Logistic Regression OR = exp
Y = Categorical
❖
β
❖ Dead/ severity of injury/ bone fracture
► Poisson Regression
❖ Y = Incidence/count
❖ Dead IRR = exp
► Cox’s Proportional Hazard Regression β
❖ Y = Time to event
► Time from injury to dead HR = exp
β
X= continuous / categorical Note: If P0 (T) is small, when comparing two groups
; sex, age, alcohol drinking
Principles for studying association 105
⮚ Start with graphical display: scatterplots
■ Display the relationship between two quantitative variables.
■ The values of one variable appear on the horizontal axis (the x axis) and the values of
the other variable on the vertical axis (the y axis).
■ Each individual is the point in the plot fixed by the values of both variables for that
individual.
■ In regression, usually call the explanatory variable x and the response variable y.
⮚ Look for overall patterns and for striking deviations from the pattern :
interpreting scatterplots
■ Overall pattern: the relationship has ...
⬥ form (linear relationships, curved relationships, clusters)
⬥ direction (positive/negative association)
⬥ strength (how close the points follow a clear form?)
⬥ Outliers
■ For a categorical x and quantitative y, show the distributions of y for each
category of x.
⮚ When the overall pattern is quite regular, use a compact mathematical model
to describe it.
106
Linear Regression
Y = CONTINUOUS + NORMAL DISTRIBUTION
Normal distribution of Y 107
108
109
110
111
Normal distribution of Y 112
scatterplots 113
Linear regression 114
Y = a + bx
่ มขึ
ทุก 1 หน่ วย x ทีเพิ ่ น้ จะเพิม
่ y ขึน้ b หน่ วย
Y = a + bx
่ มขึ
ทุก 1 หน่ วย x ทีเพิ ่ น้ จะเพิม
่ y ขึน้ b หน่ วย
Logistic Regression
Y = CATEGORICAL
Logistic Regression 119
► Binary outcome
► Outcome = yes/no
► Ordinal outcome
► Outcome = level
► Ex. Tumor grade
► Multinomial outcome
► Outcome = category
Binary Logistic regression 120
► Outcome = level
► Ex. 1 2 3 4 5
► เป็ นการเปรียบเทียบกับระดดับทีสู่ ง
่ า
กว่าและตากว่
► 1 เทียบกับ 2, 2 เทียบกับ 1 และ 3, 3
เทียบกับ 2 และ 4, 4 เทียบกับ 3 และ
5, 5 เทียบกับ 4
Ordinal Logistic regression 122
Ordinal Logistic regression 123
้ าให ้
การตกจากเก ้าอีจะท ่ การยุบตัวของตัวถังรถ
การนั่งบริเวณทีมี
การบาดเจ็บรุนแรงขึน้ 4.5 จะทาให ้การบาดเจ็บรุนแรงขึน้ 13.54
เท่า เท่า
Ordinal Logistic regression 124
้ าให ้การบาดเจ็บรุนแรงขึน้
การตกจากเก ้าอีจะท
4.69 เท่า
่ านึ งถึงตัวแปรรบกวนจากการนั่งบริเวณทีมี
เมือค ่ การ
Multinomial Logistic regression 125
คนทีสู่ บบุหรีหนั
่ กจะมีความอยากเลิกแต่ไม่
่ ยบคน
เคยพยายามเลิกเป็ น 0.75 เท่าเมือเที
่ อยากเลิก
ทีไม่
่
คนทีอยากเลิ กแต่ไม่เคยพยายามเลิกจะเป็ น
่ ก
คนสูบบุหรีหนั
่ ยบกับคนทีไม่
เป็ น 0.75 เท่าเมือเที ่ อยากเลิก
่ บบุหรีหนั
คนทีสู ่ กจะมีความอยากเลิกและ
่ น 0.65 เท่าของคนทีไม่
พยายามเลิกบุหรีเป็ ่
อยากเลิก
Confounding vs effect modification 126
Confounding 127
EXPOSURE DISEASE
(alcohol drinking) (heart disease)
CONFOUNDING
VARIABLE
(cigarette smoking)
Degree of Confounding
⮚>1 over estimation
⮚<1 under estimation
Effect modification/ Interaction 129
Poisson Regression
Y = INCIDENCE / CONTINUOUS
131
Univariate analysis 132
ี่
• ผูท้ ตกจากเก ้ ความเสียงที
้าอีจะมี ่ จะมี
่ คา่
รุนแรงการบาดเจ็บเพิมขึ่ นเป็
้ น 4.18 เท่า
่ ตก เมือตั
ของคนทีไม่ ่ ดตัวรบกวนจากการ
หลับขณะเกิดเหตุ การนั่งบริเวณทีมี ่ การ
ยุบตัวของตัวถังรถและการโดนชินส่ ้ วนรถ
กระแทกแล ้ว
• คนทีนั่ ่ งบริเวณทีมี
่ การยุบตัวขอรถมีคาม
่ จะมี
เสียงที ่ คะแนนความรุนแรงการ
บาดเจ็บเพิมขึ ่ น้ 3.86 เท่า เมือตั
่ ดตัว
รบกวนจากการหลับขณะเกิดเหตุ การตก
้
เก ้าอีและการโดนชิ ้ วนรถกระแทกแล ้ว
นส่
Multivariate analysis; Coef. 134
ี่
• ผูท้ ตกจากเก ้ ความเสียงที
้าอีจะมี ่ จะมี
่ คา่
รุนแรงการบาดเจ็บเพิมขึ่ นเป็
้ น 1.43
่ ดตัวรบกวนจากการหลับ
คะแนน เมือตั
ขณะเกิดเหตุ การนั่งบริเวณทีมี่ การยุบตัว
ของตัวถังรถและการโดนชินส่้ วนรถ
กระแทกแล ้ว
่ ่ งบริเวณทีมี
• คนทีนั ่ การยุบตัวขอรถมีคาม
่ จะมี
เสียงที ่ คะแนนความรุนแรงการ
บาดเจ็บเพิมขึ ่ น้ 1.35 เมือตั
่ ดตัวรบกวน
จากการหลับขณะเกิดเหตุ การตกเก ้าอี ้
และการโดนชินส่ ้ วนรถกระแทกแล ้ว
Data management Poisson Regression 135
Rate ratio / Incidence rate ratio 136
(IRR) (1)
No. of sick Person-time Incidence rate
Exposed A TE A/TE
Unexposed B TU B/TU
► A ratio of two incidence rates Total A+B TE+TU (A+B)/(TE+TU)
1. ข ้อมูลเราเป็ นแบบไหน
Category / ordinal/ continue
Normal distribution ??
► Categorical Variables
▪ Ratio, Proportion, Percent (%)
► Continuous Variable
▪ Normal Distribution
⮚ Mean, SD
▪ Not normal Distribution
⮚ Median, Range/IQR
Analytic
► Comparison
► Categorical outcome
► Chi-square (χ2) test
► Continuous Variable
❖ Normal Distribution
► t-test (2 groups) F-test/ANOVA (>= 2 groups)
❖ Not normal Distribution
► Wilcoxon test, Mann-Whitney U test
► Association
► Study design
Association by study design