如何解决这个t检验错误-它说“数据本质上是恒定的”?

时间:2019-01-09 20:49:31

标签: r

这是我的代码,下面是我得到的错误:

t.test(replication$Expecatation_Factor, replication$Amused_After_centered)

#replication$Expecatation_Factor is a factor as verified by str() and class()
#replication$Amused_After_centered is an integer as verified by srt() and class()

已报告错误

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.

1 个答案:

答案 0 :(得分:1)

在没有看到实际数据集的情况下,很难确切地说出正在发生什么,但是看来您正在使用的向量之一实际上不是数字的。参见下面的内容,当您尝试对字符串变量使用t.test时会发生什么;非常接近您的警告。

> t.test(factor(c('a', 'b', 'c')), c(1, 2, 3)) # you can't run a t-test on c('a', 'b', 'c')
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.