Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

What is the g parameter in ttestBF in the BayesFactor library?

I am trying to understand the output for a two-factor Bayesian t-test using ttestBF in the BayesFactor R library. E.g.,

summarise_draws(ttestBF(formula=mpg ~ am, data=mtcars, posterior = TRUE, iterations=10000))

# A tibble: 5 × 10
 variable     mean median     sd  mad    q5   q95 rhat ess_bulk ess_tail
   <chr>        <dbl>  <dbl>   <dbl> <dbl>  <dbl>  <dbl> <dbl>    <dbl>    <dbl>
1 mu           20.7   20.7    0.906 0.897 19.3   22.2    1.00    9154.    9445.
2 beta (0 - 1) -6.47  -6.50   1.90  1.89  -9.54  -3.33   1.00    6325.    7587.
3 sig2         26.2   25.0    7.18  6.35  16.8   39.4    1.00    8040.    8876.
4 delta        -1.30  -1.30   0.418 0.418 -1.99  -0.618  1.00    6047.    7374.
5 g            14.0    1.60 444.    1.59   0.291 22.6    1.00    6968.    8035.

There's a mysterious parameter g that does not seem to be documented anywhere that I can find. It bounces around a lot, witness the high sd.

Going down the rabbit hole, I eventually found the source code for the Gibbs sampler for the test here. g is initialized to:

g = pow(beta, 2) / sig2 + 1

and makes an appearance in computing the variance for beta and the scale for sig2

varBeta = sig2 / ( sumN/4 + 1/g );

scaleSig2 = 0.5 * ( sumySq - 2.0 * mu * sumy - beta * diffy +
                         N[0] * pow(mu - beta/2, 2) + N[1] * pow(mu + beta/2, 2) );
if(!nullModel) scaleSig2 += pow(beta, 2) / g / 2

g itself seems to be an inverse gamma:

scaleg = 0.5 * ( pow(beta,2) / sig2 + rscaleSq );
g = 1 / Rf_rgamma( 0.5 * (1 + !nullModel), 1/scaleg );

I thought the answer might have something to do with this StackExchange question about the g in a JZS prior for a Bayesian t test, but I am not seeing the connection.

Any insight into what it's doing in the model would be greatly welcomed.

Comments

Sign In or Register to comment.