r语言 - chisq.使用数字变量进行测试



我有以下表格:

<表类> 词 猫 Num tbody><<tr>十五214十五N190深圳大鹏DE1308深圳大鹏N925

我认为这段代码可能很有用。

tibble(Word = c("shiwu", "shiwu", "dongxi", "dongxi"),
Cat = c("DE", "N", "DE", "N"),
Num = c(214, 190, 1308, 925)) %>% # build tibble (like data frame)
pivot_wider(names_from = Cat, values_from = Num) %>% # structuring it as a table
column_to_rownames("Word") %>% # defining first column (Word) as rownames
as.matrix() %>% # converting data for a contigency table
chisq.test() # executing chi-squared test

答案将是皮尔逊卡方检验的结果,并带有耶茨校正(此校正,对于此数据不会影响结果)。

Pearson's Chi-squared test with Yates' continuity correction
data:  .
X-squared = 4.1782, df = 1, p-value = 0.04095

好工作

最新更新