为什么x必须是使用binom.test的非负整数

时间:2018-04-06 14:51:51

标签: r statistics

为什么我收到此错误?

  

binom.test中的错误(0.555,10):' x'必须是非负整数

1 个答案:

答案 0 :(得分:0)

第一个输入x应该是长度为1的整数,成功次数或长度为2的成功次数和失败次数,如下所示。

有关详细信息,请参阅?binom.test

binom.test(c(round(0.555*10), round((1-0.555)*10))) 
  Exact binomial test

data:  c(round(0.555 * 10), round((1 - 0.555) * 10))
number of successes = 6, number of trials = 10, p-value = 0.7539
alternative hypothesis: true probability of success is not equal to 0.5
95 percent confidence interval:
 0.2623781 0.8784477
sample estimates:
probability of success 
                   0.6

来自文档:

Usage

binom.test(x, n, p = 0.5,
           alternative = c("two.sided", "less", "greater"),
           conf.level = 0.95)
Arguments

x 
number of successes, or a vector of length 2 giving the numbers of successes and failures, respectively.
n 
number of trials; ignored if x has length 2.