Hi everyone,
I’m working on fitting an ODE model using brms
and Stan, and I’m encountering some issues with my code. I’m new to Bayesian inference and Stan, so I’d appreciate any guidance you can provide.
The model I’m trying to fit is:
\frac{dn}{dt} = φ(t) - μ \cdot n(t), \\ n(t=0) = 0
where μ
is a parameter to be inferred, and φ(t)
is a non-parametric function modeled using a Gaussian process. The analytical solution to the ODE is:
n(t) = \int_0^t \exp(-\mu (t-s)) \phi(s) \, ds
I’ve attempted to implement this in brms
with the following code:
data = data.frame(
t = c(0, 1, 2, 3, 4, 5, 6, 7),
n = c(0.00, 0.39, 0.57, 0.50, 0.12, 0.06, 0.02, 0.00),
dndt = c(0.39, 0.28, 0.05, -0.23, -0.22, -0.05, -0.03, -0.02)
)
fit = brms::brm(
formula = brms::bf(dndt ~ gp(t) - mu * n, mu ~ 1, nl = TRUE),
data = data,
prior = brms::set_prior("gamma(2, 0.1)", nlpar = "mu"),
sample_prior = "yes",
family = gaussian(),
control = list(adapt_delta = 0.95),
chains = 4,
iter = 2000,
cores = 4,
algorithm = "sampling",
silent = 0
)
summary(fit)
plot(fit)
However, I’m getting the following error:
Error: The following priors do not correspond to any model parameter:
b_mu ~ gamma(2, 0.1)
I’m trying to enforce a positive prior on μ
(hence the gamma distribution), but it seems the model isn’t recognizing the mu
parameter correctly. Instead, the output only includes sigma
and an intercept, which I suspect might be mu
.
Additionally, I need to extract both μ
and the hyperparameters of the Gaussian process (gp(t)
) so that I can reconstruct the function n(t)
afterwards.
Could someone kindly help me understand what’s going wrong with the priors and how I can properly specify the model to estimate μ
and the GP hyperparameters? Any suggestions or corrections to my code would be greatly appreciated!
Thank you in advance for your help!