微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用 R,如何让 chisq.test 函数读取 4 列条目以获得正确的统计信息 数据

如何解决使用 R,如何让 chisq.test 函数读取 4 列条目以获得正确的统计信息 数据

我有这个数据集

structure(list(`total primary - yes RS` = 138L,`total primary - no RS` = 29L,`total secondary- yes rs` = 6L,`total secondary- no rs` = 0L),row.names = c(NA,-1L),class = c("tbl_df","tbl","data.frame"))


`total primary - yes RS`|`total primary - no RS`|`total secondary- yes rs`|`total secondary- no rs`
                   138                      29                         6                      0

我不是要求像这样转换它,而是使用它作为数据集对齐的参考

                   Col1                     Col2
 Row1 `total primary - yes RS|`total secondary- yes rs`
 Row2 `total primary - no RS`|`total secondary- no rs`

                   Col1                     Col2 
 Row1                 138                         6
 Row2                  29                         0

我试图运行这个,但我不知道我应该如何订购它。我使用这样的数据集得到了错误的结果。

 chisq.test(sample[,c("total primary - yes RS","total primary - no RS","total secondary- yes rs","total secondary- no rs")])

我期望的结果是

X-squared = 0.31654,df = 1,p-value = 0.5737
       

解决方法

在应用 unlist 之前,matrix 和创建 dimchisq.test 更容易chisq.test(matrix(unlist(df1),ncol = 2)) # Pearson's Chi-squared test with Yates' continuity correction #data: matrix(unlist(df1),ncol = 2) #X-squared = 0.31654,df = 1,p-value = 0.5737

df1 <- structure(list(`total primary - yes RS` = 138L,`total primary - no RS` = 29L,`total secondary- yes rs` = 6L,`total secondary- no rs` = 0L),row.names = c(NA,-1L),class = c("tbl_df","tbl","data.frame"))

数据

numpy

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。