这是一个 prop.test 函数:
baby.prop.test = function (x, n, p, conf.level = 0.95) {
# ...
return(prop.test(x,n,p,conf.level))
#baby.prop.test$statistic
}
# test case
baby.prop = baby.prop.test(72, 100, .7, conf.level=.99)
stopifnot(isTRUE(all.equal(as.numeric(baby.prop$statistic), .43643578)))
stopifnot(isTRUE(all.equal(as.numeric(baby.prop$p.value), .66252058)))
这里是错误:
Error in match.arg(alternative) :
'arg' must be NULL or a character vector
知道哪里出了问题吗?
最佳答案
根据 formals(prop.test)
或 ?prop.test
第四个参数称为 alternative
并且必须是字符c("双面", "less", "greater")
。您的第四个元素是 conf.level
(这是 prop.test
的第五个元素,顺序很重要)。要“忽略”参数的顺序,您必须命名参数(至少 conf.level
):
prop.test(x, n, p, conf.level=conf.level)
关于r - 'arg' 必须为 NULL 或字符向量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22145089/