我在一个拷贝区域中有4种基因型的观察计数样本。我想做的是,计算这些基因型的等位基因频率,然后用卡方检验这些频率与预期值25%:25%:25%:25%的显著偏离。
到目前为止,我得到了:
> a <- c(do.call(rbind, strsplit(as.character(gdr18[1,9]), ",")), as.character(gdr18[1,8]))
> a
[1] "27" "30" "19" "52"接下来,我得到总计数:
> sum <- as.numeric(a[1]) + as.numeric(a[2]) + as.numeric(a[3]) + as.numeric(a[4])
> sum
[1] 128现在频率:
> af1 <- as.numeric(a[1])/sum
> af2 <- as.numeric(a[2])/sum
> af3 <- as.numeric(a[3])/sum
> af4 <- as.numeric(a[4])/sum
> af1
[1] 0.2109375
> af2
[1] 0.234375
> af3
[1] 0.1484375
> af4
[1] 0.40625我现在迷路了。我想知道af1、af2、af3和af4是否显著偏离0.25、0.25、0.25和0.25
我如何在R中做到这一点?
谢谢你,艾利安
编辑:
好的,我正在按照建议尝试chisq.test():
> p <- c(0.25,0.25,0.25,0.25)
> chisq.test(af, p=p)
Chi-squared test for given probabilities
data: af
X-squared = 0.146, df = 3, p-value = 0.9858
Warning message:
In chisq.test(af, p = p) : Chi-squared approximation may be incorrect警告消息试图告诉我什么?为什么这个近似值是不正确的?
为了测试这种方法,我选择了与预期值0.25相去甚远的值:
> af=c(0.001,0.200,1.0,0.5)
> chisq.test(af, p=p)
Chi-squared test for given probabilities
data: af
X-squared = 1.3325, df = 3, p-value = 0.7214
Warning message:
In chisq.test(af, p = p) : Chi-squared approximation may be incorrect在这种情况下,H0仍然不会被拒绝,即使这些值与预期值0.25相差甚远。
发布于 2014-07-06 03:32:45
observed <- c(27,30,19,52)
chisq.test(observed)这表明这样的频率或更极端的频率会在大约0.03%的时间内偶然出现(p = 0.0003172)。
如果您的零假设不是跨四个类别的25:25:25:25分布,但假设问题是这些数据是否显著偏离3:3:1:9预期,则需要显式计算预期频率:
expected <- sum(observed)*c(3,3,1,9)/16
chisq.test(observed,p=c(3,3,1,9),rescale.p=TRUE)https://stackoverflow.com/questions/24589712
复制相似问题