Is it possible to “fix or pin” parameters in a hierarchical model to predefined values akin to ceiling analysis?

For example, my current workflow for testing components of a hierarchical model is to copy-paste the relevant portions into a new model file, compile, and run the inference on synthetic data. However, ensuring the different model snippets are always in sync can be a bit fiddly.

Being able to pass in the “truth” (based on synthetic data) for portions of the model would make it possible to sever the flow of information through the DAG defined by the model and test different components independently (without having to recompile or copy code snippets). In other words, the pinned parameters would be treated just like data.

Apologies if I missed the relevant section in the documentation.

You can sample raw parameters and define the actual parameter in the transformed parameter block which you do based on an if statement which selects the case you are interested in. Have a look at brms generated Stan models when using the constant prior.

Thank you for the pointer! Something like the following seems to do the trick (but is still a little fiddly). Is there a simpler solution?

// Very simple model to estimate the loc/scale of a normal distribution
data {
// Actual data
int<lower=0> n;
vector[n] x;
// "Data" used to feed in fixed parameters
int fix_mu;
int fix_sigma;
real mu_fixed;
real sigma_fixed;
}
parameters {
// Parameters to be inferred under normal circumstances
real mu_param;
real<lower=0> sigma_param;
}
transformed parameters {
// Transformed parameters that use fixed values if desired
real mu = fix_mu ? mu_fixed : mu_param;
real<lower=0> sigma = fix_sigma ? sigma_fixed : sigma_param;
}
model {
// Standard model built using transformed parameters
x ~ normal(mu, sigma);
mu ~ normal(0, 10);
sigma ~ lognormal(0, 2);
}