Hi, I’m trying to recreate the brms
model found here: Bayesian meta-analysis in brms | A. Solomon Kurz in Stan.
Specifically, this one:
b14.5 <-
brm(data = spank, family = gaussian,
d | se(se) ~ 1 + (1 | study),
prior = c(prior(normal(0, 1), class = Intercept),
prior(cauchy(0, 1), class = sd)),
iter = 2000, warmup = 1000, cores = 4, chains = 4,
seed = 14)
I know that there’s stancode()
function in brms
, but the output is too difficult for me to parse. I just want the bare-bones structure to start with.
Here’s my Stan code:
data {
int <lower=0> N; // total number of observations
vector[N] d; // dependent variable
vector <lower=0>[N] se; // standard errors
// data for group-level effects
int <lower=1> K; // number of groups
array[N] int<lower=1, upper=K> J; // grouping indicator per observation
}
parameters {
real<lower=0> tau;
real Intercept;
vector[K] theta;
}
model {
for (n in 1:N) {
target += normal_lpdf(d[n] | theta[J[n]], se[n]);
target += normal_lpdf(theta[J[n]] | Intercept, tau);
}
target += normal_lpdf(Intercept | 0, 1);
target += cauchy_lpdf(tau | 0, 1);
}
However, I get slightly different output:
brms
output:
Intercept
= 0.38 [.30, .45]
sd(Intercept)
= 0.26 [.21, .33]
And the output from my model is:
Intercept
= 0.33 [.30, .38]
tau
= 0.21 [.18, .24]
I think the differences are a bit too large for mcmc simulation variation, so I must be misspecifying the model, but can’t figure what exactly am I doing wrong? Thanks.