-
Notifications
You must be signed in to change notification settings - Fork 0
/
AAFBF_by_hand.Rmd
47 lines (36 loc) · 1.88 KB
/
AAFBF_by_hand.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
---
title: "Calculating the AAFBF for two hypotheses"
author: "Ulrich Lösener"
date: "26-9-2023"
output: html_document
---
This script based on the paper "Approximated adjusted fractional Bayes factors: A general method for testing informative hypotheses" by Gu, Mulder and Hoijtink (2018)
Two hypotheses of interest:
- H1: beta = 0
- H2: beta > 0
```{r}
library(bain)
```
prior under the unconstrained hypothesis: $\pi_u^\ast \sim N(0, \frac{\sigma^2}{b})$
posterior under the unconstrained hypothesis: $\pi_u \sim N(\hat{\beta}, \sigma^2)$
```{r}
# specify input values
estimate <- 1 # estimate for beta
names(estimate) <- "est" # give the estimate a name that the hypothesis argument in bain can refer to
sigma_estimate <- .1 # SE of that estimate
N <- 100 # sample size
b <- 1/N # b fraction
# prior ~ N(0, sigma_estimate/b)
# posterior ~ N(estimate, sigma_estimate)
# calculate complexity and fit of H0
comp1 <- dnorm(0, mean=0, sd=sqrt(sigma_estimate/b)) # overlap of parameter under H0 and unconstrained prior -> density of the prior under Hu at the focal point 0
fit1 <- dnorm(0, mean=estimate, sd=sqrt(sigma_estimate)) # overlap of parameter under H0 and posterior -> density of the posterior at focal point 0
AAFBF1u <- fit1/comp1 # AAFBF of H0 vs Hu
# calculate complexity and fit of 1
comp2 <- pnorm(0, mean=0, sd=sqrt(sigma_estimate/b)) # always .5 for H1
fit2 <- 1 - pnorm(0, mean=estimate, sd=sqrt(sigma_estimate)) # the fit is equal to 1 - the fit of the complement
AAFBF2u <- fit2/comp2 # AAFBF of H0 vs Hu
# compare with output from bain
bain(estimate, hypothesis = c("est=0; est>0"), Sigma = as.matrix(sigma_estimate), n=N, fraction = 1)
cat(c("\n","\n", "BF.u for H1 by hand:", AAFBF1u, "\n", "BF.u for H2 by hand:", AAFBF2u, "\n"))
```