jomulder / BFpack

BFpack can be used for testing statistical hypotheses using the Bayes factor, a Bayesian criterion originally developed by sir Harold Jeffreys.
https://bfpack.info/
14 stars 4 forks source link

BF() returns error if hypothesis contains only numbers #21

Closed fboeingmessing closed 1 month ago

fboeingmessing commented 4 years ago

I recently encountered an error when using BF() for testing variances. The following code illustrates the problem:

y <- rnorm(20)
g <- factor(rep(c(1, 2), c(10, 10)))
x <- bartlett_test(y, g)
hypothesis <- "1=2; 1<2"
BF(x, hypothesis)

I get the following error message when I run this code:

Error in gsub(hyp_params[par], varnames[match_names[par]], hyp) : 
  invalid 'pattern' argument

Apparently, the problem is that the hypothesis contains only numbers, because the error disappears if I introduce a letter in the labels of the levels and thus the hypothesis:

y <- rnorm(20)
g <- factor(rep(c(1, 2), c(10, 10)))
levels(g) <- c("g1", "g2")
x <- bartlett_test(y, g)
hypothesis <- "g1=g2; g1<g2"
BF(x, hypothesis)
cjvanlissa commented 4 years ago

Dear Florian, thank you for bringing this to our attention. It is correct that you receive an error here, because your hypothesis does not conform to the syntax requirements. It should probably break in a more informative manner, though, and we will include more ubiquitous references to the syntax in the function documentation. Please check the syntax requirements here: https://cran.r-project.org/web/packages/bain/vignettes/Introduction_to_bain.html

cjvanlissa commented 4 years ago

@jomulder can you please ensure that the bain:::parse_hypothesis syntax is adequately referenced in the package documentation, and that bartlett_test() labels factor levels the same way lm() does, i.e.:

paste0(varname, levels(varname)) instead of just using levels(varname)

jomulder commented 4 years ago

Will check. Thanks.