Upload
others
View
16
Download
0
Embed Size (px)
Citation preview
Wilcoxon Signed Ranks test
ใช้เมื่อไร?• 2 correlated group design
• ตัวอย่างถูกเลือกมาจากประชากร แล้วทดลองเปรียบเทียบ1. Before/Method 1
2. After/Method 2
สมมุติฐาน
Ho: ค่า Median ของผลต่างแต่ละคู่ ไม่แตกต่างจาก 0H1: ค่า Median ของผลต่างแต่ละคู่ แตกต่างจาก 0
Contrary to paired t-test
Ho: ค่า Mean ของผลต่างแต่ละคู่ ไม่แตกต่างจาก 0
H1: ค่า Mean ของผลต่างแต่ละคู่ แตกต่างจาก 0
Wilcoxon Signed Ranks test
ข ัน้ตอน
1. หาคา่ผลตา่ง (difference) ของแตล่ะคู่
2. เรยีงล าดบัของคา่ผลตา่งโดยไมต่อ้งค านงึวา่จะ
เป็นคา่ + หรอื - แลว้ให ้Rank
3. แลว้ก าหนด + หรอื – ใหก้บั Rank ตามคา่
ผลตา่ง
4. หาผลรวมของ rank ทีเ่ป็น + (T+) และ – (T-)
5. คา่ Tobt = min(T+ ,T-)
6. หาก Tobt Tcrit reject Ho
• If N > 25, then use Tmin to estimate z (one-tail) for testing hypothesis
– Note: some may say that N as few as 8 can be used this estimation
i
ii ttNNN
NNT
z3
min
48
1
24
)12)(1(
4
)1(
where
• Tmin = min(T+ ,T-)
• N : number of all pair differences not equal to 0; may be the same as or less than that of observations
• ti : number of pair differences with the same rank i , i.e. tied ranks; summation of all groups of tied ranks is necessary
Rank-
-4
-8
-5
-9
-6
-7
-3
Example
T+=3 T-=-42Median difference = -0.05, Tobt=3
Ho: The median difference of polybrominated biphenyl (PBB) in contaminated raw meat between pairs is equal to 0
H1: The median difference of polybrominated biphenyl (PBB) in contaminated raw meat between pairs is not equal to 0
Tcrit, 2-tailed, α=0.05, N=9 = 5
z = -2.31; P2-tailed = 0.02
Conclusion: Because of Tobt
Kruskal-Wallis test, k samples
ใช้เมื่อไร?• k independent group design, k 2• เมื่อข้อมูลมีการกระจายไม่เป็นแบบปกติ
• หากความแปรปรวนของแต่ละกลุ่มตัวอย่างไม่เท่ากัน ให้
ใช้ Welch’s Test
สมมุติฐาน
Ho: ค่าเฉลี่ยของ Rank ในกลุ่มตัวอย่าง k กลุ่ม ไม่แตกต่างกัน
H1: ค่าเฉลี่ยของ Rankในกลุ่มตัวอย่าง k กลุ่ม แตกต่างกัน
Kruskal-Wallis test, k samples
ข ัน้ตอน
1. น าคา่ขอ้มลูทัง้หมดมาเรยีงล าดบั แลว้ให ้Rank
จาก 1 ถงึ N เมือ่ N=จ านวนคา่ทัง้หมด
2. หาผลรวมของ rank ในแตล่ะกลุม่
3. ค านวนคา่ Hobt จากสมการ
4. เมือ่จ านวนคา่ขอ้มลูในแตล่ะกลุม่เทา่กบัหรอืมากกวา่ 5
แลว้ คา่ Hobt จะมกีารแจกแจงใกลเ้คยีงกบัคา่ 2 ที่
df=k-1
5. หาก Hobt > Hcrit reject Ho
)1(3)(
)1(
12
1
2
Nn
R
NNH
k
i i
iobt
k = จ ำนวนกลุ่มni = จ ำนวนค่ำสงัเกตของกลุ่ม iRi = ผลรวมของ rank ของค่ำสงัเกตในกลุ่ม iN = จ ำนวนค่ำขอ้มูลทั้งหมด
𝐻′ =𝐻𝑜𝑏𝑡𝑇
=𝐻𝑜𝑏𝑡
1 −1
𝑁3 −𝑁σ𝑖(𝑡𝑖
3−𝑡𝑖)
หำกมี tied rank แลว้ ใหห้ำ H แทน ดว้ย
ti คือ จ ำนวนค่ำสังเกตท่ีมี rank เป็น i เดียวกนั และตอ้งรวมค่ำทุก tied rank
Example
Control nondialyzed
patient
dialyzed
patient
206.90 194.60 288.00
150.00 145.60 269.20
197.30 174.90 288.30
173.20 187.50 357.50
147.20 223.40 229.20
143.80 143.00 249.00
192.60 170.00 346.10
216.60
202.60
213.50
Ho: Mean ranks of liver sizes in three groups are the same
H1: Mean ranks of liver sizes in three groups are NOT the same
Does hemodialysis have effect on the size of the liver?
Group 2 1 2 1 1 2 1 2 2
Scores 143.00 143.80 145.60 147.20 150.00 170.00 173.20 174.90 187.50
Rank 1 2 3 4 5 6 7 8 9
Group 1 2 1 3 1 3 3 2 3
Scores 192.60 194.60 197.30 202.60 206.90 213.50 216.60 223.40 229.20
Rank 10 11 12 13 14 15 16 17 18
Group 3 3 3 3 3 3
Scores 249.00 269.20 288.00 288.30 346.10 357.50
Rank 19 20 21 22 23 24
Ranking
k = 3N = 24
n1 = 7R1 = 54
n2 = 7R2 = 55
n3 = 10R3 =191
2131
94.14
)124(310
191
7
55
7
54
)124(24
12
)1(3)(
)1(
12
222
1
2
kdf
Nn
R
NNH
k
i i
iobt
Hcrit, α=0.05, df=2 = 2α=0.05, df=2 = 5.991
Hobt > Hcrit, reject Ho, that is, difference in liver size does exist among three populations
P = chisq.dist.rt(14.94,2) = 0.0005
Which group has the largest size of liver?
Control
(1)
nondialyzed
patient (2)
dialyzed
patient (3)
206.90 194.60 288.00
150.00 145.60 269.20
197.30 174.90 288.30
173.20 187.50 357.50
147.20 223.40 229.20
143.80 143.00 249.00
192.60 170.00 346.10
216.60
202.60
213.50
ത𝑅1 =54
7= 7.71
ത𝑅2 =55
7= 7.86
ത𝑅3 =191
10= 19.10
Which group has the largest size of liver?
Post hoc test using Dunn procedure
ในการเปรียบเทียบของกลุ่มที่ i กับกลุ่มที่ j (ที่มีจ านวนค่าข้อมูลดิบเป็น ni กับ nj ตามล าดับ) ท าดังน้ี
1. หาคะแนนมาตรฐานของกลุ่ม i และ j จาก
𝑧𝑖𝑗 =ത𝑅𝑖− ത𝑅𝑗
𝑁(𝑁+1)
12×
1
𝑛𝑖+
1
𝑛𝑗
หรือหากมี tied rank ให้หาจาก
𝑧𝑖𝑗 =ത𝑅𝑖 − ത𝑅𝑗
𝑁(𝑁 + 1)12
−σ𝑖 𝑡𝑖
3 − 𝑡𝑖12(𝑁 − 1)
×1𝑛𝑖+1𝑛𝑗
เมื่อ N เป็นจ านวนข้อมูลดิบทั้งหมด และ ത𝑅. คือ ค่าเฉลี่ยของ rank
Which group has the largest size of liver?
Post hoc test using Dunn procedure
2. ในกรณีทดสอบแบบ 2-tailed ที่ระดับ
หาก 𝑧 > 𝑧1− ൗ𝛼
∗2แล้ว ปฏิเสธ Ho: ത𝑅𝑖 = ത𝑅𝑗
หาก 𝑧 ≤ 𝑧1− ൗ𝛼
∗2แล้ว ยอมรับ Ho: ത𝑅𝑖 = ത𝑅𝑗
o เมื่อเปรียบเทยีบคา่กลุม่หนึ่งกับกลุ่มอื่น ๆ ทุกกลุ่ม ใช้ 𝛼∗ =𝛼
ൗ𝑘(𝑘−1) 2
และ k คือจ านวนกลุ่ม
o เมื่อเปรียบเทยีบคา่กลุม่อ้างอิงหรือ control กับกลุ่มอื่น ๆ ทุกกลุ่ม
ใช้ 𝛼∗ =𝛼
𝑘−1และ k คือจ านวนกลุ่ม
o Example: k=4
=k(k-1)
=4*3
=12
i ii
iii
iv
ii i
iii
iv
iii i
ii
iv
iv i
ii
iii
i ii
iii
iv
ii iii
iv
iii iv
=k(k-1)/2
=4*3/2
=6
i ii
iii
iv
=k-1
=4-1
=3
Which group has the largest size of liver?
Control
(1)
nondialyzed
patient (2)
dialyzed
patient (3)
206.90 194.60 288.00
150.00 145.60 269.20
197.30 174.90 288.30
173.20 187.50 357.50
147.20 223.40 229.20
143.80 143.00 249.00
192.60 170.00 346.10
216.60
202.60
213.50
ത𝑅1 =54
7= 7.71
ത𝑅2 =55
7= 7.86
ത𝑅3 =191
10= 19.10
= 0.05* = /3* = 0.008331-*/2 = 0.99584z1-*/2 = 2.63839
|z12| = 0.03780
|z13| = 3.26738 *
|z23| = 3.22639 *
Something’s different but results
are the same
Ranks
Marker class N
Mean
Rank
Sum of
RanksF_st value DNA 6 10.08 60.50
Protein 14 10.68 149.50
Total 20
Test Statisticsb
F_st valueMann-Whitney U 39.500
Wilcoxon W 60.500
Z -0.206
Asymp. Sig. (2-tailed) 0.837
Exact Sig. [2*(1-tailed Sig.)] 0.841a
Ranks
Marker class N Mean RankF_st value DNA 6 10.08
Protein 14 10.68
Total 20
Test Statisticsa,b
F_st valueChi-Square 0.043
df 1
Asymp. Sig. 0.837
Exact Sig. 0.857
Point Probability 0.033
Mann-Whitney U test Kruskal-Wallis test
Spearman’s Rank Correlation Coefficient
• When to use
• Finding bivariate correlation for ordinal or ranked variables, or for data with uncertainty about normality
• Detecting monotonic correlation between variables
• A monotonic function is one that either never
increases or never decreases as its independent
variable increases. The following graphs illustrate
monotonic functions:
Monotonically increase –
as x increases, y never
decreases
Monotonically decrease
– as x increases, y never
increases
Non-monotonic – as x
increases, y sometimes
decreases and
sometimes increases
Spearman’s Rank Correlation Coefficient
ขัน้ตอน
1. พจิารณาขอ้มลูแตล่ะคู ่(xi, yi) ใหเ้รยีงล าดบัขอ้มลู
ตวัแปร X จากนอ้ยไปมากและให ้Rank
2. จากนัน้ ท าเชน่เดยีวกบัตวัแปร Y ท ัง้นีห้า้มแยกคา่
สงัเกตทีเ่ป็นคูก่นั
3. หาคา่ rx_i ry_i rx_iry_i r2x_i และ r
2y_i
– หากไม่ Tied rank อาจใชค้า่ d2 แทนได ้
4. ค านวณคา่ rs แลว้แปลงเป็นคา่ t โดยม ีdf=n-2
ทดสอบสมมตุฐิาน
5. ถา้ tobt tcrit reject Ho
]][[ 2222
iiii
iiii
yyxx
yxyx
s
rrnrrn
rrrrnr
Spearman’s rank correlation coefficient, rs
n=# paired ranksrx_i=ranks of xi variablesry_i=ranks of yi variablesrx_i=sum of ranks of x variablerx_i=sum of ranks of x variable
Spearman’s rank correlation coefficient, rs
𝑟𝑠 = 1 −6σ𝑑2
𝑛3 − 𝑛
• เมือ่ d คอืผลตา่งของ rank ของขอ้มลูดบิแตล่ะคู ่หรอื 𝑑𝑖 = 𝑟𝑥𝑖 − 𝑟𝑦𝑖เมือ่ 𝑟𝑥𝑖= Rank of xi และ 𝑟𝑦𝑖= Rank of yi
• n คอื จ านวนขอ้มลูดบิ (คู)่
• ใชเ้มือ่ Rank ของขอ้มลูในตวัแปรทัง้สอง ไมม่ี tie
Approximation of t for testing rs
)2/()1( 2
nr
rt
s
s
df = n-2 where n=# paired ranks
Value of rs Interpretation
r= 0 The two variables do not vary
together at all
0 > r > 1 The two variables tend to increase
or decrease together
r = 1.0 Perfect correlation
-1 > r > 0 One variable increases as the other
decreases
r = -1.0 Perfect negative or inverse
correlation
Melfi and Poyser (2007) observed the behavior of 6 male colobus monkeys (Colobus
guereza) in a zoo and number od eggs of Trichuris nematodes per gram of monkey
feces. They wanted to know whether social dominance was associated with the number
of nematode eggs.
Monkey
name
Dominance
rank, x
Eggs per
gram
Rank of Eggs
per gram, y
Erroll 1 5777 1
Milo 2 4225 2
Fraiser 3 2674 3
Fergus 4 1249 4
Kabul 5 749 6
Hope 6 870 5
From -- http://www.biostathandbook.com/spearman.html
𝑥 = 21,𝑥2 = 91
𝑦 = 21,𝑦2 = 91𝑥𝑦 = 90
𝑟𝑠 =6 × 90 − 21 × 21
(6 × 91 − 212) × (6 × 91 − 212)
𝑟𝑠 = 0.943
𝑡𝑐𝑎𝑙 =0.943
൘(1 − 0.9432)
(6 − 2)
= 5.659
𝑑𝑓 = 6 − 2 = 4𝑃2−𝑡𝑎𝑖𝑙𝑒𝑑 = 𝑡. 𝑑𝑖𝑠𝑡. 2𝑡 0.5659,4 = 0.005𝑡𝑐𝑟𝑖𝑡,2−𝑡𝑎𝑖𝑙𝑒𝑑,∝=0.05 = 2.776
Ho : social dominance and the number of nematode eggs are NOT associated
H1 : social dominance and the number of nematode eggs are associated
Tcal > Tcrit [or P
Nicotine in
blood (nmol/L)
Nicotine in
cigar (mg)rx ry d d
2 r2x r2
y rx*ry
196.5 0.76 4 1 3 9 16 1 4
192.8 0.84 3 2 1 1 9 4 6
197.3 0.96 5 3 2 4 25 9 15
199.1 1.11 6 4 2 4 36 16 24
207.4 1.14 9 5 4 16 81 25 45
204.2 1.21 8 6 2 4 64 36 48
183.0 1.28 1 7 -6 36 1 49 7
185.7 1.51 2 8 -6 36 4 64 16
234.1 1.53 10 9 1 1 100 81 90
199.9 1.66 7 10 -3 9 49 100 70
sum 55 55 120 385 385 325
Ho: No correlation between nicotine in blood and nicotine in cigarH1: There is correlation between them
rx ry d d2 r2x r
2y rx*ry
sum 55 55 120 385 385 325
2727.0825
255
]55)38510][(55)38510[(
)5555()32510(
]][[
22
2222
s
s
yyxx
yxyx
s
r
r
rrnrrn
rrrrnr
iiii
iiii
𝑟𝑠 = 1 −6σ𝑑2
𝑛3 − 𝑛
𝑟𝑠 = 1 −6 × 120
103 − 10= 1 −
720
990= 0.2727
tcal = 0.801df=8P = t.dist.2t(0.801,8)=0.94Tcrit, 2-tailed, α=0.05 = 2.306
tcal < tcrit Retain H0, that is there is no statistically correlation between nicotine in blood and nicotine in cigar
Hypothesis testing
8018.03402.0
2727.0
)210/()2727.01(
2727.0
)2/()1(
2
2
t
t
nr
rt
s
s
Pearson, rp, vs Spearman rank, rs, correlation coefficients
rp= 0.647
rs= 1.000
rp= 0.008
rs= 0.000
rp= -0.647
rs= -1.000
rp= 0.022
rs= 0.069
NO monotonic relationship, but perfect quadratic
relationship
NO relationship
Perfect positive monotonic relationship Perfect negative monotonic relationship
Tie or Equal Rank: WSR test(and similar tests)
A. หากพบว่าข้อมูลดิบคู่ใดมีค่าเดียวกัน ไม่ต้องน าขอ้มลูดบิคูน่ัน้
ไปวิเคราะห์
B. หากค่าผลต่าง (x-y) อย่างน้อย 2 ค่า มีค่าเท่ากัน ให้หาค่าเฉลี่ยRank ของผลต่างที่มีค่าเท่ากัน แล้วจึงใช้ค่าเฉลี่ย Rank ใน
การก าหนด Rank ของผลต่างน้ัน ๆ
X Y x-y R|x-y| R(x-y)(final)
15 17 -2 3 -2.5
10 10 0 N/A N/A
9 10 -1 1 -1
5 7 -2 2 -2.5
A
B
B
Tie or Equal Rank: Kruskal-Wallis test (and similar tests)
• เม่ือเรียงล าดับข้อมูลดิบแล้วพบว่าข้อมูลดิบ 2 ค่าหรือ
มากกว่า เป็นค่าเดียวกัน
• Rank ของข้อมูลดิบ 2 ค่าหรือมากกว่า มีค่าเดียวกัน
• Example
– ให้เรียงข้อมูลตามเดิม เช่น 199 201 201 203
– ในการก าหนด Rank นั้น ขั้นแรกก าหนดเรียงจากน้อยไป
มาก ในตัวอย่างข้างต้น คือ 1 2 3 4
– จากน้ัน ให้เฉลี่ยค่า Rank ของข้อมูลดิบที่มีค่าเดียวกัน ใน
ตัวอย่าง คือข้อมูลดิบ 201 ซึ่งมี 2 ค่า และมี Rank เป็น 2
และ 3 จึงหาค่าเฉลี่ยได้ (2+3)/2= 2.5
– ก าหนด Rank ใหม่เป็น 1 2.5 2.5 4
Tie or Equal Rank: Spearman Rank Correlation Coefficient (and similar tests)
A. หากว่าค่าข้อมูลดิบในตัวแปรเดียวกันอย่างน้อย 2 ค่า มีค่าเท่ากัน ให้หาค่าเฉลี่ย Rank ของข้อมูลที่มีค่าเท่ากัน แล้วจึง
ใช้ค่าเฉลี่ย Rank ในการก าหนด Rank ของข้อมูลนั้น ๆ
B. หากว่า Rank ที่ก าหนดในตัวแปร X และตัวแปร Y เป็น
Rank เดียวกัน ไม่นับวา่เปน็ tie และไม่ต้องตัดออกจากการวิเคราะห์
X Y R_x R_y R_y (final)
15 17 4 4 4
10 10 3 3 2.5
9 10 2 2 2.5
5 7 1 1 1 B
B A A