Investigation: Bayes factors and competing hypotheses

Investigation: Bayes factors and competing hypotheses#

A Bayes factor compares marginal likelihoods under specified models and parameter priors. Posterior model odds additionally require prior model odds. Evidence for a point null is different from demonstrating practical equivalence.

Question. Compute an analytic Bayes factor for a normal mean with known sampling standard error and vary the proper alternative-prior scale.

Before running: write the result you expect and what would challenge it. Data are simulated unless explicitly identified otherwise.

# Open this notebook from book/notebooks (or book/exercises).
course_path <- if (file.exists("../R/course.R")) "../R/course.R" else "book/R/course.R"
stopifnot(file.exists(course_path))
source(course_path)
set.seed(432)

A transparent analytic example#

Assume an estimate has a normal sampling distribution with known standard error. H0 fixes the mean at zero; H1 assigns a proper Normal(0, prior_sd²) prior to the mean. Integrating over this prior gives a Normal(0, se² + prior_sd²) marginal distribution for the estimate. This simplified example is not a replacement for unknown-variance paired-data models.

estimate <- .3
se <- .15
prior_sd <- c(.1,.3,1,3)
bf10 <- normal_mean_bf(estimate,se,prior_sd)
prior_odds <- 1
posterior_odds <- bf10*prior_odds
results <- data.frame(prior_sd=prior_sd,BF10=bf10,BF01=1/bf10,posterior_probability_H1=posterior_odds/(1+posterior_odds))
results
plot(prior_sd,bf10,type="b",log="x",xlab="Alternative prior SD",ylab="BF10")
abline(h=1,lty=2)
A data.frame: 4 × 4
prior_sdBF10BF01posterior_probability_H1
<dbl><dbl><dbl><dbl>
0.11.53959940.64951960.6062371
0.32.21506340.45145430.6889641
1.01.04890310.95337690.5119340
3.00.36715612.72363730.2685546
../_images/a5218782645cd7fc83268ac498f59bb642d0e4b4e0e61da155a9cdc6941c5134.png
# Cross-check the analytic marginal likelihood with numerical integration.
prior <- .3
marginal <- integrate(function(theta) dnorm(estimate,theta,se)*dnorm(theta,0,prior),-Inf,Inf)$value
numerical_bf <- marginal/dnorm(estimate,0,se)
stopifnot(abs(numerical_bf-normal_mean_bf(estimate,se,prior))<1e-7)
numerical_bf
2.21506343914211

Interpretation#

BF10 is a relative predictive density under these models; it is not itself a model probability. Changing prior model odds changes posterior odds, while changing the parameter prior can change the BF. Report prior sensitivity and inconclusive evidence. A flat prior on a finite range still has a scale; an improper flat prior generally does not define an ordinary marginal likelihood.

If using the historical R sleep example independently, it compares two soporific drug conditions within participants; it is not the sleepstudy deprivation/RT dataset. Fixed-effect ToothGrowth comparisons are not mixed models merely because several predictors appear.

Interpret and verify#

Plot prior sensitivity and identify when evidence is inconclusive. Separate BF10, BF01, and posterior model probability.

Failure to consider: A uniform prior does not make parameter priors irrelevant. Its range affects the marginal likelihood; improper priors generally do not define ordinary Bayes factors.

Report the target, the numerical result with its units, the relevant uncertainty, and one limitation. Distinguish what is established by the simulation from what would require real data.

AI audit: critique the saved faulty claim in the companion exercise before using any live assistant. If you use AI, record the relevant suggestion, your independent check, and the final decision.

Contrast tail probabilities with model-relative evidence, then evaluate how either approach can miss errors.

sessionInfo()
R version 4.2.1 (2022-06-23)
Platform: aarch64-apple-darwin20 (64-bit)
Running under: macOS 15.7.7

Matrix products: default
BLAS:   /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRblas.0.dylib
LAPACK: /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/lib/libRlapack.dylib

locale:
[1] C.UTF-8/C.UTF-8/C.UTF-8/C/C.UTF-8/C.UTF-8

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
 [1] fansi_1.0.3         crayon_1.5.1        digest_0.6.29      
 [4] utf8_1.2.2          IRdisplay_1.1       repr_1.1.4         
 [7] lifecycle_1.0.1     jsonlite_1.8.0      evaluate_0.15      
[10] pillar_1.8.0        rlang_1.0.6         cli_3.3.0          
[13] uuid_1.1-0          vctrs_0.4.1         IRkernel_1.3.0.9000
[16] tools_4.2.1         glue_1.6.2          fastmap_1.1.0      
[19] compiler_4.2.1      base64enc_0.1-3     pbdZMQ_0.3-7       
[22] htmltools_0.5.3    

Attribution#

Notebook authored by Krista Bond and edited by Charles Wu, Patience Stevens, and Amy Sentis.

Revised investigation: 2026 course revision. Original authorship is retained; examples and explanatory text have been updated.