Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R BayesFactor Package: Output BF value

Tags:

r

I'm working with the BayesFactor Package in R but I can't output the Bayes Factor statistic as a variable to save.

For example, using a t-test paired-sample data design:

a = c(94,95,98,99,98,99,96,97,97,100,66,100,99,97,100,99,100,97,99)
b = c(97,100,99,100,100,98,98,97,97,100,67,100,100,98,99,99,100,98,100)
out = ttestBF(a,y = b,paired = T)

returns:

Bayes factor analysis

[1] Alt., r=0.707 : 4.258084 ±0.03%

Against denominator:

  Null, mu = 0

Bayes factor type: BFoneSample, JZS

I'd like to be able to save 4.258084 to a variable.

Typically in other R functions I'd access it as: out$variable_name

But the available options for this output are:

(1) out$Alt., r=0.707
(2) out$Null, mu=0

And these return errors when called:

(1) Error: unexpected ',' in "out$Alt.,"
(2) Error: unexpected ',' in "out$Null,"

Any help would be greatly appreciated

like image 249
nicalbee Avatar asked Oct 17 '25 01:10

nicalbee


2 Answers

(I am the author of the BayesFactor package). The easiest way to get the Bayes factor by itself is to simply use

as.vector(out)

and that will give you the desired number(s). There's no need to go deep in the object structure.

like image 142
richarddmorey Avatar answered Oct 18 '25 17:10

richarddmorey


I've managed to ask the right person and the answer is deeper into the output structure:

The Bayes Factor that you get from "out@bayesFactor$bf" is the LOG of the BayesFactor you want.

So to get the actual BF value:

BF = exp(1)^out@bayesFactor$bf

like image 37
nicalbee Avatar answered Oct 18 '25 17:10

nicalbee