【问题标题】:Two-sample chi-squared test in RR中的两样本卡方检验
【发布时间】:2014-01-27 06:07:48
【问题描述】:

我对 R 很陌生,所以请多多包涵。我正在使用卡方检验来比较给定位置的核苷酸频率,并计算了两个不同数据集中的 A、C、G、T 的数量:

x1 <- c(272003,310418,201601,237168)
x2 <- c(239614,316515,182070,198025)

我可以想到两种方法来进行双样本卡方检验:

> chisq.test(x1,x2)

    Pearson's Chi-squared test

data:  x1 and x2
X-squared = 12, df = 9, p-value = 0.2133

Warning message:
In chisq.test(x1, x2) : Chi-squared approximation may be incorrect

> chisq.test(cbind(x1,x2))

    Pearson's Chi-squared test

data:  cbind(x1, x2)
X-squared = 2942.065, df = 3, p-value < 2.2e-16

我怀疑第二个版本是正确的,因为我也可以这样做:

> chisq.test(x1,x1)

    Pearson's Chi-squared test

data:  x1 and x1
X-squared = 12, df = 9, p-value = 0.2133

Warning message:
In chisq.test(x1, x1) : Chi-squared approximation may be incorrect

结果相同且明显不正确。

在这种情况下实际计算的是什么?

谢谢!

【问题讨论】:

    标签: r chi-squared


    【解决方案1】:

    chisq.test(x1,x1)$expected 显示如下:

            x1
    x1       201601 237168 272003 310418
      201601   0.25   0.25   0.25   0.25
      237168   0.25   0.25   0.25   0.25
      272003   0.25   0.25   0.25   0.25
      310418   0.25   0.25   0.25   0.25
    

    观察到的计数 (chisq.test(x1,x1)$observed):

            x1
    x1       201601 237168 272003 310418
      201601      1      0      0      0
      237168      0      1      0      0
      272003      0      0      1      0
      310418      0      0      0      1
    

    因此,它假设您提供所有对,但您只提供相同的数字,因此这是观察到的计数。然后,预期值实际上是“正确的”(尽管在这种情况下很愚蠢)。附带说明一下,chisq.test(cbind(x1,x1)) 会按照您的预期执行 (X-squared = 0, df = 3, p-value = 1)。

    您的第二个结果看起来不错:

    > chisq.test(cbind(x1,x2))$observed
             x1     x2
    [1,] 272003 239614
    [2,] 310418 316515
    [3,] 201601 182070
    [4,] 237168 198025
    > chisq.test(cbind(x1,x2))$expected
               x1       x2
    [1,] 266912.4 244704.6
    [2,] 327073.2 299859.8
    [3,] 200162.6 183508.4
    [4,] 227041.8 208151.2
    

    【讨论】:

      猜你喜欢
      • 2023-01-12
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-08-26
      • 1970-01-01
      • 2020-06-22
      • 2017-02-19
      相关资源
      最近更新 更多