我想知道当预测只有一个级别时,是否有办法绕过这个错误:
Error in stats::chisq.test(y[1:20], predictions[1:20]) :
'x' and 'y' must have at least 2 levels
当chisq.test中的所有预测都属于相同的级别/类时(即使变量有两个级别(尽管这两个级别都不存在),我就会得到它。
测试数据:
y <- as.factor(c(rep(1, 10), rep(0, 11)))
predictions <- as.factor(c(rep(1, 20), 0))