使用 R,如何让 chisq.test 函数读取 4 列条目以获得正确的统计信息
Using R, how to have the chisq.test function read the 4 column entries to get the proper statistics
我有这个数据集
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
在应用 chisq.test
之前 unlist
和创建 dim
2 x 2 的 matrix
更容易
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"))
我有这个数据集
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
在应用 chisq.test
unlist
和创建 dim
2 x 2 的 matrix
更容易
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"))