Description Usage Arguments Value Examples
View source: R/visualizeBF_function.R
Function for exploring Bayes Factors.
1 | visualizeBF(data, pointsize = 0.001, scale = 0.707, plot = 1)
|
data |
A vector of data |
pointsize |
Width of points for numerical integration, defaults to .001. |
scale |
Scale parameter for Cauchy prior, defaults to .707 |
plot |
The type of plot to produce. 1=BF as weighted likelihood, 2=BF as comparison of densities under prior and posterior at mu=0. for mu=0 under prior and posterior distributions. |
Returns a list with the following components:
L.m0
The likelihood evaluated at mu=0; the L of the null model (m0)
L.m1
The likelihood integrated over the whole space weighted by m1 prior;
likelihood of the alternative model (m1).
prior.mu0
The density of the prior distribution evaluated at mu=0 (m1).
posterior.m0
The density the posterior distribution evaluated at mu=0 (m0).
BF10
The Bayes Factor for alternative hypothesis relative to null.
BF01
The Bayes Factor for the null hypothesis relative to the alternative.
figure
Object containing the plot.
note
Instructions for restoring plot defaults; temporary.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | set.seed(1)
data <- rnorm(n=50, mean=.3, sd=1)
visualizeBF(data, plot=1)
visualizeBF(data, plot=2)
a <- visualizeBF(data, plot=1)
# extract density of the prior distribution at mu=0
a$prior.mu0
# calculate BF10 as likelihood ratio
a$L.m1 / a$L.m0
# alternative method for calculating BF10 as density ratio
a$prior.mu0 / a$posterior.mu0
# view the plot
a$figure
# restore plot defaults
dev.off()
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.