Contents

1
2
3 襴曙 蟆
4
5 讌 蟆
6 McNemar Test
7 谿瑚襭


1 #

  • 覯譯(category)覲襦 觜(frequency)襷 譯殊伎 覯譯狩 一危一 覿 朱朱 豺伎伎螻 覿襯 伎 蟆覯

    • : 覲語 蟯豸° 覈讌 蠍磯襯 觜蟲 蠍磯 蟯豸° 谿願 讌襯 蟆(襯覿 谿瑚)
    • 襴曙: 炎 蟯螻螳 讌 蟆
    • 讌: 螳 伎 ろ覿螳 狩讌 蟆 (襴曙 蟆螻 螳 覦伎襷, 覿覈螻 る)
  • ろ覿
    • 蟆郁骸螳 2螳讌襷 覯襯企伎 n覯 襴曙朱 覦覲牛 炎概 危覿襯 磯ジ.
    • 蟆郁骸 3螳讌 伎 蟆曙磯 ろ覿(multinomial distribution) 磯ゴ蟆 .
  • 族 = 裡 (蟯豸♀ - 蠍磯螳)族 / 蠍磯螳
  • = (rows-1)*(cols-1)
  • れ "2007 蟆曙糾, 誤讌,, " 襯 .

2 #

蟆企, 覈讌 蠍磯螳 轟 襯 磯ゴ讌 蟆曙一 蟆.


8譬襯 譯殊 觜 語^ 譟一襯 伎 襯 螳襴螻 128覈 襦 れ 螳 譬 譯朱ゼ 襦 . 譯 襷 碁 谿願 り 螳?
chi01.jpg

tmp <- textConnection( 
"譯殊襯  蟯豸°
1	12
2	18
3	11
4	21
5	23
6	16
7	7
8	20") 
x <- read.table(tmp, header=TRUE)
close.connection(tmp)
head(x)

譯殊 碁 谿願 る 蟆 觜 螳 襷. 蠏碁覩襦 螳 譯殊 蠍磯 蟯豸° 16企.
> sum(x$蟯豸°) / nrow(x)
[1] 16
chi02.png

豺伎伎螻 蟆 企慨.
蠍磯 <- replicate(nrow(x), (sum(x$蟯豸°) / nrow(x)))
x <- cbind(x,e)
chisq.test(x=x$蟯豸°, y=x$蠍磯)

蟆郁骸
> chisq.test(x=x$蟯豸°, y=x$蠍磯)

	Chi-squared test for given probabilities

data:  x$蟯豸°
X-squared = 13.5, df = 7, p-value = 0.06082

蟆郁骸伎
  • 蠏覓願: 谿願 . (譯 碁 谿企 )
  • 襴所: (譯 碁 谿願 )
  • p-value螳 0.06082襦 譴 0.05 蠏覓願 讌讌


3 襴曙 蟆 #

[http](http://freesearch.pe.kr/archives/2555) 一危磯ゼ 伎 覲伎.
tmp <- textConnection( 
  "蟲′譴  ′一ろ  
譟	螻狩′	51
螻譟	螻狩′	22
譴譟	螻狩′	43
譟	′	92
螻譟	′	21
譴譟	′	28
譟	觜′	68
螻譟	觜′	9
譴譟	觜′	22") 
x <- read.table(tmp, header=TRUE)
close.connection(tmp)
head(x)

t <- xtabs(~蟲′譴+′一ろ, data=x)
t

蟆郁骸
> t
        ′一ろ
蟲′譴 螻狩′ 觜′ ′
    螻譟     22      9   21
    譟     51     68   92
    譴譟     43     22   28

蠍磯螳 れ 讌螻襯 伎 觜(ratio)襯 螻壱覃 .
> apply(t, 1, sum)
螻狩′ 觜′   ′ 
   116     99    141 
> apply(t, 2, sum)
螻譟 譟 譴譟 
  52  211   93 

襷, 蟲′譴螻 ′一 蟯 螳企慨. 覓伎襦 れ 30覈 觸 蟲′譴 危エ覲企 豌(螻譟:譟:譴譟 = 52:211:93) 襯 蟆企. 企 覩語 蠍磯螳螻 蟯豸♀ 覩誤 谿願 朱 襴曙煙 る 蟆企. 讌襷, 蠍磯螳螻 蟯豸♀ 覩誤 谿願 る 覲螳 襦 レ 譯朱 蟆企. 讀, 襴曙 .

蠍磯螳 螻壱企慨. 豌:′ = 356:141. 蠏碁覩襦 ′一譴 譴譟語 れ 356:141 = 93:x 讀, x = 141 * 93 / 356 = 36.8347企. 企蟆 殊殊 螻壱蟆 讌讀蟾 糾貂讌襯 伎 蟇磯. R summary(xtabs())覃 襴曙 su蟆 蠏碁 .

> summary(t)
Call: xtabs(formula =  ~ 蟲′譴 + ′一ろ, data = x)
Number of cases in table: 356 
Number of factors: 2 
Test for independence of all factors:
	Chisq = 18.51, df = 4, p-value = 0.0009808

  • 蠏覓願: 蟲′譴 ′一 レ 殊讌 . (襴曙企, 蟯豸♀螻 蠍磯螳 谿願 )
  • 襴所: 蟲′譴 ′一 レ 殊. (襴曙 , 蟯豸♀螻 蠍磯螳 谿願 )
  • p-value = 0.0009808, 蠏覓願 蠍郁

豈 覲企 '蠍磯 5危 cell 豌伎 20%螳 朱 fisher exact test'襯 磯手 伎. fisher exact test(
fisher.test) 豐蠍壱覿襯 伎 p-value襯 螻壱り .

4 #

れ A 覈讌 蠍磯願, B 覲語 蟯豸°. 覲語 覈讌螻 螳 覿 襯 螳讌讌 蟆企慨.
tmp <- textConnection( 
"A    B
829	772
217	211
110	111
79	59
61	73
45	41
37	42
23	32
21	21
17	18
") 
x <- read.table(tmp, header=TRUE) 
close.connection(tmp)

plot(x$A)
lines(1:nrow(x), x$B)

v <- x$B
e <- x$A/sum(x$A)
chisq.test(v, p=e)

蟆郁骸
> chisq.test(v, p=e)

	Chi-squared test for given probabilities

data:  v
X-squared = 14.2971, df = 9, p-value = 0.1121
  • 蠏覓願: A B 谿願 . --> p-value = 0.1121襦 譴 0.05 蠏覓願 讌讌
  • 襴所: A B 谿願 .

企 覿覿 谿願 ?
覿覈 <- c(x$A[1], x$B[1]) #豌 覯讌  覿覈 蟆曙
# 覿覈 <- c(sum(x$A), sum(x$B)) #豌 sum 覿覈瑚化
for(i in 2:nrow(x)){
    覿 <- c(x$A[i], x$B[i])
    #pval <- poisson.test(覿, 覿覈)$p.value * (nrow(x)-1) # nrow(x)-1  bonferroni conrrection
    pval <- prop.test(覿, 覿覈)$p.value * (nrow(x)-1) # nrow(x)-1  bonferroni conrrection
    print(paste0(i, "=",  pval))
}

5 讌 蟆 #

曙 襦譟一 蟆郁骸.
tmp <- textConnection( 
  "譬蟲  谿煙覿	
蠍磯蟲	谿	175
蠍磯蟲	覦	125
豌譯手	谿	100
豌譯手	覦	100
覿蟲	谿	160
覿蟲	覦	140
覓願	谿	250
覓願	覦	150") 
x <- read.table(tmp, header=TRUE) 
close.connection(tmp)
summary(xtabs(~譬蟲+谿煙覿, data=x))

蟆郁骸
> summary(xtabs(~譬蟲+谿煙覿, data=x))
Call: xtabs(formula =  ~ 譬蟲 + 谿煙覿, data = x)
Number of cases in table: 1200 
Number of factors: 2 
Test for independence of all factors:
	Chisq = 10.8, df = 3, p-value = 0.01286
  • 蠏覓願: 譬蟲 蟯螻 曙 蟆 狩.
  • 襴所: 譬蟲 蟯螻 曙 蟆 狩讌 .
  • p-value = 0.01286襦 譴 0.05 蠏覓願 蠍郁

6 McNemar Test #

覲(paired sample) 襭 蟯 觜 觜蟲 蟆朱, 郁 binary 覲 谿企ゼ 觜蟲 . paired t-test 螳 . 螳 朱 蟯螻 / 谿企ゼ 觜蟲 螳 蟆曙一 .
x = xtabs(~before + after, data=xdata)
mcnemar.test(x)

7 谿瑚襭 #