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

Parse_hypothesis() with parenthesis, eg., hp > (cyl, disp) > 0 breaking down #10

Closed Jaeoc closed 1 month ago

Jaeoc commented 5 years ago

I got some warnings when I was writing a glm example related to the parsing of hypotheses:

BF(fit, hypothesis = "(zfWHR, ztrust, zAfro) > 0; ztrust > (zfWHR, zAfro) > 0;
 ztrust > (zfWHR, zAfro) = 0")
1: In if (grepl("[><=]{2,}", hyp)) stop("Do not use combined comparison signs e.g., '>=' or '=='") :
  the condition has length > 1 and only the first element will be used

Although output seems fine as far as I can tell. When I was then creating a more easily reproducible example for this issue I instead got errors..

fit <- lm(mpg~cyl + disp + hp, data = mtcars)
BF(fit, hypothesis = "(cyl, disp) > hp = 0; hp > (disp,  cyl) > 0")

Gives

Error in parse_hypothesis(names(x), hypothesis) : 
  Some of the parameters referred to in the 'hypothesis' do not correspond to parameter names of object 'x'.
  The following parameter names in the 'hypothesis' did not match any parameters in 'x': hp, disp, cyl
  The parameters in object 'x' are named:

Any ideas @cjvanlissa ? I just tried downloading the latest versions of BFpack and bain, but didn't make a difference.

cjvanlissa commented 5 years ago

Something is going wrong on the BF side, because if I run it through bain, it works:

> bain:::parse_hypothesis(names(coef(fit)), "(cyl, disp) > hp = 0; hp > (disp,  cyl) > 0")
$hyp_mat
        Intercept cyl disp hp  
hp=0            0   0    0  1 0
cyl>hp          0   1    0 -1 0
disp>hp         0   0    1 -1 0
hp>disp         0   0   -1  1 0
hp>cyl          0  -1    0  1 0
disp>0          0   0    1  0 0
cyl>0           0   1    0  0 0

$n_constraints
[1] 1 2 0 4

$original_hypothesis
[1] "(cyl,disp)>hp=0" "hp>(disp,cyl)>0"