我有以下表格:
<表类>
词
猫
Num
tbody><<tr>十五 214 十五 N 190 深圳大鹏 DE 1308 深圳大鹏 N 925 表类>
我认为这段代码可能很有用。
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
好工作