richarddmorey / BayesFactor

BayesFactor R package for Bayesian data analysis with common statistical models.
https://richarddmorey.github.io/BayesFactor/
132 stars 49 forks source link

ttestBF has issues with tibbles #105

Open sebastiansauer opened 7 years ago

sebastiansauer commented 7 years ago

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.")
richarddmorey commented 7 years ago

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.