问题描述
我有这个数据集
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
和创建 dim
的 chisq.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