我试图在r中进行chi2测试,但它没有显示观察值,我不知道为什么[关闭]

pgx2nnw8  于 2023-04-03  发布在  其他
关注(0)|答案(1)|浏览(175)

**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。

这个问题是由打字错误或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
5天前关闭。
Improve this question

chitesting <- data.frame(TQ=c(22,5,9,10,24,11,4,6,9),
                        P=c(14,2,2,16,3,46,3,2,12))

chisq.test(chitesting)
chitesting$observed
chitesting$expected

我已经创建了这个 Dataframe ,但当我试图查看观察到的/预期的分数时,结果为NULL!对r来说非常新,因此将感谢任何帮助!

w46czmvw

w46czmvw1#

您需要将调用chisq.test()函数的结果存储在一个新变量中,因为chisq.test()函数不会将这些值存储在传入的 Dataframe 中:

chitesting <- data.frame(TQ=c(22,5,9,10,24,11,4,6,9), P=c(14,2,2,16,3,46,3,2,12))
chi_result <- chisq.test(chitesting)
print("chi_result:")
print(chi_result)
print("chi_result$observed:")
print(chi_result$observed)
print("chi_result$expected:")
print(chi_result$expected)

输出:

Warning message:
In chisq.test(chitesting) : Chi-squared approximation may be incorrect
[1] "chi_result:"

    Pearson's Chi-squared test

data:  chitesting
X-squared = 49.299, df = 8, p-value = 5.572e-08

[1] "chi_result$observed:"
      TQ  P
 [1,] 22 14
 [2,]  5  2
 [3,]  9  2
 [4,] 10 16
 [5,] 24  3
 [6,] 11 46
 [7,]  4  3
 [8,]  6  2
 [9,]  9 12
[1] "chi_result$expected:"
        TQ    P
 [1,] 18.0 18.0
 [2,]  3.5  3.5
 [3,]  5.5  5.5
 [4,] 13.0 13.0
 [5,] 13.5 13.5
 [6,] 28.5 28.5
 [7,]  3.5  3.5
 [8,]  4.0  4.0
 [9,] 10.5 10.5

相关问题