【发布时间】:2015-05-21 16:37:20
【问题描述】:
我在 R 中有一个名为 df 的数据框。对于数据框中恰好是一个因素的每个变量,我想执行按受试者性别分层的卡方检验并保存结果 p 值。我已经编写了代码来执行此操作,如下所示。
sapply(df, function(x) if(class(x) == "factor") { chisq.test(table(df$Sex, x))$p.value } )
问题是,当我运行这段代码时,我得到以下信息:
There were 50 or more warnings (use warnings() to see the first 50)
warnings()
Warning messages:
1: In chisq.test(table(df$Sex, x)) : Chi-squared approximation may be incorrect
当卡方检验生成警告时,如何修改我的原始代码以执行 Fisher 精确检验 fisher.test()?我不确定如何让代码在出现警告时进行识别。谢谢!
【问题讨论】:
-
一直使用渔夫?
标签: r function statistics compiler-warnings chi-squared