R 中的 3 路卡方检验

Gün*_*nal 5 testing statistics r

我有如下分类数据:

gender age_group diagnosis
male     young    x
female   child    y
female   adult    x
male     old      z

gender, age_group and diagnosis have 2, 4 and 3 levels respectively. 
Run Code Online (Sandbox Code Playgroud)

我想进行一个Chi-Squared Test查看两个类之间的关系。我怎么能在 R 中做到这一点

mto*_*oto 4

我认为,三维列联表的适当测试是Cochran-Mantel-Haenszel 测试。为了使用它,您需要将数据转换为三维数组,并确保stratum生成的列联表中每个可能的频率 > 1。

# convert data to contigency table
df <- table(data)

# run test
mantelhaen.test(df)
Run Code Online (Sandbox Code Playgroud)

  • CMH 测试条件独立性,而卡方测试则测试相互独立性 [请参阅 https://onlinecourses.science.psu.edu/stat504/book/export/html/102] (2认同)