【问题标题】:"data are essentially constant" error with t testt 检验的“数据基本不变”错误
【发布时间】:2018-05-09 17:35:23
【问题描述】:
t.test(antibioticdata$Bacteria,
       antibioticdata$Inhibition, 
       alternative = c("two.sided"),
       paired = FALSE, 
       var.equal = FALSE)

这是我的 R 代码,用于对一组关于细菌抗生素耐药性的数据进行 t 检验。这给了我错误代码:

Error in if (stderr < 10 * .Machine$double.eps * max(abs(mx), abs(my))) stop("data are essentially constant") : 
  missing value where TRUE/FALSE needed
In addition: Warning messages:
1: In mean.default(x) : argument is not numeric or logical: returning NA
2: In var(x) :
  Calling var(x) on a factor x is deprecated and will become an error.
  Use something like 'all(duplicated(x)[-1L])' to test for a constant vector.

不知道我做错了什么

【问题讨论】:

  • 您能否提供一个重现此问题的最小输入数据集(最小重现)?这可能有助于故障排除。
  • 我相信这为正在发生的事情提供了线索:Calling var(x) on a factor x。如果BacteriaInhibition 之一是一个因素,则将发生错误和警告。
  • 请查看可能重复的链接,这可能会回答您的问题。
  • 请给minimal reproducible example,虽然错误信息很清楚。您是否有意对分类数据使用 t 检验?由于分类值不是正态分布的,甚至没有有意义的均值或方差,因此不清楚您希望通过运行测试发现什么。也许 R 只是在保护您免受统计废话的影响。 “不确定我做错了什么”的答案可能是“尝试对分类数据进行 t 检验”。

标签: r


【解决方案1】:

我刚刚遇到了同样的错误。这可能是由于每组中的所有值都相同。

所以再写两个“if else”。对我来说,我做到了

library("greenbrown") 

apply(data.table, 1, function(x){

  if(AllEqual(x[1:9])){return(1)}

  else if(AllEqual(x[1:4]) & AllEqual(x[5:9])){return(0)} else {

  t.test(as.numeric(x[1:4]), as.numeric(x[5:9]))->t.results

  return(t.results$p.value)
  }
})->P.for.data.table

【讨论】:

    猜你喜欢
    • 2013-08-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-29
    • 2018-05-17
    • 2017-12-20
    • 2015-06-13
    相关资源
    最近更新 更多