Sarah J.
Sarah J.

Reputation: 1

How do I fix this t-test error - it says "data are essentially constant"?

Here is my code and below is the error that I'm getting:

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 REPORTED

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.

Upvotes: 0

Views: 3636

Answers (1)

Joseph Clark McIntyre
Joseph Clark McIntyre

Reputation: 1094

Without seeing your actual dataset it's hard to say exactly what's happening, but it appears that one of the vectors you're using is not actually numeric. See below for what happens when you try to use t.test on a string variable; it's very close to your warning.

> 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.

Upvotes: 1

Related Questions