View source: R/bfactor_to_prob.R
| bfactor_to_prob | R Documentation |
Update prior probabilities of models/hypotheses to posterior probabilities using Bayes factors.
bfactor_to_prob(bf, prior_prob = 0.5)
bf |
A numeric vector of non-negative values. |
prior_prob |
A numeric vector with values in the [0,1] interval.
If |
bfactor_to_prob turns Bayes factors into posterior
probabilities using a vectorized version of the following
equation from \insertCitebergerDelampady1987;textualpcal:
P(H0 | x) = (1 + ( (1 - π) / π) (1 / B(x) ) ) ^ ( -1 )
where B(x) is a Bayes factor in favor of the null hypothesis (given the data x), π is the prior probability of the null hypothesis and 1 - π is the prior probability of the alternative hypothesis.
If bf is a vector of Bayes factors (in favor of the null hypothesis)
and prior_prob is a vector with the prior probabilities of those
hypotheses then bfactor_to_prob(bf, prior_prob) updates prior_prob
to posterior probabilities. The posterior probabilities of the alternative
hypotheses can be obtained with 1 - bfactor_to_prob(bf, prior_prob).
The prior_prob argument is optional and is set to 0.5 by default,
implying prior equiprobability of hypotheses. prior_prob can only
be of length equal to length(bf), in which case
each prior probability in prior_prob will be updated using the
corresponding element of bf, or of length 1,
in which case it will be recycled (if length(bf) > 1) and each
element of bf will update the same prior_prob value.
If length(bf) > 1 then bfactor_to_prob returns a numeric
vector with the same length as bf, otherwise it
returns a numeric vector with the same length as
prior_prob. Warning messages are thrown if there are NA or NaN
values in bf or in prior_prob.
bfactor_interpret for the interpretation of
Bayes factors.
# With a Bayes factor that is indifferent between the null # and the alternative hypotheses: # -------------------------------------------------------- bfactor_to_prob(1) # Same as above but the null hypothesis has high prior probability: # ----------------------------------------------------------------- bfactor_to_prob(1, .99) # Posterior probability of the null hypothesis as a function # of the prior probability: # ----------------------------------------------------------------- bfactor_to_prob(1, seq(.5, 1, .1)) # With Bayes factors that favor the null hypothesis: # ----------------------------------------------------------------- round(bfactor_to_prob(seq(2, 50, 2.5)), 3) # Same as above but the null hypothesis has low prior probability: # ----------------------------------------------------------------- round(bfactor_to_prob(seq(2, 50, 2.5), prior_prob = .01), 3) # Posterior probabilities obtained with Bayes factors that # favor the alternative hypothesis: # ----------------------------------------------------------------- round(bfactor_to_prob(seq(0, 1, .05)), 3) # Same as above but the null hypothesis has high prior probability: # ----------------------------------------------------------------- round(bfactor_to_prob(seq(0, 1, .05), prior_prob = .99), 3) # Application: chi-squared goodness-of-fit test, # lower bound on the posterior probability of the null hypothesis: # ----------------------------------------------------------------- x <- matrix(c(12, 41, 25, 33), ncol = 2) bfactor_to_prob(bcal(chisq.test(x)[["p.value"]]), prior_prob = .9)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.