Hi,
I’m trying to run a one sample bayesian power analysis using this excellent blog post.
The frequenstis version returns power of 56% while the Bayesian gives 70%.
My question is why the frequenstis power analysis differ so much from the bayesian one (especially in a simple example like this one).
As example,
I have these conditions
n_sample = 6
mu_fake = 1.87
sd_fake = 1.75
The frequentists one sample power analysis gives 56% power.
power.t.test(n = n_sample,
sd = sd_fake,
delta = mu_fake,
alternative = "two.sided",
type = "one.sample", sig.level = 0.05)
For the Bayesian I’m following the below process
# The reference model to perform one.sample t-test
# The nu prior comes from Kruschke’s [paper](https://psycnet.apa.org/fulltext/2012-18082-001.html)
prior_t <- c(prior(normal(0, 5), class = 'Intercept'),
prior(exponential(1), class = 'sigma'),
prior("exponential(1.0/29)", class = 'nu'))
set.seed(917536)
bfit_reference <- brm(res ~ 1,
data = data.frame(res = rnorm(n_sample, mu_fake, sd_fake)),
family=student,
prior = prior_t,
chains = 3, cores = 3,
silent = 2, # Mute the additional info with silent & refresh
refresh = 0)
# Function to get the posterior samples from the model
post_sample <- function(x, ...)(posterior_summary(as.data.frame(x), ...))
#Simulate one new sample, update the fit and get the parameters out
sim_1s_and_fit <- function(seed,
n_sample = n_sample,
mu = mu_fake, # true mean
sd_r = sd_fake, # repeatability error
model = bfit_reference
)
{
set.seed(seed)
dat_f <- data.frame(res = rnorm(n_sample, mu, sd_r))
updated_fit <- update(model, newdata = dat_f)
tb_ft <- updated_fit %>% post_sample %>% as.data.frame %>%
rownames_to_column(var = 'param') %>%
filter(!grepl('lp', param))
return(tb_ft)
}
#Apply multiple times the sim_d_and_fit()
multiple_1s_fits_fun <- function(n_sim = 5, ...){
tibble(seed = sample(1:1e9, n_sim)) %>%
mutate(b1 = map(seed, sim_1s_and_fit, ...)) %>%
unnest(b1) %>% return
}
(t3 <- Sys.time());
set.seed(1)
ttest_sim_ta <- multiple_1s_fits_fun(n_sim = 500,
n_sample = n_sample, mu = mu_fake, sd_r = sd_fake,
model = bfit_reference)
t4 <- Sys.time(); t4-t3
Estimate the power which in this case is around 70%
ttest_sim_ta %>% filter(param == ‘b_Intercept’) %>%
mutate(check = ifelse(Q2.5 > 0, 1, 0)) %>%
summarise(power = mean(check))
Thanks for your time.