我正在尝试针对多个分布(针对相同的预期分布)进行卡方检验。我想知道如何通过将所有测试集成到一个函数中来提高代码效率。感谢您的支持。
exp <- c(0.26,0.74) #defines the expected distribution
obsof <- c(57, 2051) #defines the observed distribution
obsto <- c(47, 235)
obsand <- c(58, 344)
obsthe <- c(42, 293)
obsin <- c(27, 134)
test1 <- chisq.test(obsof, p=exp) #defines the test
test1
test1$p.value #the test is significant if the p value is less than or equal to 0.05
test1$stdres #returns standardized residuals
test2 <- chisq.test(obsto, p=exp)
test2
test2$p.value
test3 <- chisq.test(obsand, p=exp)
test3
test3$p.value
test3$stdres
#
最好, Chamil
答案 0 :(得分:2)
lapply(mget(ls(pattern="^obs.*")),chisq.test,p=exp)