【发布时间】:2017-10-09 17:01:29
【问题描述】:
我有一个这样的数据集:
contingency_table<-tibble::tibble(
x1_not_happy = c(1,4),
x1_happy = c(19,31),
x2_not_happy = c(1,4),
x2_happy= c(19,28),
x3_not_happy=c(14,21),
X3_happy=c(0,9),
x4_not_happy=c(3,13),
X4_happy=c(17,22)
)
事实上,还有许多其他变量来自两年不同年份的民意调查。
然后,我在每个 2X2 列联矩阵中应用 Fisher 检验,使用以下代码:
matrix1_prueba <- contingency_table[1:2,1:2]
matrix2_prueba<- contingency_table[1:2,3:4]
fisher1<-fisher.test(matrix1_prueba,alternative="two.sided",conf.level=0.9)
fisher2<-fisher.test(matrix2_prueba,alternative="two.sided",conf.level=0.9)
我想通过函数或循环使用短代码运行此任务。输出必须是包含每个问题的 p_values 的向量。
谢谢,
弗雷德里克
【问题讨论】: