代码之家  ›  专栏  ›  技术社区  ›  Newmen

为什么使用binom时x必须是非负整数。测验

  •  -1
  • Newmen  · 技术社区  · 7 年前

    为什么会出现此错误?

    binom错误。测试(0.555,10):“x”必须为非负整数

    1 回复  |  直到 7 年前
        1
  •  0
  •   Hack-R    7 年前

    第一次输入, 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.