BayesFactor icon indicating copy to clipboard operation
BayesFactor copied to clipboard

ttestBF has issues with tibbles

Open sebastiansauer opened this issue 7 years ago • 1 comments

ttestBF appears to have issues when a tibble is given as input. Consider this tibble:

tibble::tribble(
  ~value, ~group,
  4,    "a",
  1,    "b",
  5,    "a",
  2,    "b"
) -> df

And, in contrast, this data.frame version of the same data:

df2 <- data.frame(df)

To check:

class(df)
class(df2)

In checking.R this evaluation is performed (line 42):

is.numeric(df["value"])
is.numeric(df2["value"])

leading to a wrong conclusion for df, and to a right conclusion for df2. So, that's the problem.

Seen from a different perspective, tibble subsetting does not yield a vector, but a tibble, which is an unexpected behavior, see:

df[, "value"] %>% str
df2[, "value"] %>% str

I suggest replacing the code in checking.R by something like this (see line 42):

is.numeric(df[["value"]])
is.numeric(df2[["value"]])

That should solve the issue.

For reference, line 42:

if(!is.numeric(data[,dv])) stop("Dependent variable must be numeric.")

sebastiansauer avatar Jun 28 '17 08:06 sebastiansauer

Yes, a number of people have noted that BayesFactor does unexpected things with tibbles. I have not added support for tibbles because I'm not sure about their (intended) behaviour in all cases. Your suggested fix appears neutral, so I'll push that out.

richarddmorey avatar Jun 28 '17 19:06 richarddmorey