R中的标准Chi平方测试?

时间:2014-07-05 19:09:22

标签: r chi-squared

我在单个拷贝区域中有4种基因型的观察计数样本。我想要做的是计算这些基因型的等位基因频率,然后对这些频率的测试显着偏离预期值25%:25%:25%:25%使用Chi Squared in R。

到目前为止,我得到了:

> 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

在这种情况下,即使值与预期的0.25值相差很远,H0仍然不会被拒绝。

1 个答案:

答案 0 :(得分:1)

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)
相关问题